forked from AseanK/python-tools-and-games
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (34 loc) · 868 Bytes
/
Copy pathmain.py
File metadata and controls
43 lines (34 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from turtle import Screen
from animal import Animal
from cars import Cars
from level import Level
from time import sleep
# turtle screen
screen = Screen()
screen.setup(width=600, height=600)
screen.title("Road Crossing")
screen.tracer(0)
screen.listen()
animal = Animal()
car = Cars()
display = Level()
screen.onkeypress(animal.move_up, "Up")
screen.onkeypress(animal.move_down, "Down")
# Main loop
game_on = True
while game_on:
sleep(.05)
screen.update()
car.create_car()
car.move_cars()
# Game over when hit by the car
for each_car in car.all_cars:
if each_car.distance(animal) < 25:
display.game_over()
game_on = False
# Level up when the player reaches certain y_cor
if animal.ycor() > 280:
animal.reset_animal()
display.level_up()
car.level_up()
screen.exitonclick()