-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (32 loc) · 1015 Bytes
/
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
import time
from turtle import Screen
from constants import SCREEN_HEIGHT, SCREEN_WIDTH, GAME_SLEEP, PLAYER_CAR_DISTANCE
from player import Player
from car_manager import CarManager
from scoreboard import Scoreboard
screen = Screen()
screen.setup(width=SCREEN_WIDTH, height=SCREEN_HEIGHT)
screen.tracer(0)
player = Player()
scoreboard = Scoreboard()
car_manager = CarManager()
screen.listen()
screen.onkey(key="Up", fun=player.move)
game_is_on = True
while game_is_on:
time.sleep(GAME_SLEEP)
screen.update()
car_manager.create_car()
car_manager.move_cars()
# Detect if player has crossed finish line
if player.has_crossed_finish_line():
scoreboard.increment_level()
player.go_to_start()
car_manager.increase_car_speed()
# Detect collision with any car
cars = car_manager.get_cars()
for car in cars:
if player.distance(car) < PLAYER_CAR_DISTANCE:
scoreboard.show_game_over()
game_is_on = False
screen.exitonclick()