File simulatie/connection.py changed (mode: 100644) (index d40085a..4c7f529) |
... |
... |
def update(index, addCars, dirRequests): |
112 |
112 |
else: |
else: |
113 |
113 |
print("INPUT IS DISABLED!") |
print("INPUT IS DISABLED!") |
114 |
114 |
|
|
115 |
|
def transform(index, original): |
|
116 |
|
if inputEnabled: |
|
117 |
|
msg = json.dumps({ |
|
118 |
|
"TrafficUpdate": { |
|
119 |
|
"LightId": lights[original][0], |
|
120 |
|
"Count": 0,#lights[index][1], |
|
121 |
|
"DirectionRequests": None |
|
122 |
|
} |
|
123 |
|
}, sort_keys=False, indent=4, separators=(',',': ')) |
|
124 |
|
|
|
125 |
|
purelySendMsg(msg) |
|
126 |
|
|
|
127 |
|
msg = json.dumps({ |
|
128 |
|
"TrafficUpdate": { |
|
129 |
|
"LightId": lights[index][0], |
|
130 |
|
"Count": 1,#lights[index][1], |
|
131 |
|
"DirectionRequests": None |
|
132 |
|
} |
|
133 |
|
}, sort_keys=False, indent=4, separators=(',',': ')) |
|
134 |
|
|
|
135 |
|
purelySendMsg(msg) |
|
136 |
|
|
|
137 |
|
else: |
|
138 |
|
print("INPUT IS DISABLED!") |
|
139 |
|
|
|
140 |
115 |
def listen(): |
def listen(): |
141 |
116 |
print('Waiting for a sign..') |
print('Waiting for a sign..') |
142 |
117 |
recieve.basic_consume ( |
recieve.basic_consume ( |
File simulatie/pyg.py changed (mode: 100644) (index f1fb4e2..1c7e252) |
... |
... |
bg = pygame.transform.scale(pygame.image.load("./PlattegrondV5.png"), (800,800)) |
20 |
20 |
class Light(object): |
class Light(object): |
21 |
21 |
def __init__(self, lightIndex): |
def __init__(self, lightIndex): |
22 |
22 |
self.lamp = pygame.image.load("Light.png") |
self.lamp = pygame.image.load("Light.png") |
23 |
|
#self.lamp_tint = self.lamp() |
|
24 |
23 |
self.rect = self.lamp.get_rect() |
self.rect = self.lamp.get_rect() |
25 |
24 |
|
|
26 |
25 |
print("Light " + str(lightIndex) + " -> " + str(tm.lightsPos[lightIndex])) |
print("Light " + str(lightIndex) + " -> " + str(tm.lightsPos[lightIndex])) |
|
... |
... |
class Vehicle(object): |
101 |
100 |
for i in range(0, len(tm.transforms)): |
for i in range(0, len(tm.transforms)): |
102 |
101 |
if tm.transforms[i]["from"] == trafficType: |
if tm.transforms[i]["from"] == trafficType: |
103 |
102 |
return tm.transforms[i]["to"] |
return tm.transforms[i]["to"] |
104 |
|
print("transform found!") |
|
105 |
103 |
return 0 |
return 0 |
106 |
104 |
|
|
107 |
105 |
def update(self): |
def update(self): |
|
... |
... |
class Vehicle(object): |
155 |
153 |
print("NW: " + str(self.wp) + " / " + str(len(tm.waypoints[self.trafficId][self.direction]))) |
print("NW: " + str(self.wp) + " / " + str(len(tm.waypoints[self.trafficId][self.direction]))) |
156 |
154 |
|
|
157 |
155 |
elif not self.waiting: # Check for transform |
elif not self.waiting: # Check for transform |
158 |
|
if str(self.transform) != "0":# and self.transform != None and self.transform != "": |
|
159 |
|
#self.trafficId = self.transform |
|
160 |
|
self.wp = 1 |
|
161 |
|
self.waiting = True |
|
|
156 |
|
if str(self.transform) != "0": |
162 |
157 |
|
|
163 |
158 |
self.transform = self.checkForTransform() |
self.transform = self.checkForTransform() |
164 |
|
connection.transform(self.transform, self.trafficId) # Connection.update moet geen nieuwe vehicle spawnen |
|
165 |
|
self.trafficId = self.transform |
|
166 |
|
print("TRANSFORM: " + str(self.transform)) |
|
|
159 |
|
if self.transform != 0: |
|
160 |
|
|
|
161 |
|
# NOTE: |
|
162 |
|
# self.firedUpdate wordt niet meer op false gezet, |
|
163 |
|
# aangezien een transform voor het wachten geen pad heeft. |
|
164 |
|
|
|
165 |
|
connection.update(self.transform, 1, None) |
|
166 |
|
self.wp = 1 |
|
167 |
|
self.waiting = True |
|
168 |
|
self.trafficId = self.transform |
|
169 |
|
print("TRANSFORM: " + str(self.transform)) |
167 |
170 |
else: |
else: |
168 |
171 |
pass # Destructor here? |
pass # Destructor here? |
169 |
172 |
|
|
|
... |
... |
class Vehicle(object): |
176 |
179 |
return |
return |
177 |
180 |
self.waiting = False |
self.waiting = False |
178 |
181 |
self.wp = 0 |
self.wp = 0 |
179 |
|
connection.update(self.trafficId, -1, None)#self.direction) |
|
|
182 |
|
connection.update(self.trafficId, -1, None) |
180 |
183 |
self.update() |
self.update() |
181 |
184 |
|
|
182 |
185 |
clock = pygame.time.Clock() |
clock = pygame.time.Clock() |
|
... |
... |
clock = pygame.time.Clock() |
184 |
187 |
def update(jsonObj): |
def update(jsonObj): |
185 |
188 |
result = json.loads(jsonObj) |
result = json.loads(jsonObj) |
186 |
189 |
tm.lights = result['Lights'] |
tm.lights = result['Lights'] |
187 |
|
#for i in range(0, len(lights)): |
|
188 |
|
#lights[i].lighCheck() |
|
189 |
190 |
|
|
190 |
191 |
|
|
191 |
192 |
def spawnTrein(naarGroningen): |
def spawnTrein(naarGroningen): |