forked from tdostilio/Race_Game
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTrafficSign.py
75 lines (60 loc) · 2.15 KB
/
TrafficSign.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from V2X import V2X
import pygame
import numpy as np
class TrafficSign(V2X):
def __init__(self, position, width, height, imagePath=None):
V2X.__init__(self, position, name="TrafficSign")
self.position = position
self.width = width
self.height = height
if imagePath is None:
sample_array = 100 * np.ones((width, height, 3), np.uint8)
self.image =\
pygame.pixelcopy.make_surface(sample_array)
else:
self.image = pygame.image.load(imagePath)
self.image =\
pygame.transform.scale(self.image, (self.width, self.height))
self.data = [
self.name, self.position,
self.width, self.height,
]
def draw(self, screen):
image_rect = self.image.get_rect()
image_rect.left, image_rect.top = self.position
screen.blit(self.image, image_rect)
class Right(TrafficSign):
def __init__(self, position, width, height,
imagePath="images/right.JPG"):
TrafficSign.__init__(self, position, width, height,
imagePath=imagePath)
self.name = "Right"
self.data = [
self.name, self.position,
self.width, self.height,
]
class Left(TrafficSign):
def __init__(self, position, width, height, imagePath="images/left.JPG"):
TrafficSign.__init__(self, position, width, height,
imagePath=imagePath)
self.name = "Left"
self.data = [
self.name, self.position,
self.width, self.height,
]
if __name__ == "__main__":
import sys
pygame.init()
pygame.display.set_caption("TrafficSign Example")
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
t = Right((300, 200), 100, 100, "images/no_left.JPG")
while True:
clock.tick(5)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill((0, 0, 0))
print(t.data)
t.draw(screen)
pygame.display.flip()