-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (42 loc) · 1.33 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
52
53
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.title("Turtle Crossing Game")
screen.tracer(0)
my_turtle = Player()
scoreboard = Scoreboard()
cars = []
screen.listen()
screen.onkeypress(my_turtle.move, "Up")
screen.onkeypress(my_turtle.move, "space")
game_is_on = True
car_occurence_frequency = 20
i = 0
while game_is_on:
time.sleep(0.1)
screen.update()
if i % car_occurence_frequency == 0:
new_car = CarManager()
cars.append(new_car)
i = 0
# collision with car
for car in cars:
car.move()
if my_turtle.distance(car) < 20 or my_turtle.distance(car.xcor()+20, car.ycor()) < 20 \
or my_turtle.distance(car.xcor()-20, car.ycor()) < 20:
scoreboard.game_over()
game_is_on = False
print(f"turtle: {my_turtle.xcor()}, {my_turtle.ycor()}")
print(f"car: {car.xcor()}, {car.ycor()}")
# achieving finish line
if my_turtle.ycor() > my_turtle.finish:
scoreboard.increase_level()
my_turtle.reset()
car_occurence_frequency = (car_occurence_frequency * 0.9).__ceil__()
i = 0
i += 1
screen.exitonclick()