-
Notifications
You must be signed in to change notification settings - Fork 385
/
Copy pathmain.py
49 lines (35 loc) · 1.1 KB
/
main.py
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
44
45
46
47
48
49
import time
from turtle import Screen
from player import Player
from car_manager import CarManager
from scoreboard import Scoreboard
screen = Screen()
screen.setup(width=600, height=600)
screen.tracer(0)
player = Player()
car_manager = CarManager()
scoreboard = Scoreboard()
screen.listen()
# move turtle when we press the Up key
screen.onkey(key="Up", fun=player.move_turtle)
game_is_on = True
while game_is_on:
time.sleep(0.1)
car_manager.create_car()
car_manager.move_car()
# Detect collision with cars
screen.update()
# create and move the cars
for car in car_manager.all_cars:
if car.distance(player) < 22:
game_is_on = False
scoreboard.game_over()
# print game over whenever the turtle collide with cars
# Detect collision with wall
if player.ycor() > 285:
player.reset_turtle()
car_manager.level_up_speed()
#level up the speed of car whenever turtle collide with wall
scoreboard.increase_level()
#level up the score whenever turtle collide with the wall
screen.exitonclick()