This is my fourth commit. I fixed the issue I was having with the cars breaking apart.

I am very happy that I was able to fix this problem.  I had to email you about this problem and you showed me how this could be completed by creating another class.  This makes so much sense now as you could spawn one part of the car right behind the other to give the illusion that it is one car.
I learned the new skill of using 2 different classes together when making the car 2 wide.
This commit is contained in:
jwberent
2025-12-06 22:54:28 -05:00
parent abca9dbd4f
commit 4ff9dbd231
6 changed files with 14 additions and 40 deletions

View File

@@ -1,5 +1,6 @@
from random import randint
from path import Car
from car_back import CarBack
class CarSpawner:
display = False
@@ -8,17 +9,11 @@ class CarSpawner:
width, height = game.board_size
game.state['score'] += 1
if self.should_spawn_car(game.turn_number):
#car = Car((randint(0, width - 1), 0))
#car = Car((0, randint(0, height - 1)))
#car2 = Car((30,randint(0, height - 1)))
#game.add_agent(car)
#game.add_agent(car2)
y = randint(0, height - 1)
y = randint(1, height-1)
car3 = Car((0, y))
car4 = Car((1,y))
car3.next = CarBack((1,y))
game.add_agent(car3)
game.add_agent(car4)
game.add_agent(car3.next)
def should_spawn_car(self, turn_number):
return randint(0, 1000) < turn_number