From 218dc27b37cdaec4721155be20da21ecb97d2a73 Mon Sep 17 00:00:00 2001 From: Better nya Date: Wed, 18 Feb 2026 09:40:56 +1100 Subject: [PATCH] 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)