-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar_manager.py
48 lines (40 loc) · 1.33 KB
/
car_manager.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
from turtle import Turtle
import random
COLORS = ["firebrick", "salmon", "goldenrod", "olive drab", "light sky blue", "medium purple"]
STARTING_MOVE_DISTANCE = 5
MOVE_INCREMENT = 10
CAR_SPAWN_COR_X = 330
CAR_SPAWN_LIMIT_Y = [-240, 240]
class CarManager:
def __init__(self):
self.car_objects = []
def create_car(self):
car = Turtle("square")
car.penup()
car.color(random.choice(COLORS))
car.resizemode("user")
car.setheading(180)
car.turtlesize(stretch_wid=1.0, stretch_len=2.0)
car.setx(CAR_SPAWN_COR_X)
car.sety(random.randrange(-240, 240, 20))
self.car_objects.append(car)
def drive(self):
for car in self.car_objects:
car.forward(STARTING_MOVE_DISTANCE)
def increase_carspeed(self):
global STARTING_MOVE_DISTANCE
STARTING_MOVE_DISTANCE += MOVE_INCREMENT
def detect_player(self, turtle):
for car in self.car_objects:
car_y = car.ycor()
player_y = turtle.ycor()
abs_y = abs(car_y - player_y)
abs_x = abs(car.xcor())
if abs_y < 18 and abs_x <= 20:
return False
return True
def true_speed(self):
global STARTING_MOVE_DISTANCE
if STARTING_MOVE_DISTANCE > 45:
return True
return False