From d455b8230f124d008332c8601954420b94cc0c67 Mon Sep 17 00:00:00 2001 From: casualhonk Date: Fri, 20 Feb 2026 22:16:15 +1100 Subject: [PATCH] extremely struggling to make them queue at lights Signed-off-by: casualhonk --- main.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 2952cd9..379fb0c 100644 --- a/main.py +++ b/main.py @@ -52,14 +52,25 @@ class Vehicle: self.speed = speed self.wait = 0 - def update(self, lights): - #check if light ahead + def update(self, lights, vehicles): + #check if car/light ahead + + for other in vehicles: + if other is self: + continue + + if abs(self.x - other.x) < 5: + if other.y > self.y: + dist = other.y - self.y + if dist < 60: + return # too close back up + for light in lights: - if abs(self.x - light.x) < 10 and self.y < light.y < self.y + 40: - if light.current != "green": - self.wait += 1 - return + if abs(self.x - light.x) < 10: + if self.y < light.y < self.y + 40: + if light.current != "green": + return self.y += self.speed @@ -108,7 +119,7 @@ while running: if event.type == pygame.MOUSEBUTTONDOWN: mx, my = pygame.mouse.get_pos() - if placing_mode == "remove" and event.button == 3: + if placing_mode == "remove" and event.button == 1: DEL_RADIUS = 25 @@ -163,11 +174,16 @@ while running: light.update() light.draw(screen) + vehicles.sort(key=lambda v: v.y) + #update vehicles for v in vehicles: - v.update(lights) + v.update(lights, vehicles) v.draw(screen) + #remove dem + vehicles = [v for v in vehicles if v.y < HEIGHT + 50] + #draw intersections for x, y in intersections: pygame.draw.rect(screen, WHITE, (x - 20, y - 20, 40, 40), 2)