-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (32 loc) · 938 Bytes
/
main.py
File metadata and controls
40 lines (32 loc) · 938 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
import time
from turtle import Screen
from player import Player
from car_manager import CarManager
from scoreboard import Scoreboard
screen = Screen()
screen.title("Turtle Crossing Game")
screen.setup(width=600, height=600)
screen.tracer(0)
player = Player()
scoreboard = Scoreboard()
cars = CarManager()
screen.listen()
screen.onkey(key="Up", fun=player.move)
game_is_on = True
while game_is_on:
time.sleep(0.1)
cars.move_cars()
if player.ycor() >= 280:
player.level_up()
scoreboard.level_up()
cars.increase_speed()
# Add a new car to the list of cars every other time the level is increased
if scoreboard.level % 2 == 0:
cars.create_car()
# Game ends if the player collides with a car
for car in cars.all_cars:
if player.distance(car) < 20:
scoreboard.game_over()
game_is_on = False
screen.update()
screen.exitonclick()