From fe2ccf5edf9f473a7ac93875fa91a3bc26c6ff25 Mon Sep 17 00:00:00 2001 From: Better nya Date: Tue, 17 Feb 2026 10:32:59 +1100 Subject: [PATCH 1/3] add gameplay Signed-off-by: Better nya --- main.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index d2a9e50..40d2f2d 100644 --- a/main.py +++ b/main.py @@ -1,16 +1,37 @@ import sys import pygame + pygame.init() #SETUP -WIDTH, HEIGHT = 800, 800 -WINDOW = pygame.display.set_mode((WIDTH, HEIGHT)) +WIDTH, HEIGHT = 800, 600 +screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Traffic Controller") #CONSTANTS FPS = 60 -# Game loop +#CLOCK clock = pygame.time.Clock() + +#COLOURS + +ROAD_COLOUR = (50, 50, 50) +LINE_COLOUR = (255, 255, 0) +CAR_COLOUR = (200, 0, 0) +BG_COLOUR = (30, 150, 30) + +#CAR +car_width = 40 +car_height = 70 +car_x = WIDTH // 2 - car_width // 2 +car_y = HEIGHT - car_height - 20 +car_speed = 4 +lane_speed = 5 + +#LANE +lane_y = 0 + +#LOOP running = True while running: clock.tick(FPS) @@ -20,3 +41,31 @@ while running: pygame.quit() sys.exit() + #INPUT + keys = pygame.key.get_pressed() + if keys[pygame.K_LEFT]: + car_x -= car_speed + if keys[pygame.K_RIGHT]: + car_x += car_speed + + #LANE SPEED + lane_y += lane_speed + if lane_y > HEIGHT: + lane_y = 0 + + #BG + screen.fill(BG_COLOUR) + + #ROAD + pygame.draw.rect(screen, ROAD_COLOUR, (200, 0, 400, HEIGHT)) + + #LANE DIVIDER + for i in range(-1, 10): + pygame.draw.rect(screen, LINE_COLOUR, + (WIDTH//2 - 5, lane_y + i * 80, 10, 40)) + + #CAR + pygame.draw.rect(screen, CAR_COLOUR, (car_x, car_y, car_width, car_height)) + + pygame.display.flip() + clock.tick(FPS) From 9b1dc0c48e34f471aaf49e654f0d2a9fa588e941 Mon Sep 17 00:00:00 2001 From: Better nya Date: Wed, 18 Feb 2026 08:54:31 +1100 Subject: [PATCH 2/3] add gameplay Signed-off-by: Better nya --- main.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 40d2f2d..a5e400e 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,8 @@ -import sys import pygame +import sys pygame.init() +pygame.font.init() #SETUP WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) @@ -41,12 +42,27 @@ while running: pygame.quit() sys.exit() + + #score/timer + font = pygame.font.SysFont(None, 48) + start_time = 0 + current_time = pygame.time.get_ticks() + elapsed_time = (current_time - start_time) // 1000 + + timer_text = font.render(f"Time: {elapsed_time}s", True, (255, 255, 255)) # Render the text + + screen.blit(timer_text, (100, 100)) + #INPUT keys = pygame.key.get_pressed() - if keys[pygame.K_LEFT]: + if keys[pygame.K_LEFT] or keys[pygame.K_a]: car_x -= car_speed - if keys[pygame.K_RIGHT]: + if keys[pygame.K_RIGHT] or keys[pygame.K_d]: car_x += car_speed + if keys[pygame.K_UP] or keys[pygame.K_w]: + car_y -= car_speed + if keys[pygame.K_DOWN] or keys[pygame.K_s]: + car_y += car_speed #LANE SPEED lane_y += lane_speed From 218dc27b37cdaec4721155be20da21ecb97d2a73 Mon Sep 17 00:00:00 2001 From: Better nya Date: Wed, 18 Feb 2026 09:40:56 +1100 Subject: [PATCH 3/3] fix lane divider and scoring system Signed-off-by: Better nya --- main.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/main.py b/main.py index a5e400e..bf6269d 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,7 @@ pygame.display.set_caption("Traffic Controller") #CONSTANTS FPS = 60 +START_TIME = 0 #CLOCK clock = pygame.time.Clock() @@ -42,16 +43,8 @@ while running: pygame.quit() sys.exit() - - #score/timer - font = pygame.font.SysFont(None, 48) - start_time = 0 - current_time = pygame.time.get_ticks() - elapsed_time = (current_time - start_time) // 1000 - - timer_text = font.render(f"Time: {elapsed_time}s", True, (255, 255, 255)) # Render the text - - screen.blit(timer_text, (100, 100)) + #BG + screen.fill(BG_COLOUR) #INPUT keys = pygame.key.get_pressed() @@ -65,23 +58,27 @@ while running: car_y += car_speed #LANE SPEED - lane_y += lane_speed - if lane_y > HEIGHT: - lane_y = 0 - - #BG - screen.fill(BG_COLOUR) + lane_y = (lane_y + lane_speed) % 80 #ROAD pygame.draw.rect(screen, ROAD_COLOUR, (200, 0, 400, HEIGHT)) #LANE DIVIDER - for i in range(-1, 10): + for i in range(-2, HEIGHT // 80 + 3): pygame.draw.rect(screen, LINE_COLOUR, (WIDTH//2 - 5, lane_y + i * 80, 10, 40)) #CAR pygame.draw.rect(screen, CAR_COLOUR, (car_x, car_y, car_width, car_height)) + #score/timer + font = pygame.font.SysFont(None, 48) + current_time = pygame.time.get_ticks() + elapsed_time = ((current_time - START_TIME) // 1000) * 5 + + timer_text = font.render(f"Score: {elapsed_time}", True, (255, 255, 255)) # Render the text + + screen.blit(timer_text, (50, 50)) + pygame.display.flip() clock.tick(FPS)