extremely struggling to make them queue at lights
Signed-off-by: casualhonk <casualhonk@Tomoe.nya>
This commit is contained in:
parent
e2ffea00e0
commit
d455b8230f
1 changed files with 24 additions and 8 deletions
32
main.py
32
main.py
|
|
@ -52,14 +52,25 @@ class Vehicle:
|
||||||
self.speed = speed
|
self.speed = speed
|
||||||
self.wait = 0
|
self.wait = 0
|
||||||
|
|
||||||
def update(self, lights):
|
def update(self, lights, vehicles):
|
||||||
#check if light ahead
|
#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:
|
for light in lights:
|
||||||
if abs(self.x - light.x) < 10 and self.y < light.y < self.y + 40:
|
if abs(self.x - light.x) < 10:
|
||||||
if light.current != "green":
|
if self.y < light.y < self.y + 40:
|
||||||
self.wait += 1
|
if light.current != "green":
|
||||||
return
|
return
|
||||||
|
|
||||||
self.y += self.speed
|
self.y += self.speed
|
||||||
|
|
||||||
|
|
@ -108,7 +119,7 @@ while running:
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
mx, my = pygame.mouse.get_pos()
|
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
|
DEL_RADIUS = 25
|
||||||
|
|
||||||
|
|
@ -163,11 +174,16 @@ while running:
|
||||||
light.update()
|
light.update()
|
||||||
light.draw(screen)
|
light.draw(screen)
|
||||||
|
|
||||||
|
vehicles.sort(key=lambda v: v.y)
|
||||||
|
|
||||||
#update vehicles
|
#update vehicles
|
||||||
for v in vehicles:
|
for v in vehicles:
|
||||||
v.update(lights)
|
v.update(lights, vehicles)
|
||||||
v.draw(screen)
|
v.draw(screen)
|
||||||
|
|
||||||
|
#remove dem
|
||||||
|
vehicles = [v for v in vehicles if v.y < HEIGHT + 50]
|
||||||
|
|
||||||
#draw intersections
|
#draw intersections
|
||||||
for x, y in intersections:
|
for x, y in intersections:
|
||||||
pygame.draw.rect(screen, WHITE, (x - 20, y - 20, 40, 40), 2)
|
pygame.draw.rect(screen, WHITE, (x - 20, y - 20, 40, 40), 2)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue