-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (41 loc) · 1.19 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
50
51
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)
# Create a turtle and animate it by pressing "UP"
player = Player()
screen.listen()
screen.onkey(player.move, "Up")
scoreboard = Scoreboard()
cars = []
for _ in range(20):
cars.append(CarManager())
game_is_on = True
while game_is_on:
time.sleep(0.1)
screen.update()
# Generate moving cars at random points of Y axel
for i in range(len(cars)):
cars[i].move_car()
# Make cars reset if they reach the left wall
if cars[i].xcor() < -320:
cars[i].reset()
# Detect turtle collision with cars
if cars[i].distance(player) < 20:
# Game Over
scoreboard.game_over()
game_is_on = False
# Detect turtle reaching the finish line
if player.ycor() == player.finish_line:
# Reset turtles position
player.reset()
# Upgrade level
scoreboard.level_up()
# Increase cars' speed
for i in range(len(cars)):
cars[i].increase_speed()
screen.exitonclick()