153
while check:
for event in pygame.event.get():
if event.type == pygame.QUIT:
check = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_x:
playerCar.moveRight(10)
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
playerCar.moveLeft(5)
if keys[pygame.K_RIGHT]:
playerCar.moveRight(5)
if keys[pygame.K_UP]:
speed += 0.05
if keys[pygame.K_DOWN]:
speed -= 0.05
for car in all_coming_cars:
car.moveForward(speed)
if car.rect.y > SCREENHEIGHT:
c a r . c h a n g e S p e e d ( r a n d o m .
randint(50,100))
car.repaint(random.choice(colorList))
car.rect.y = -200
car_collision_list
=
pygame.sprite.
spritecollide(playerCar,all_coming_cars,False)
for car in car_collision_list:
print("Car crash!")
check=False
cars_list.update()
screen.fill(GREEN)
pygame.draw.rect(screen, GREY, [40,0,400,
SCREENHEIGHT])
pygame.draw.line(screen, WHITE, [140,0],
[140,SCREENHEIGHT], 5)
pygame.draw.line(screen, WHITE, [240,0],
[240,SCREENHEIGHT], 5)
pygame.draw.line(screen, WHITE, [340,0],
[340,SCREENHEIGHT], 5)
cars_list.draw(screen)
Достарыңызбен бөлісу: