File simulatie/pyg.py changed (mode: 100644) (index 4dbb9e0..749b178) |
... |
... |
class Vehicle(object): |
28 |
28 |
elif trafficType < 400: # Is een fietser |
elif trafficType < 400: # Is een fietser |
29 |
29 |
self.auto = pygame.transform.scale(pygame.image.load("Fietser.png"), (64,64)) |
self.auto = pygame.transform.scale(pygame.image.load("Fietser.png"), (64,64)) |
30 |
30 |
elif trafficType < 500: # Is een voetganger |
elif trafficType < 500: # Is een voetganger |
31 |
|
self.auto = pygame.transform.scale(pygame.image.load("Fietser.png"), (64,64)) |
|
|
31 |
|
self.auto = pygame.transform.scale(pygame.image.load("Voetganger.png"), (64,64)) |
32 |
32 |
elif trafficType < 600: # Is een trein |
elif trafficType < 600: # Is een trein |
33 |
33 |
self.auto = pygame.transform.scale(pygame.image.load("Trein.png"), (64,64)) |
self.auto = pygame.transform.scale(pygame.image.load("Trein.png"), (64,64)) |
34 |
34 |
else: # zijn slagbomen |
else: # zijn slagbomen |
|
... |
... |
class Vehicle(object): |
44 |
44 |
self.rect.x = tm.queues[trafficId][0][0] |
self.rect.x = tm.queues[trafficId][0][0] |
45 |
45 |
self.rect.y = tm.queues[trafficId][0][1] |
self.rect.y = tm.queues[trafficId][0][1] |
46 |
46 |
|
|
47 |
|
if trafficType == 103 or trafficType == 106 or trafficType == 108 or trafficType == 109 or trafficType == 110: |
|
|
47 |
|
if trafficType == 103 or trafficType == 106 or trafficType == 108 or trafficType == 109 or trafficType == 110 or trafficType == 303 or trafficType == 402: |
48 |
48 |
self.auto = pygame.transform.flip(self.auto, True, False) |
self.auto = pygame.transform.flip(self.auto, True, False) |
49 |
49 |
|
|
50 |
50 |
def update(self): |
def update(self): |
|
... |
... |
class Vehicle(object): |
75 |
75 |
self.wp += 1 |
self.wp += 1 |
76 |
76 |
print("W: " + str(self.wp) + " / " + str(len(tm.queues[self.trafficId]))) |
print("W: " + str(self.wp) + " / " + str(len(tm.queues[self.trafficId]))) |
77 |
77 |
|
|
|
78 |
|
# elif self.waiting: # Debug |
|
79 |
|
# time.sleep(1) |
|
80 |
|
# tm.lights[self.trafficId]["Status"] = 1 # Debug |
|
81 |
|
|
78 |
82 |
elif not self.waiting and self.wp < len(tm.waypoints[self.trafficId]): |
elif not self.waiting and self.wp < len(tm.waypoints[self.trafficId]): |
79 |
83 |
self.goto(tm.waypoints[self.trafficId][self.wp][0], tm.waypoints[self.trafficId][self.wp][1]) |
self.goto(tm.waypoints[self.trafficId][self.wp][0], tm.waypoints[self.trafficId][self.wp][1]) |
80 |
84 |
self.wp += 1 |
self.wp += 1 |
|
... |
... |
def spawnVehicle(index): |
120 |
124 |
|
|
121 |
125 |
# Mainloop |
# Mainloop |
122 |
126 |
def gameloop(): |
def gameloop(): |
123 |
|
id = 5 |
|
124 |
|
car = Vehicle(tm.queues[id][0][0],tm.queues[id][0][1],id) |
|
|
127 |
|
#id = 16 |
|
128 |
|
#car = Vehicle(tm.queues[id][0][0],tm.queues[id][0][1],id) |
125 |
129 |
while True: |
while True: |
126 |
130 |
clock.tick(60) |
clock.tick(60) |
127 |
131 |
for event in pygame.event.get(): |
for event in pygame.event.get(): |
|
... |
... |
def gameloop(): |
131 |
135 |
screen.blit(bg, bg.get_rect()) |
screen.blit(bg, bg.get_rect()) |
132 |
136 |
for vehicle in vehicles: |
for vehicle in vehicles: |
133 |
137 |
vehicle.trafficCheck() |
vehicle.trafficCheck() |
134 |
|
car.trafficCheck() |
|
135 |
|
#screen.blit(car.auto, car.rect) |
|
|
138 |
|
#car.trafficCheck() |
136 |
139 |
pygame.display.flip() |
pygame.display.flip() |
|
140 |
|
|
|
141 |
|
#gameloop() |
File simulatie/trafficModel.py changed (mode: 100644) (index dc21a1d..e67a96e) |
... |
... |
lights = [ |
151 |
151 |
|
|
152 |
152 |
queues = [ |
queues = [ |
153 |
153 |
[ # 101 |
[ # 101 |
154 |
|
[300, -50], |
|
155 |
|
[300, 0], |
|
156 |
|
[300, 140] |
|
|
154 |
|
[300, -50], [300, 140] |
157 |
155 |
], |
], |
158 |
156 |
[ # 102 |
[ # 102 |
159 |
|
[350, -50], |
|
160 |
|
[350, 0], |
|
161 |
|
[350, 140] |
|
|
157 |
|
[350, -50], [350, 140] |
162 |
158 |
], |
], |
163 |
159 |
[ # 103 |
[ # 103 |
164 |
|
[400, -50], |
|
165 |
|
[400, 0], |
|
166 |
|
[400, 140] |
|
|
160 |
|
[400, -50], [400, 140] |
167 |
161 |
], |
], |
168 |
162 |
[ # 104 |
[ # 104 |
169 |
|
[850, 350], |
|
170 |
|
[650, 350] |
|
|
163 |
|
[850, 350], [650, 350] |
171 |
164 |
], |
], |
172 |
165 |
[ # 105 |
[ # 105 |
173 |
|
[850, 400], |
|
174 |
|
[650, 400] |
|
|
166 |
|
[850, 400], [650, 400] |
175 |
167 |
], |
], |
176 |
168 |
[ # 106A |
[ # 106A |
177 |
|
[470, 850], |
|
178 |
|
[470, 690] |
|
|
169 |
|
[470, 850], [470, 690] |
179 |
170 |
], |
], |
180 |
171 |
[ # 107 |
[ # 107 |
181 |
|
[430, 850], |
|
182 |
|
[470, 690] |
|
|
172 |
|
[430, 850], [470, 690] |
183 |
173 |
], |
], |
184 |
174 |
[ #108 |
[ #108 |
185 |
|
[-50, 450], |
|
186 |
|
[150, 450] |
|
|
175 |
|
[-50, 450], [150, 450] |
187 |
176 |
], |
], |
188 |
177 |
[ # 109 |
[ # 109 |
189 |
|
[-50, 400], |
|
190 |
|
[150, 400] |
|
|
178 |
|
[-50, 400], [150, 400] |
191 |
179 |
], |
], |
192 |
180 |
[ # 110 |
[ # 110 |
193 |
|
[-50, 350], |
|
194 |
|
[150, 350] |
|
|
181 |
|
[-50, 350], [150, 350] |
|
182 |
|
], |
|
183 |
|
[ # 201 |
|
184 |
|
[0,0] |
|
185 |
|
], |
|
186 |
|
[ # 301 |
|
187 |
|
[250, -50], [250, 250] |
|
188 |
|
], |
|
189 |
|
[ # 302 |
|
190 |
|
[-50, 250], [250, 250] |
|
191 |
|
], |
|
192 |
|
[ # 303 |
|
193 |
|
[850, 250], [550, 250] |
|
194 |
|
], |
|
195 |
|
[ # 304 |
|
196 |
|
[540, 850], [540, 600] |
|
197 |
|
], |
|
198 |
|
[ # 305 |
|
199 |
|
[260, 850], [260, 500] |
|
200 |
|
], |
|
201 |
|
[ # 401 |
|
202 |
|
[220, -50], [220, 250] |
|
203 |
|
], |
|
204 |
|
[ # 402 |
|
205 |
|
[-50, 200], [270, 200] |
195 |
206 |
] |
] |
196 |
207 |
] |
] |
197 |
208 |
|
|
198 |
209 |
waypoints = [ |
waypoints = [ |
199 |
210 |
[ # 101 |
[ # 101 |
200 |
|
#[300, -50], |
|
201 |
|
#[300, 0], |
|
202 |
|
#[300, 140] |
|
203 |
|
[300, 280], |
|
204 |
|
[-50, 300] |
|
|
211 |
|
[300, 280], [-50, 300] |
205 |
212 |
], |
], |
206 |
213 |
[ # 102 |
[ # 102 |
207 |
|
#[350, -50], |
|
208 |
|
#[350, 0], |
|
209 |
|
[350, 300], |
|
210 |
|
[310, 600], |
|
211 |
|
[310, 850] |
|
|
214 |
|
[350, 300], [310, 600], [310, 850] |
212 |
215 |
], |
], |
213 |
216 |
[ # 103 |
[ # 103 |
214 |
|
#[400, -50], |
|
215 |
|
#[400, 0], |
|
216 |
|
[400, 350], |
|
217 |
|
[850, 450] |
|
|
217 |
|
[400, 350], [850, 450] |
218 |
218 |
], |
], |
219 |
219 |
[ #104 |
[ #104 |
220 |
|
#[850, 350], |
|
221 |
|
[500, 350], |
|
222 |
|
[490, -50] |
|
|
220 |
|
[500, 350], [490, -50] |
223 |
221 |
], |
], |
224 |
222 |
[ #105 |
[ #105 |
225 |
|
#[850, 400], |
|
226 |
|
[500, 400], |
|
227 |
|
[300, 300], |
|
228 |
|
[-50, 300] |
|
|
223 |
|
[500, 400], [300, 300], [-50, 300] |
229 |
224 |
], |
], |
230 |
225 |
[ # 106A |
[ # 106A |
231 |
|
#[470, 850], |
|
232 |
|
[470, 500], |
|
233 |
|
[490, -50] |
|
|
226 |
|
[470, 500], [490, -50] |
234 |
227 |
], |
], |
235 |
228 |
[ # 107 |
[ # 107 |
236 |
|
#[430, 850], |
|
237 |
|
[420, 400], |
|
238 |
|
[300, 300], |
|
239 |
|
[-50, 300] |
|
|
229 |
|
[420, 400], [300, 300], [-50, 300] |
240 |
230 |
], |
], |
241 |
231 |
[ # 108 |
[ # 108 |
242 |
|
#[-50, 450], |
|
243 |
|
[310, 450], |
|
244 |
|
[310, 850] |
|
|
232 |
|
[310, 450], [310, 850] |
245 |
233 |
], |
], |
246 |
234 |
[ # 109 |
[ # 109 |
247 |
|
#[-50, 400], |
|
248 |
|
[310, 400], |
|
249 |
|
[500, 450], |
|
250 |
|
[850, 450] |
|
|
235 |
|
[310, 400], [500, 450], [850, 450] |
251 |
236 |
], |
], |
252 |
237 |
[ # 110 |
[ # 110 |
253 |
|
#[-50, 350], |
|
254 |
|
[450, 350], |
|
255 |
|
[490, -50] |
|
|
238 |
|
[450, 350], [490, -50] |
|
239 |
|
], |
|
240 |
|
[ # 201 |
|
241 |
|
[0,0] |
|
242 |
|
], |
|
243 |
|
[ # 301 |
|
244 |
|
[250, 250], [250, 850] |
|
245 |
|
], |
|
246 |
|
[ # 302 |
|
247 |
|
[250, 250], [850, 250] |
|
248 |
|
], |
|
249 |
|
[ # 303 |
|
250 |
|
[-50, 250] |
|
251 |
|
], |
|
252 |
|
[ # 304 |
|
253 |
|
[540, -50] |
|
254 |
|
], |
|
255 |
|
[ # 305 |
|
256 |
|
[250, -50] |
|
257 |
|
], |
|
258 |
|
[ # 401 |
|
259 |
|
[220, 325] |
|
260 |
|
], |
|
261 |
|
[ # 402 |
|
262 |
|
[470, 200] |
256 |
263 |
] |
] |
|
264 |
|
] |
257 |
265 |
|
|
|
266 |
|
transforms = [ |
|
267 |
|
{ "from": 401, "to": 411}, |
|
268 |
|
{ "from": 402, "to": 408}, |
|
269 |
|
{ "from": 403, "to": 407}, |
|
270 |
|
{ "from": 404, "to": 410}, |
|
271 |
|
{ "from": 405, "to": 409}, |
|
272 |
|
{ "from": 406, "to": 412} |
258 |
273 |
] |
] |