I am trying to make a car game in pygame, but whenever I try to spawn the cars, some of them get on top of each other, how do I fix it?
Here is the code for spawning the car:
if len(enemiesL) == 0:
if len(enemiesR) == 0:
wavelengthL += 3
for _ in range(wavelengthL):
enemy = EnemyL(random.randrange(160, Width/2 - 50), random.randrange(-1500, -100), random.choice(["black", "blue", "brown", "darkblue", "orange", "pale", "purple", "red", "white", "yellow"]))
enemiesL.append(enemy)
if len(enemiesR) == 0:
wavelengthR += 3
for _ in range(wavelengthR):
enemy = EnemyR(random.randrange(Width/2, Width-200), random.randrange(-1500, -100), random.choice(["black", "blue", "brown", "darkblue", "orange", "pale", "purple", "red", "white", "yellow"]))
enemiesR.append(enemy)
See Question&Answers more detail:os