-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_vehicle_sprites.py
More file actions
192 lines (153 loc) · 6.16 KB
/
create_vehicle_sprites.py
File metadata and controls
192 lines (153 loc) · 6.16 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python3
"""
Script to create vehicle sprite images for the traffic simulation.
Generates simple vehicle sprites in different styles.
"""
import pygame
import os
from entities.vehicle import VehicleType
def create_vehicle_sprites():
"""Create vehicle sprite images."""
# Initialize pygame
pygame.init()
# Create assets directory if it doesn't exist
os.makedirs("assets/vehicles", exist_ok=True)
# Vehicle specifications
vehicle_specs = {
VehicleType.CAR: {
'size': (30, 20),
'color': (0, 100, 200),
'details': 'car'
},
VehicleType.BUS: {
'size': (40, 25),
'color': (200, 100, 0),
'details': 'bus'
},
VehicleType.BIKE: {
'size': (25, 15),
'color': (100, 200, 100),
'details': 'bike'
},
VehicleType.AMBULANCE: {
'size': (35, 22),
'color': (200, 0, 0),
'details': 'ambulance'
}
}
for vehicle_type, specs in vehicle_specs.items():
# Create sprite surface
surface = pygame.Surface(specs['size'], pygame.SRCALPHA)
# Draw vehicle based on type
if specs['details'] == 'car':
draw_car(surface, specs['color'])
elif specs['details'] == 'bus':
draw_bus(surface, specs['color'])
elif specs['details'] == 'bike':
draw_bike(surface, specs['color'])
elif specs['details'] == 'ambulance':
draw_ambulance(surface, specs['color'])
# Save sprite
filename = f"assets/vehicles/{vehicle_type.value}.png"
pygame.image.save(surface, filename)
print(f"Created {filename}")
pygame.quit()
print("All vehicle sprites created successfully!")
def draw_car(surface, color):
"""Draw a car sprite."""
width, height = surface.get_size()
# Main body
body_rect = pygame.Rect(2, height//3, width-4, height//3)
pygame.draw.rect(surface, color, body_rect)
# Windshield
windshield_color = (150, 200, 255)
windshield_rect = pygame.Rect(width//3, height//6, width//3, height//4)
pygame.draw.rect(surface, windshield_color, windshield_rect)
# Wheels
wheel_color = (40, 40, 40)
wheel_radius = height//8
# Front wheels
pygame.draw.circle(surface, wheel_color, (width//4, height//4), wheel_radius)
pygame.draw.circle(surface, wheel_color, (width//4, 3*height//4), wheel_radius)
# Rear wheels
pygame.draw.circle(surface, wheel_color, (3*width//4, height//4), wheel_radius)
pygame.draw.circle(surface, wheel_color, (3*width//4, 3*height//4), wheel_radius)
# Border
pygame.draw.rect(surface, (255, 255, 255), surface.get_rect(), 2)
def draw_bus(surface, color):
"""Draw a bus sprite."""
width, height = surface.get_size()
# Main body
body_rect = pygame.Rect(2, height//4, width-4, height//2)
pygame.draw.rect(surface, color, body_rect)
# Windows
window_color = (100, 150, 200)
for i in range(4):
window_rect = pygame.Rect(width//8 + i*width//6, height//6, width//10, height//3)
pygame.draw.rect(surface, window_color, window_rect)
# Wheels
wheel_color = (40, 40, 40)
wheel_radius = height//8
# Front wheels
pygame.draw.circle(surface, wheel_color, (width//4, height//4), wheel_radius)
pygame.draw.circle(surface, wheel_color, (width//4, 3*height//4), wheel_radius)
# Rear wheels
pygame.draw.circle(surface, wheel_color, (3*width//4, height//4), wheel_radius)
pygame.draw.circle(surface, wheel_color, (3*width//4, 3*height//4), wheel_radius)
# Border
pygame.draw.rect(surface, (255, 255, 255), surface.get_rect(), 2)
def draw_bike(surface, color):
"""Draw a bike sprite."""
width, height = surface.get_size()
# Main frame
frame_color = (60, 60, 60)
frame_rect = pygame.Rect(width//2-2, height//4, 4, height//2)
pygame.draw.rect(surface, frame_color, frame_rect)
# Wheels
wheel_color = (40, 40, 40)
wheel_radius = height//4
# Front wheel
pygame.draw.circle(surface, wheel_color, (width//3, height//2), wheel_radius)
pygame.draw.circle(surface, (200, 200, 200), (width//3, height//2), wheel_radius-2)
# Rear wheel
pygame.draw.circle(surface, wheel_color, (2*width//3, height//2), wheel_radius)
pygame.draw.circle(surface, (200, 200, 200), (2*width//3, height//2), wheel_radius-2)
# Handlebar
handle_color = (80, 80, 80)
handle_rect = pygame.Rect(width//3-5, height//4, 10, 3)
pygame.draw.rect(surface, handle_color, handle_rect)
# Seat
seat_color = (100, 50, 0)
seat_rect = pygame.Rect(2*width//3-3, height//2-2, 6, 4)
pygame.draw.rect(surface, seat_color, seat_rect)
# Border
pygame.draw.rect(surface, (255, 255, 255), surface.get_rect(), 2)
def draw_ambulance(surface, color):
"""Draw an ambulance sprite."""
width, height = surface.get_size()
# Main body
body_rect = pygame.Rect(2, height//4, width-4, height//2)
pygame.draw.rect(surface, color, body_rect)
# Red cross
cross_color = (255, 255, 255)
cross_rect = pygame.Rect(width//2-3, height//2-8, 6, 16)
pygame.draw.rect(surface, cross_color, cross_rect)
cross_rect = pygame.Rect(width//2-8, height//2-3, 16, 6)
pygame.draw.rect(surface, cross_color, cross_rect)
# Siren light
siren_color = (255, 255, 0)
siren_rect = pygame.Rect(width//2-2, height//6, 4, 6)
pygame.draw.rect(surface, siren_color, siren_rect)
# Wheels
wheel_color = (40, 40, 40)
wheel_radius = height//8
# Front wheels
pygame.draw.circle(surface, wheel_color, (width//4, height//4), wheel_radius)
pygame.draw.circle(surface, wheel_color, (width//4, 3*height//4), wheel_radius)
# Rear wheels
pygame.draw.circle(surface, wheel_color, (3*width//4, height//4), wheel_radius)
pygame.draw.circle(surface, wheel_color, (3*width//4, 3*height//4), wheel_radius)
# Border
pygame.draw.rect(surface, (255, 255, 255), surface.get_rect(), 2)
if __name__ == "__main__":
create_vehicle_sprites()