-
Notifications
You must be signed in to change notification settings - Fork 0
/
car.py
40 lines (33 loc) · 1.42 KB
/
car.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
import pygame
class Car:
def __init__(self, color, player, location, width=50, length=100):
self.width = width
self.length = length
self.color = color
self.player = player
self.location = location
def displayCar(self, display):
# self.display = display
pygame.draw.rect(display, self.color, (self.location[0], self.location[1], self.width, self.length))
def leaveRail(self, time=60):
#keep a square at cars previous location for set amount of time
pass
def KeyBoard(self, event, x_change, y_change):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT and x_change == 0:
x_change = -self.length
y_change = 0
self.width, self.length = self.length, self.width
elif event.key == pygame.K_RIGHT and x_change == 0:
x_change = self.length
y_change = 0
self.width, self.length = self.length, self.width
elif event.key == pygame.K_UP and y_change == 0:
y_change = -self.length
x_change = 0
self.width, self.length = self.length, self.width
elif event.key == pygame.K_DOWN and y_change == 0:
y_change = self.length
x_change = 0
self.width, self.length = self.length, self.width
return [x_change, y_change]