File simulatie/connection.py changed (mode: 100644) (index f4f7402..8acadb2) |
1 |
1 |
import pika |
import pika |
2 |
|
import model |
|
3 |
2 |
import threading |
import threading |
4 |
3 |
|
|
|
4 |
|
import model |
|
5 |
|
import pyg |
|
6 |
|
|
5 |
7 |
creds = pika.PlainCredentials(model.uname, model.passwd) |
creds = pika.PlainCredentials(model.uname, model.passwd) |
6 |
8 |
SendConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds)) |
SendConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds)) |
7 |
9 |
RecieveConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds)) |
RecieveConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds)) |
8 |
10 |
channel = SendConnection.channel() |
channel = SendConnection.channel() |
9 |
11 |
recieve = RecieveConnection.channel() |
recieve = RecieveConnection.channel() |
10 |
12 |
|
|
11 |
|
channel.queue_declare( |
|
12 |
|
queue=model.sendQueue, |
|
|
13 |
|
recieve.queue_declare( |
|
14 |
|
queue=model.recieveQueue, |
13 |
15 |
arguments={'x-message-ttl' : 10000}, |
arguments={'x-message-ttl' : 10000}, |
14 |
16 |
auto_delete=True |
auto_delete=True |
15 |
17 |
) |
) |
|
... |
... |
thread = threading.Thread(target=listen) |
39 |
41 |
thread.setDaemon(True) |
thread.setDaemon(True) |
40 |
42 |
thread.start() |
thread.start() |
41 |
43 |
thread.join(0) |
thread.join(0) |
|
44 |
|
|
|
45 |
|
gamethread = threading.Thread(target=pyg.gameloop) |
|
46 |
|
gamethread.setDaemon(True) |
|
47 |
|
gamethread.start() |
|
48 |
|
gamethread.join(0) |
File simulatie/pyg.py changed (mode: 100644) (index eb29611..87527c7) |
... |
... |
screen = pygame.display.set_mode((800,600)) |
9 |
9 |
screen.fill((255,255,255)) |
screen.fill((255,255,255)) |
10 |
10 |
bg = pygame.transform.scale(pygame.image.load("kruispunt.png"), (800,600)) |
bg = pygame.transform.scale(pygame.image.load("kruispunt.png"), (800,600)) |
11 |
11 |
|
|
12 |
|
class Auto(object): |
|
13 |
|
def __init__(self, x, y): |
|
14 |
|
self.auto = pygame.transform.scale(pygame.image.load("auto.png"), (64,64)) |
|
|
12 |
|
class Vehicle(object): |
|
13 |
|
def __init__(self, x, y, trafficId): |
|
14 |
|
if trafficId >= 100 and trafficId < 200: # Is een auto |
|
15 |
|
self.auto = pygame.transform.scale(pygame.image.load("Auto.png"), (64,64)) |
|
16 |
|
elif trafficId < 300: # Is een bus |
|
17 |
|
self.auto = pygame.transform.scale(pygame.image.load("Auto.png"), (64,64)) |
|
18 |
|
elif trafficId < 400: # Is een fietser |
|
19 |
|
self.auto = pygame.transform.scale(pygame.image.load("Fietser.png"), (64,64)) |
|
20 |
|
elif trafficId < 500: # Is een voetganger |
|
21 |
|
self.auto = pygame.transform.scale(pygame.image.load("Fietser.png"), (64,64)) |
|
22 |
|
elif trafficId < 600: # Is een trein |
|
23 |
|
self.auto = pygame.transform.scale(pygame.image.load("Trein.png"), (64,64)) |
|
24 |
|
else: # zijn slagbomen |
|
25 |
|
pass |
15 |
26 |
self.rect = self.auto.get_rect() |
self.rect = self.auto.get_rect() |
16 |
27 |
self.dest = [x,y] |
self.dest = [x,y] |
17 |
28 |
self.speed = [0,0] |
self.speed = [0,0] |
|
... |
... |
class Auto(object): |
35 |
46 |
self.dest = [x,y] |
self.dest = [x,y] |
36 |
47 |
self.speed = [1,1] |
self.speed = [1,1] |
37 |
48 |
|
|
38 |
|
car = Auto(50,50) |
|
|
49 |
|
car = Vehicle(50,50, 102) |
39 |
50 |
clock = pygame.time.Clock() |
clock = pygame.time.Clock() |
40 |
51 |
car.goto(200,500) |
car.goto(200,500) |
41 |
52 |
|
|
42 |
53 |
# Mainloop |
# Mainloop |
43 |
|
while True: |
|
44 |
|
clock.tick(60) |
|
45 |
|
for event in pygame.event.get(): |
|
46 |
|
if event.type == pygame.QUIT: sys.exit() |
|
47 |
|
|
|
48 |
|
screen.fill((255,255,255)) |
|
49 |
|
screen.blit(bg, bg.get_rect()) |
|
50 |
|
car.update() |
|
51 |
|
screen.blit(car.auto, car.rect) |
|
52 |
|
pygame.display.flip() |
|
|
54 |
|
def gameloop(): |
|
55 |
|
while True: |
|
56 |
|
clock.tick(60) |
|
57 |
|
for event in pygame.event.get(): |
|
58 |
|
if event.type == pygame.QUIT: sys.exit() |
|
59 |
|
|
|
60 |
|
screen.fill((255,255,255)) |
|
61 |
|
#screen.blit(bg, bg.get_rect()) |
|
62 |
|
car.update() |
|
63 |
|
screen.blit(car.auto, car.rect) |
|
64 |
|
pygame.display.flip() |
File simulatie/test/connection.py changed (mode: 100644) (index 69e2a02..2c56479) |
... |
... |
connection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, |
8 |
8 |
channel = connection.channel() |
channel = connection.channel() |
9 |
9 |
recieve = connection.channel() |
recieve = connection.channel() |
10 |
10 |
|
|
11 |
|
channel.queue_declare( |
|
12 |
|
queue=model.sendQueue, |
|
|
11 |
|
recieve.queue_declare( |
|
12 |
|
queue=model.recieveQueue, |
13 |
13 |
arguments={'x-message-ttl' : 10000}, |
arguments={'x-message-ttl' : 10000}, |
14 |
14 |
auto_delete=True |
auto_delete=True |
15 |
15 |
) |
) |