-
Notifications
You must be signed in to change notification settings - Fork 0
/
car_manager.py
39 lines (26 loc) · 962 Bytes
/
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
from turtle import Turtle
import random
COLORS = ["red", "orange", "yellow", "green", "blue", "purple"]
STARTING_MOVE_DISTANCE = 5
MOVE_INCREMENT = 10
#This class is responsible for generating cars to travel across the screen.
class CarManager:
def __init__(self):
self.all_cars = []
self.car_speed = STARTING_MOVE_DISTANCE
def create_car(self):
random_chance = random.randint(1,6)
if random_chance == 1:
new_car = Turtle()
new_car.shape('square')
new_car.penup()
new_car.color(random.choice(COLORS))
new_car.shapesize(stretch_wid=1,stretch_len=2)
random_y = random.randint(-240,250)
new_car.goto(300,random_y)
self.all_cars.append(new_car)
def move_car(self):
for car in self.all_cars:
car.backward(STARTING_MOVE_DISTANCE)
def level_up(self):
self.car_speed += MOVE_INCREMENT