shuvit 4 years ago
parent
commit
dc9b7dd61e
7 changed files with 16 additions and 457 deletions
  1. 0
    112
      scripts/StatesCar.py
  2. 4
    116
      scripts/StatesWalker.py
  3. 2
    78
      scripts/astar.py
  4. 1
    11
      scripts/birds.py
  5. 5
    25
      scripts/camera.py
  6. 4
    74
      scripts/cars.py
  7. 0
    41
      scripts/walkers.py

+ 0
- 112
scripts/StatesCar.py View File

61
     for x in potentials:
61
     for x in potentials:
62
         min_dist = 45
62
         min_dist = 45
63
         dist = self.obj.getDistanceTo(x.obj)
63
         dist = self.obj.getDistanceTo(x.obj)
64
-        #print('dist to potential', dist)
65
         if dist < min_dist:
64
         if dist < min_dist:
66
             potentials.remove(x)
65
             potentials.remove(x)
67
-            #print('----removing potential')
68
     if len(potentials) > 0:
66
     if len(potentials) > 0:
69
-
70
         new_parking = random.choice(potentials)
67
         new_parking = random.choice(potentials)
71
-        #path = self.manager.navmesh.findPath(self.start_empty.obj.worldPosition, new_parking.obj.worldPosition)
72
         path2 = self.manager.navmesh2.queue_path(self.start_empty.obj.worldPosition, new_parking.obj.worldPosition, self)
68
         path2 = self.manager.navmesh2.queue_path(self.start_empty.obj.worldPosition, new_parking.obj.worldPosition, self)
73
-        #print('parking added at', new_parking.obj.worldPosition)
74
-        #path.remove(path[0])
75
-        #mark_path(path, self)
76
         return new_parking, path2
69
         return new_parking, path2
77
     else:
70
     else:
78
-        #print('cant find parking for', self)
79
         self.FSM.FSM.ToTransition('toEnterParallelPark')
71
         self.FSM.FSM.ToTransition('toEnterParallelPark')
80
 
72
 
81
 def get_lane_point(self):
73
 def get_lane_point(self):
88
         self.lane_point = self.point + self.manager.lane_position * nv
80
         self.lane_point = self.point + self.manager.lane_position * nv
89
     else:
81
     else:
90
         pass
82
         pass
91
-        #print('skipping lane point')
92
 
83
 
93
 def update_point(self):
84
 def update_point(self):
94
-    #print(self.path_index, 'path index', len(self.path))
95
     if self.path_index >= (len(self.path) ):
85
     if self.path_index >= (len(self.path) ):
96
         self.FSM.FSM.ToTransition('toEnterParallelPark')
86
         self.FSM.FSM.ToTransition('toEnterParallelPark')
97
     else:
87
     else:
105
                 self.path_index += 1
95
                 self.path_index += 1
106
          
96
          
107
 def align_to_point(self):
97
 def align_to_point(self):
108
-    #print('lane_point', self.lane_point)
109
     v = self.obj.getVectTo(self.lane_point)[1]
98
     v = self.obj.getVectTo(self.lane_point)[1]
110
     v.z = 0
99
     v.z = 0
111
     self.obj.alignAxisToVect(v, 0, .1)
100
     self.obj.alignAxisToVect(v, 0, .1)
175
         self.FSM.owner.obj.restorePhysics()
164
         self.FSM.owner.obj.restorePhysics()
176
         self.FSM.owner.obj.restoreDynamics()
165
         self.FSM.owner.obj.restoreDynamics()
177
         self.FSM.owner.obj.linearVelocity = [0,0,0]
166
         self.FSM.owner.obj.linearVelocity = [0,0,0]
178
-        # self.FSM.owner.target, self.FSM.owner.path = find_new_parking(self.FSM.owner)
179
         self.FSM.owner.path_index = 0
167
         self.FSM.owner.path_index = 0
180
         self.FSM.owner.point = self.FSM.owner.path[self.FSM.owner.path_index]
168
         self.FSM.owner.point = self.FSM.owner.path[self.FSM.owner.path_index]
181
         self.FSM.owner.target.status = 'targetted'
169
         self.FSM.owner.target.status = 'targetted'
182
         self.FSM.owner.start_empty.status = 'available'
170
         self.FSM.owner.start_empty.status = 'available'
183
-        #mark_path(self.FSM.owner.path, self.FSM.owner)
184
-        print('physics resumed')
185
         super(ExitParallelPark, self).Enter()        
171
         super(ExitParallelPark, self).Enter()        
186
         
172
         
187
     def Execute(self):
173
     def Execute(self):
203
         
189
         
204
     def Enter(self):
190
     def Enter(self):
205
         self.FSM.stateLife = 1
191
         self.FSM.stateLife = 1
206
-        #print('entering parallel park')
207
         self.FSM.owner.obj.worldPosition = self.FSM.owner.target.obj.worldPosition.copy()
192
         self.FSM.owner.obj.worldPosition = self.FSM.owner.target.obj.worldPosition.copy()
208
         self.FSM.owner.obj.worldOrientation = self.FSM.owner.target.obj.worldOrientation.copy()
193
         self.FSM.owner.obj.worldOrientation = self.FSM.owner.target.obj.worldOrientation.copy()
209
         self.FSM.owner.obj.applyMovement([0, -6, 0], True)
194
         self.FSM.owner.obj.applyMovement([0, -6, 0], True)
217
         self.FSM.owner.point = self.FSM.owner.target.obj.worldPosition.copy()
202
         self.FSM.owner.point = self.FSM.owner.target.obj.worldPosition.copy()
218
         self.FSM.owner.path_index = 0
203
         self.FSM.owner.path_index = 0
219
         self.FSM.owner.path = None
204
         self.FSM.owner.path = None
220
-        #print('clearning last path')
221
-        
222
         clear_markers(self)
205
         clear_markers(self)
223
-        
224
-        #self.FSM.owner.obj.suspendDynamics()
225
-        #self.FSM.owner.obj.suspendPhysics()
226
         super(EnterParallelPark, self).Enter()        
206
         super(EnterParallelPark, self).Enter()        
227
         
207
         
228
     def Execute(self):
208
     def Execute(self):
277
 
257
 
278
     def drive_to_point(self):
258
     def drive_to_point(self):
279
         pass
259
         pass
280
-        # if self.FSM.path:
281
-        #     ground_ray = get_ground_ray(self)
282
-        #     if ground_ray[0]:
283
-        #         set_height(self, ground_ray)
284
-        #         align_to_road(self, ground_ray) 
285
-
286
-        #     v = self.FSM.owner.getVectTo(self.lane_point)               
287
-        #     speed_force = 800.0
288
-        #     max_speed = 5.0
289
-        #     behind = False
290
-        #     local = self.FSM.owner.worldOrientation.inverted() * (self.lane_point - self.FSM.owner.worldPosition) 
291
-        #     v2 = v[1].copy()
292
-        #     v2.z = 0
293
-        #     delta = self.last_lane_point - self.lane_point
294
-        #     delta = delta.cross(v[1])
295
-        #     delta_mult = -.1
296
-        #     mult = 1.0
297
-        #     backup_time = 20
298
-
299
-        #     #change max speed
300
-        #     if self.FSM.stateLife % 180 == 0:
301
-        #         print('change speed force')
302
-        #         self.speed_force = random.choice([max_speed * 1.3, max_speed * 1.6, max_speed * .8, max_speed * .6, max_speed])
303
-
304
-        #     if local.x > 0 and self.backup == 0:
305
-
306
-        #         if self.FSM.owner.linearVelocity.x < self.max_speed:
307
-        #             self.FSM.owner.applyForce([speed_force, 0, 0], True)
308
-
309
-        #         deltamove = delta[2] * delta_mult
310
-        #         #self.FSM.owner.applyMovement([0, deltamove, 0], True)
311
-
312
-        #         f = deltamove * 5000
313
-        #         self.FSM.owner.applyForce([0, f, 0], True)
314
-        #         v = self.FSM.owner.getVectTo(self.lane_point)
315
-        #         v2 = v[1].copy()
316
-        #         v2.z = 0
317
-        #         self.FSM.owner.alignAxisToVect(v2, 0, .05)
318
-
319
-
320
-        #     else:
321
-        #         if local.x < 0:
322
-        #             self.backup = backup_time   
323
-
324
-        #         if self.backup > 0:
325
-        #             print('backing up')
326
-        #             v = self.FSM.owner.getVectTo(self.FSM.path[0])
327
-        #             v2 = v[1].copy()
328
-        #             v2.z = 0
329
-        #             self.FSM.owner.alignAxisToVect(v2, 0, .02)
330
-        #             if self.FSM.owner.linearVelocity.x > -max_speed / 2:
331
-        #                 self.FSM.owner.applyForce([-speed_force * .8, 0, 0], True)
332
-        #             self.backup -= 1
333
-
334
-        #     dist = self.FSM.owner.getDistanceTo(self.lane_point)
335
-
336
-        #     if dist < 2.5 and (len(self.FSM.path) > 0):    
337
-        #         #print(self.FSM.path,'this is the path')
338
-        #         #print('navmesh point removed')
339
-        #         self.last_point = self.point
340
-        #         self.last_lane_point = self.lane_point
341
-        #         self.FSM.path.remove(self.FSM.path[0])
342
-
343
-        #         if len(self.FSM.path) > 0:
344
-        #             self.point = self.FSM.path[0]
345
-        #             v = Vector([self.last_point.x - self.point.x, self.last_point.y - self.point.y, 0])
346
-        #             tv = v.normalized()
347
-        #             nv = Vector([-tv.y, tv.x, 0]) #rotate 90 degrees
348
-        #             self.lane_point = self.point + self.lane_position * nv
349
-
350
-        #         else:
351
-        #             self.point = None
352
-
353
-        #     if self.FSM.path == []:
354
-        #         self.FSM.curTarget = None          
355
-
356
-        #     #progress
357
-        #     self.pos_his.append(self.FSM.owner.worldPosition.copy())
358
-        #     pos_his_len = len(self.pos_his)
359
-        #     if pos_his_len > 200:
360
-                
361
-        #         sum_ = abs(self.FSM.owner.worldPosition.x - self.pos_his[0][0]) + abs(self.FSM.owner.worldPosition.y - self.pos_his[0][1])
362
-        #         #print(sum_, 'sum')
363
-        #         if sum_ < .05:
364
-        #             self.backup = backup_time
365
-        #             print('progress stopped')
366
-        #         del self.pos_his[0]
367
-            
368
 
260
 
369
     def Execute(self):
261
     def Execute(self):
370
         self.FSM.stateLife += 1
262
         self.FSM.stateLife += 1
380
         
272
         
381
     def Enter(self):
273
     def Enter(self):
382
         self.FSM.stateLife = 1
274
         self.FSM.stateLife = 1
383
-
384
         self.FSM.owner.target, self.FSM.owner.path = find_new_parking(self.FSM.owner)
275
         self.FSM.owner.target, self.FSM.owner.path = find_new_parking(self.FSM.owner)
385
         self.FSM.owner.path_index = 0
276
         self.FSM.owner.path_index = 0
386
         super(RequestPath, self).Enter()        
277
         super(RequestPath, self).Enter()        
387
         
278
         
388
     def Execute(self):
279
     def Execute(self):
389
         self.FSM.stateLife += 1
280
         self.FSM.stateLife += 1
390
-        #own['ped_astar'] = Astar('nav_points')
391
-        #own['ped_astar'].get_path([5,-12,1] , [16,16,1])
392
-        #print('doing example')
393
         
281
         
394
     def Exit(self):
282
     def Exit(self):
395
         pass
283
         pass

+ 4
- 116
scripts/StatesWalker.py View File

25
             x.endObject()
25
             x.endObject()
26
         except:
26
         except:
27
             pass
27
             pass
28
+            
28
 def get_ground_ray(self):
29
 def get_ground_ray(self):
29
     Axis = 2
30
     Axis = 2
30
     Distance = -10
31
     Distance = -10
61
     for x in potentials:
62
     for x in potentials:
62
         min_dist = 45
63
         min_dist = 45
63
         dist = self.obj.getDistanceTo(x.obj)
64
         dist = self.obj.getDistanceTo(x.obj)
64
-        #print('dist to potential', dist)
65
         if dist < min_dist:
65
         if dist < min_dist:
66
             potentials.remove(x)
66
             potentials.remove(x)
67
-            #print('----removing potential')
68
-    if len(potentials) > 0:
69
 
67
 
68
+    if len(potentials) > 0:
70
         new_parking = random.choice(potentials)
69
         new_parking = random.choice(potentials)
71
-        #path = self.manager.navmesh.findPath(self.start_empty.obj.worldPosition, new_parking.obj.worldPosition)
72
         path2 = self.manager.navmesh2.queue_path(self.start_empty.obj.worldPosition, new_parking.obj.worldPosition, self)
70
         path2 = self.manager.navmesh2.queue_path(self.start_empty.obj.worldPosition, new_parking.obj.worldPosition, self)
73
-        #print('parking added at', new_parking.obj.worldPosition)
74
-        #path.remove(path[0])
75
-        #mark_path(path, self)
76
         return new_parking, path2
71
         return new_parking, path2
77
     else:
72
     else:
78
-        #print('cant find parking for', self)
79
         self.FSM.FSM.ToTransition('toEnterParallelPark')
73
         self.FSM.FSM.ToTransition('toEnterParallelPark')
80
 
74
 
81
 def get_lane_point(self):
75
 def get_lane_point(self):
88
         self.lane_point = self.point + self.manager.lane_position * nv
82
         self.lane_point = self.point + self.manager.lane_position * nv
89
     else:
83
     else:
90
         pass
84
         pass
91
-        #print('skipping lane point')
92
 
85
 
93
 def update_point(self):
86
 def update_point(self):
94
-    #print(self.path_index, 'path index', len(self.path))
95
     if self.path_index >= (len(self.path) ):
87
     if self.path_index >= (len(self.path) ):
96
         self.FSM.FSM.ToTransition('toEnterParallelPark')
88
         self.FSM.FSM.ToTransition('toEnterParallelPark')
97
     else:
89
     else:
105
                 self.path_index += 1
97
                 self.path_index += 1
106
          
98
          
107
 def align_to_point(self):
99
 def align_to_point(self):
108
-    #print('lane_point', self.lane_point)
109
     v = self.obj.getVectTo(self.lane_point)[1]
100
     v = self.obj.getVectTo(self.lane_point)[1]
110
     v.z = 0
101
     v.z = 0
111
     self.obj.alignAxisToVect(v, 0, .1)
102
     self.obj.alignAxisToVect(v, 0, .1)
125
         f *= -1
116
         f *= -1
126
     self.obj.applyForce([0, f, 0], True)
117
     self.obj.applyForce([0, f, 0], True)
127
             
118
             
128
-              
129
 def apply_gas(self):
119
 def apply_gas(self):
130
     if self.obj.linearVelocity.x < self.speed_targ:
120
     if self.obj.linearVelocity.x < self.speed_targ:
131
         self.obj.applyForce([self.speed_inc, 0, 0], True)
121
         self.obj.applyForce([self.speed_inc, 0, 0], True)
175
         self.FSM.owner.obj.restorePhysics()
165
         self.FSM.owner.obj.restorePhysics()
176
         self.FSM.owner.obj.restoreDynamics()
166
         self.FSM.owner.obj.restoreDynamics()
177
         self.FSM.owner.obj.linearVelocity = [0,0,0]
167
         self.FSM.owner.obj.linearVelocity = [0,0,0]
178
-        # self.FSM.owner.target, self.FSM.owner.path = find_new_parking(self.FSM.owner)
179
         self.FSM.owner.path_index = 0
168
         self.FSM.owner.path_index = 0
180
         self.FSM.owner.point = self.FSM.owner.path[self.FSM.owner.path_index]
169
         self.FSM.owner.point = self.FSM.owner.path[self.FSM.owner.path_index]
181
         self.FSM.owner.target.status = 'targetted'
170
         self.FSM.owner.target.status = 'targetted'
182
         self.FSM.owner.start_empty.status = 'available'
171
         self.FSM.owner.start_empty.status = 'available'
183
-        #mark_path(self.FSM.owner.path, self.FSM.owner)
184
         print('physics resumed')
172
         print('physics resumed')
185
         super(ExitParallelPark, self).Enter()        
173
         super(ExitParallelPark, self).Enter()        
186
         
174
         
203
         
191
         
204
     def Enter(self):
192
     def Enter(self):
205
         self.FSM.stateLife = 1
193
         self.FSM.stateLife = 1
206
-        #print('entering parallel park')
207
         self.FSM.owner.obj.worldPosition = self.FSM.owner.target.obj.worldPosition.copy()
194
         self.FSM.owner.obj.worldPosition = self.FSM.owner.target.obj.worldPosition.copy()
208
         self.FSM.owner.obj.worldOrientation = self.FSM.owner.target.obj.worldOrientation.copy()
195
         self.FSM.owner.obj.worldOrientation = self.FSM.owner.target.obj.worldOrientation.copy()
209
         self.FSM.owner.obj.applyMovement([0, 0, 0], True)
196
         self.FSM.owner.obj.applyMovement([0, 0, 0], True)
217
         self.FSM.owner.point = self.FSM.owner.target.obj.worldPosition.copy()
204
         self.FSM.owner.point = self.FSM.owner.target.obj.worldPosition.copy()
218
         self.FSM.owner.path_index = 0
205
         self.FSM.owner.path_index = 0
219
         self.FSM.owner.path = None
206
         self.FSM.owner.path = None
220
-        #print('clearning last path')
221
-        
222
-        clear_markers(self)
223
-        
224
-        #self.FSM.owner.obj.suspendDynamics()
225
-        #self.FSM.owner.obj.suspendPhysics()
226
         super(EnterParallelPark, self).Enter()        
207
         super(EnterParallelPark, self).Enter()        
227
         
208
         
228
     def Execute(self):
209
     def Execute(self):
255
         delta_to_vect(self.FSM.owner)
236
         delta_to_vect(self.FSM.owner)
256
         apply_gas(self.FSM.owner)
237
         apply_gas(self.FSM.owner)
257
 
238
 
258
-        #emergency exit
259
         if self.FSM.stateLife > 30 * 180 * 3:
239
         if self.FSM.stateLife > 30 * 180 * 3:
260
             self.FSM.ToTransition('toEnterParallelPark')
240
             self.FSM.ToTransition('toEnterParallelPark')
261
 
241
 
277
 
257
 
278
     def drive_to_point(self):
258
     def drive_to_point(self):
279
         pass
259
         pass
280
-        # if self.FSM.path:
281
-        #     ground_ray = get_ground_ray(self)
282
-        #     if ground_ray[0]:
283
-        #         set_height(self, ground_ray)
284
-        #         align_to_road(self, ground_ray) 
285
-
286
-        #     v = self.FSM.owner.getVectTo(self.lane_point)               
287
-        #     speed_force = 800.0
288
-        #     max_speed = 5.0
289
-        #     behind = False
290
-        #     local = self.FSM.owner.worldOrientation.inverted() * (self.lane_point - self.FSM.owner.worldPosition) 
291
-        #     v2 = v[1].copy()
292
-        #     v2.z = 0
293
-        #     delta = self.last_lane_point - self.lane_point
294
-        #     delta = delta.cross(v[1])
295
-        #     delta_mult = -.1
296
-        #     mult = 1.0
297
-        #     backup_time = 20
298
-
299
-        #     #change max speed
300
-        #     if self.FSM.stateLife % 180 == 0:
301
-        #         print('change speed force')
302
-        #         self.speed_force = random.choice([max_speed * 1.3, max_speed * 1.6, max_speed * .8, max_speed * .6, max_speed])
303
-
304
-        #     if local.x > 0 and self.backup == 0:
305
-
306
-        #         if self.FSM.owner.linearVelocity.x < self.max_speed:
307
-        #             self.FSM.owner.applyForce([speed_force, 0, 0], True)
308
-
309
-        #         deltamove = delta[2] * delta_mult
310
-        #         #self.FSM.owner.applyMovement([0, deltamove, 0], True)
311
-
312
-        #         f = deltamove * 5000
313
-        #         self.FSM.owner.applyForce([0, f, 0], True)
314
-        #         v = self.FSM.owner.getVectTo(self.lane_point)
315
-        #         v2 = v[1].copy()
316
-        #         v2.z = 0
317
-        #         self.FSM.owner.alignAxisToVect(v2, 0, .05)
318
-
319
-
320
-        #     else:
321
-        #         if local.x < 0:
322
-        #             self.backup = backup_time   
323
-
324
-        #         if self.backup > 0:
325
-        #             print('backing up')
326
-        #             v = self.FSM.owner.getVectTo(self.FSM.path[0])
327
-        #             v2 = v[1].copy()
328
-        #             v2.z = 0
329
-        #             self.FSM.owner.alignAxisToVect(v2, 0, .02)
330
-        #             if self.FSM.owner.linearVelocity.x > -max_speed / 2:
331
-        #                 self.FSM.owner.applyForce([-speed_force * .8, 0, 0], True)
332
-        #             self.backup -= 1
333
-
334
-        #     dist = self.FSM.owner.getDistanceTo(self.lane_point)
335
-
336
-        #     if dist < 2.5 and (len(self.FSM.path) > 0):    
337
-        #         #print(self.FSM.path,'this is the path')
338
-        #         #print('navmesh point removed')
339
-        #         self.last_point = self.point
340
-        #         self.last_lane_point = self.lane_point
341
-        #         self.FSM.path.remove(self.FSM.path[0])
342
-
343
-        #         if len(self.FSM.path) > 0:
344
-        #             self.point = self.FSM.path[0]
345
-        #             v = Vector([self.last_point.x - self.point.x, self.last_point.y - self.point.y, 0])
346
-        #             tv = v.normalized()
347
-        #             nv = Vector([-tv.y, tv.x, 0]) #rotate 90 degrees
348
-        #             self.lane_point = self.point + self.lane_position * nv
349
-
350
-        #         else:
351
-        #             self.point = None
352
-
353
-        #     if self.FSM.path == []:
354
-        #         self.FSM.curTarget = None          
355
-
356
-        #     #progress
357
-        #     self.pos_his.append(self.FSM.owner.worldPosition.copy())
358
-        #     pos_his_len = len(self.pos_his)
359
-        #     if pos_his_len > 200:
360
-                
361
-        #         sum_ = abs(self.FSM.owner.worldPosition.x - self.pos_his[0][0]) + abs(self.FSM.owner.worldPosition.y - self.pos_his[0][1])
362
-        #         #print(sum_, 'sum')
363
-        #         if sum_ < .05:
364
-        #             self.backup = backup_time
365
-        #             print('progress stopped')
366
-        #         del self.pos_his[0]
367
-            
368
-
260
+        
369
     def Execute(self):
261
     def Execute(self):
370
         self.FSM.stateLife += 1
262
         self.FSM.stateLife += 1
371
 
263
 
387
         
279
         
388
     def Execute(self):
280
     def Execute(self):
389
         self.FSM.stateLife += 1
281
         self.FSM.stateLife += 1
390
-        #own['ped_astar'] = Astar('nav_points')
391
-        #own['ped_astar'].get_path([5,-12,1] , [16,16,1])
392
-        #print('doing example')
393
-        
282
+
394
     def Exit(self):
283
     def Exit(self):
395
-        pass

+ 2
- 78
scripts/astar.py View File

9
         return value
9
         return value
10
     return wrapper
10
     return wrapper
11
 
11
 
12
-def draw(locs, self):
13
-    for x in locs:
14
-        b = bge.logic.getCurrentScene().addObject('ball')
15
-        b.worldPosition = self.points[x].loc
16
-        b.color = [1,0,0,1]
17
-        
18
-def draw_mesh(self):
19
-    self.searched = set(self.searched)
20
-    for x in self.searched:
21
-        b = bge.logic.getCurrentScene().addObject('ball')
22
-        b.worldPosition = x.loc
23
-        b.color = [0,0,1,1]
24
-        b.worldScale = [.5, .5, .5] 
25
-    
26
-def draw_searched(self):
27
-    pass
28
-
29
-def draw_se(self):        
30
-    b = bge.logic.getCurrentScene().addObject('ball')
31
-    b.worldPosition = self.start.loc
32
-    b.color = [0,1,0,1]
33
-    b.worldScale = [.75, .75, .75] 
34
-    #----    
35
-    b = bge.logic.getCurrentScene().addObject('ball')
36
-    b.worldPosition = self.end.loc
37
-    b.color = [1,1,0,1]
38
-    b.worldScale = [2, 2, 2]  
39
-
40
 def draw_all(self):
12
 def draw_all(self):
41
     for x in self.points:
13
     for x in self.points:
42
-
43
         pm = bge.logic.getCurrentScene().addObject('path_marker')
14
         pm = bge.logic.getCurrentScene().addObject('path_marker')
44
         pm.worldPosition = x.loc
15
         pm.worldPosition = x.loc
45
         pm.color = [1,1,0,1]
16
         pm.color = [1,1,0,1]
50
         return iter(cls._registry)
21
         return iter(cls._registry)
51
 
22
 
52
 def load_points(points_file):        
23
 def load_points(points_file):        
53
-    #mainDir = bge.logic.expandPath("//")
54
     mainDir = bge.logic.expandPath("//assets/")
24
     mainDir = bge.logic.expandPath("//assets/")
55
     fileName = mainDir + points_file    
25
     fileName = mainDir + points_file    
56
     with open(fileName, 'r') as filehandle:        
26
     with open(fileName, 'r') as filehandle:        
70
     length = (end - start).magnitude
40
     length = (end - start).magnitude
71
     return length
41
     return length
72
 
42
 
73
-
74
-
75
 class Point(object):
43
 class Point(object):
76
     __metaclass__ = IterRegistry
44
     __metaclass__ = IterRegistry
77
     _registry = []
45
     _registry = []
131
         self.life += 1
99
         self.life += 1
132
         if self.state == 'searching':
100
         if self.state == 'searching':
133
             self.search()
101
             self.search()
134
-            #print('life', self.life)
135
             if self.life > 5000:
102
             if self.life > 5000:
136
-                #print('path failed')
137
                 self.state = 'idle'
103
                 self.state = 'idle'
138
         else:
104
         else:
139
-            #print('updating pathfinder queue')
140
             self.update_queue()        
105
             self.update_queue()        
141
              
106
              
142
     def get_results(self):
107
     def get_results(self):
143
         result_locs = []
108
         result_locs = []
144
         results = []
109
         results = []
145
-        #print('self.end', self.end, self.end.id)
146
         cp = self.end   
110
         cp = self.end   
147
         breaker = 0
111
         breaker = 0
148
         while cp != self.start:
112
         while cp != self.start:
154
                 cp = cp.prev
118
                 cp = cp.prev
155
             breaker += 1
119
             breaker += 1
156
             if breaker > 2000:
120
             if breaker > 2000:
157
-                #print('breaking results')
158
                 break
121
                 break
159
-        #if cp == self.start:
160
-            #print('start found!!')
161
-        #print('sp', self.start.id, 'ep', self.end.id)
162
-        #print('final path', result_locs, len(result_locs)) 
163
-        #draw_mesh(self)
164
-        #draw(result_locs, self)  
165
-        #publish
166
         results.reverse()
122
         results.reverse()
167
         self.messenger.dispatch('path found', ['found path for object', self.current_searcher, results])
123
         self.messenger.dispatch('path found', ['found path for object', self.current_searcher, results])
168
-        #draw_all(self)
169
 
124
 
170
     def smallest_f(self):
125
     def smallest_f(self):
171
         if len(self.open) > 1:
126
         if len(self.open) > 1:
175
                 l.append(x)
130
                 l.append(x)
176
                 lfs.append(x.f)
131
                 lfs.append(x.f)
177
             ind = lfs.index(min(lfs))  
132
             ind = lfs.index(min(lfs))  
178
-            #print(ind, lfs, l[ind]) 
179
             return l[ind]
133
             return l[ind]
180
         else:
134
         else:
181
             return self.start
135
             return self.start
182
             
136
             
183
     #@chrono    
137
     #@chrono    
184
     def search(self):
138
     def search(self):
185
-        #Loop until you find the end
186
         tries = 0
139
         tries = 0
187
         if self.open == []:
140
         if self.open == []:
188
-            draw_mesh(self)
189
             self.state = 'inactive'
141
             self.state = 'inactive'
190
 
142
 
191
         while self.open != []:
143
         while self.open != []:
192
-            #Get the current node from open list with smallest fval
193
             try:
144
             try:
194
                 self.open.remove(self.current)
145
                 self.open.remove(self.current)
195
             except:
146
             except:
196
                 pass
147
                 pass
197
-                #print('current is not in open, cant remove')
198
             current_node = self.smallest_f()
148
             current_node = self.smallest_f()
199
             self.current = current_node
149
             self.current = current_node
200
             self.searched.append(current_node)
150
             self.searched.append(current_node)
201
-             #remove from open
202
             self.closed.append(current_node) #add to closed
151
             self.closed.append(current_node) #add to closed
203
             if current_node == self.end:
152
             if current_node == self.end:
204
-                #print('path found')
205
                 path = self.get_results()
153
                 path = self.get_results()
206
-                #print('p', path)
207
                 self.state = 'inactive'
154
                 self.state = 'inactive'
208
                 self.open = []
155
                 self.open = []
209
                 break                
156
                 break                
157
+
210
             else:
158
             else:
211
                 children = current_node.neighbors
159
                 children = current_node.neighbors
212
                 for child in children:
160
                 for child in children:
229
                         self.closed[:] = [x for x in self.closed if x != child]    
177
                         self.closed[:] = [x for x in self.closed if x != child]    
230
                         self.open.append(child)
178
                         self.open.append(child)
231
 
179
 
232
-#            print('trying', current_node.id, current_node.f, len(self.open))
233
-#            nei = []
234
-#            for z in current_node.neighbors:
235
-#                nei.append(z.id)
236
             tries += 1
180
             tries += 1
237
             if tries >= 5:
181
             if tries >= 5:
238
                 break                      
182
                 break                      
244
                 num = iter
188
                 num = iter
245
             else:
189
             else:
246
                 pass
190
                 pass
247
-                #print('cant get navmesh neighbor id')    
248
             iter += 1    
191
             iter += 1    
249
-        #print(num, 'id')
250
         
192
         
251
     def set_gscore(self):
193
     def set_gscore(self):
252
         self.gscores = []
194
         self.gscores = []
267
 
209
 
268
     def queue_path(self, start_in, end_in, obj):
210
     def queue_path(self, start_in, end_in, obj):
269
         self.queue.append([start_in, end_in, obj])
211
         self.queue.append([start_in, end_in, obj])
270
-        #obj.manager.pub.register("path found", obj)
271
-        #print('queueing path', len(self.queue))
272
 
212
 
273
     def update_queue(self):
213
     def update_queue(self):
274
         if self.queue != []:
214
         if self.queue != []:
275
-            #print('--getting next path in queue')
276
             self.get_path(self.queue[0][0], self.queue[0][1], self.queue[0][2])
215
             self.get_path(self.queue[0][0], self.queue[0][1], self.queue[0][2])
277
             self.queue.remove(self.queue[0])           
216
             self.queue.remove(self.queue[0])           
278
                          
217
                          
289
         self.open.append(self.start)
228
         self.open.append(self.start)
290
         self.set_gscore()
229
         self.set_gscore()
291
         self.current = self.start
230
         self.current = self.start
292
-        #beginning search
293
-        #Initialize both open and closed list
294
         self.open = []
231
         self.open = []
295
         self.closed = []
232
         self.closed = []
296
         self.searched = []
233
         self.searched = []
297
-
298
-        #Add the start node
299
         self.open.append(self.start)
234
         self.open.append(self.start)
300
         self.current = self.start
235
         self.current = self.start
301
         self.current.g = 0
236
         self.current.g = 0
302
         self.current.f = 0
237
         self.current.f = 0
303
         self.current.h = get_distance(self.current.loc, self.end.loc)
238
         self.current.h = get_distance(self.current.loc, self.end.loc)
304
-        #draw_se(self)
305
-        print('start', self.start.id, 'end', self.end.id)
306
-        
307
-# def main(cont):
308
-#     own = cont.owner
309
-#     if 'inited' not in own:
310
-#         own['inited'] = True
311
-#         own['ped_astar'] = Astar('nav_points')
312
-#         own['ped_astar'].get_path([5,-12,1] , [16,16,1])
313
-        
314
-#     own['ped_astar'].update()
315
-
239
+        

+ 1
- 11
scripts/birds.py View File

1
 import bge
1
 import bge
2
 import random
2
 import random
3
 
3
 
4
-
5
-        
6
 def bird(cont):
4
 def bird(cont):
7
     own = cont.owner
5
     own = cont.owner
8
     if 'inited' not in own:
6
     if 'inited' not in own:
12
         act.target = own['end']
10
         act.target = own['end']
13
         act.velocity = 2
11
         act.velocity = 2
14
         cont.activate(act)
12
         cont.activate(act)
15
-        #print('doing bird')
16
     if own.getDistanceTo(own['end']) < 1:
13
     if own.getDistanceTo(own['end']) < 1:
17
         own.endObject()
14
         own.endObject()
18
-        #print('kill bird') 
19
 
15
 
20
 def main(cont, scene):
16
 def main(cont, scene):
21
-
22
     def build_bird_list(scene,own):
17
     def build_bird_list(scene,own):
23
         own['bird_list'] = []
18
         own['bird_list'] = []
24
         for x in scene.objects:
19
         for x in scene.objects:
30
             if own['life'] % 50 == 0:
25
             if own['life'] % 50 == 0:
31
                 num = random.randint(0,2)
26
                 num = random.randint(0,2)
32
                 if num == 1:
27
                 if num == 1:
33
-                    #print('add bird')
34
                     top = len(own['bird_list']) - 1
28
                     top = len(own['bird_list']) - 1
35
                     start = random.randint(0, top)
29
                     start = random.randint(0, top)
36
                     end = start
30
                     end = start
40
                     obj['start'] = own['bird_list'][start]
34
                     obj['start'] = own['bird_list'][start]
41
                     obj['end'] = own['bird_list'][end]
35
                     obj['end'] = own['bird_list'][end]
42
                     obj.worldPosition = obj['start'].worldPosition
36
                     obj.worldPosition = obj['start'].worldPosition
43
-                    #print(obj['start'], obj['end'])
44
                 
37
                 
45
     def life(own):
38
     def life(own):
46
         if 'life' in own:
39
         if 'life' in own:
48
         else:
41
         else:
49
             own['life'] = 0    
42
             own['life'] = 0    
50
         
43
         
51
-  
52
-
53
     own = cont.owner
44
     own = cont.owner
54
     if 'binited' not in own:
45
     if 'binited' not in own:
55
         build_bird_list(scene, own)            
46
         build_bird_list(scene, own)            
56
         own['binited'] = True
47
         own['binited'] = True
57
 
48
 
58
     life(own)    
49
     life(own)    
59
-    do_birds(scene, own, cont)  
60
-    #print('birding')    
50
+    do_birds(scene, own, cont)  

+ 5
- 25
scripts/camera.py View File

11
 import walkers
11
 import walkers
12
 
12
 
13
 def main(cont):
13
 def main(cont):
14
-    #camFSM.main(cont)
15
     own = cont.owner
14
     own = cont.owner
16
     dict = bge.logic.globalDict
15
     dict = bge.logic.globalDict
17
     camempty = scene.objects['camEmpty.001']
16
     camempty = scene.objects['camEmpty.001']
87
             dict['cam_state'] = 'driving'
86
             dict['cam_state'] = 'driving'
88
         else:
87
         else:
89
             dict['cam_state'] = 'RollCam'   
88
             dict['cam_state'] = 'RollCam'   
90
-        #print(dict['cam_state'])             
91
-
92
 
89
 
93
     if controlcube['driving'] == False:
90
     if controlcube['driving'] == False:
94
         LAST_GRIND = False
91
         LAST_GRIND = False
101
             camempty['hitdown'] = False
98
             camempty['hitdown'] = False
102
             if cam_height > (cam_def_height + .08) and zdist > -.2 and raised == 0:
99
             if cam_height > (cam_def_height + .08) and zdist > -.2 and raised == 0:
103
                 cam.height = cam_height - .02
100
                 cam.height = cam_height - .02
104
-                #print('raising a')
101
+
105
         if cam_height < -.6 and cam_moved == 0 and LAST_GRIND == False and zdist > -.2 and raised == 0 and walk == 0:
102
         if cam_height < -.6 and cam_moved == 0 and LAST_GRIND == False and zdist > -.2 and raised == 0 and walk == 0:
106
             cam_height = .1
103
             cam_height = .1
107
-            #print('raising b')
108
         if LAST_GRIND == True and walk == 0:
104
         if LAST_GRIND == True and walk == 0:
109
             if cam.height < -.5 or zdist < -.2:
105
             if cam.height < -.5 or zdist < -.2:
110
                 cam.height = cam.height + .013
106
                 cam.height = cam.height + .013
111
-                #print('raising c')
112
             if cam.height >= -.5 and not down.triggered:
107
             if cam.height >= -.5 and not down.triggered:
113
                 pass
108
                 pass
114
 
109
 
115
         controlcube['lastCamheight'] = cam.height
110
         controlcube['lastCamheight'] = cam.height
116
-        #activating######
117
         cont.activate(own.actuators['Camera'])
111
         cont.activate(own.actuators['Camera'])
118
-        #################
112
+
119
         if near.triggered == True and walk == 0:
113
         if near.triggered == True and walk == 0:
120
-            #print("near")
121
             if cam.min < 1:
114
             if cam.min < 1:
122
                 cam.min = cam.min + .1
115
                 cam.min = cam.min + .1
123
                 cam.max = cam.max + .1
116
                 cam.max = cam.max + .1
124
             cam.height = cam_height + .01
117
             cam.height = cam_height + .01
125
-            print('moving cam up')
126
             cam.damping = .001
118
             cam.damping = .001
127
             cont.activate(move)
119
             cont.activate(move)
128
 
120
 
129
         else:
121
         else:
130
-            #print("far")
131
             cont.deactivate(move)
122
             cont.deactivate(move)
132
             if cam.min > cam_def_min:
123
             if cam.min > cam_def_min:
133
                 cam.min = cam.min - .05
124
                 cam.min = cam.min - .05
156
         hitobj = str(hitobj)
147
         hitobj = str(hitobj)
157
         
148
         
158
         if hit[0]:
149
         if hit[0]:
159
-            #if hitobj != control and walk == 0 and 'vert' not in hit[0] and 'ground' in hit[0] and controlcube['ragdoll_active'] == False:
160
             if hitobj != control and walk == 0 and 'vert' not in hit[0] and 'ground' in hit[0]:
150
             if hitobj != control and walk == 0 and 'vert' not in hit[0] and 'ground' in hit[0]:
161
                 cam.damping = .01
151
                 cam.damping = .01
162
                 if cam.height < 2:
152
                 if cam.height < 2:
163
                     cam.height = cam_height + .1
153
                     cam.height = cam_height + .1
164
                     cam.max = cam.max - .2
154
                     cam.max = cam.max - .2
165
-                    #print('small move', cam.height, dict['cam_height'])
166
                 elif cam.height >= 2 and cam.height < 4:
155
                 elif cam.height >= 2 and cam.height < 4:
167
                     cam.height = cam_height + .05
156
                     cam.height = cam_height + .05
168
                     cam.max = cam.max - .05
157
                     cam.max = cam.max - .05
169
-                    #print('big move')
170
 
158
 
171
     if dict['menu_idle_timer'] > 300:
159
     if dict['menu_idle_timer'] > 300:
172
         move_len = 2048
160
         move_len = 2048
285
             if dict['cur_ccH_targetHeight'] < dict['cch_targetHeight'] + .001:
273
             if dict['cur_ccH_targetHeight'] < dict['cch_targetHeight'] + .001:
286
                 dict['cur_ccH_targetHeight'] = dict['cch_targetHeight']
274
                 dict['cur_ccH_targetHeight'] = dict['cch_targetHeight']
287
 
275
 
288
-
289
     ccH_targetHeight = dict['cur_ccH_targetHeight']
276
     ccH_targetHeight = dict['cur_ccH_targetHeight']
290
-
291
     ccH = camCube.worldPosition.z
277
     ccH = camCube.worldPosition.z
292
     pH = camCube.parent.worldPosition.z
278
     pH = camCube.parent.worldPosition.z
293
     ccheight = (round((ccH - pH), 2) - .4)
279
     ccheight = (round((ccH - pH), 2) - .4)
294
-
295
     localPos = camCube.localPosition.z
280
     localPos = camCube.localPosition.z
281
+
296
     if localPos != ccH_targetHeight:
282
     if localPos != ccH_targetHeight:
297
         num = ccH_targetHeight - localPos
283
         num = ccH_targetHeight - localPos
298
         camCube.localPosition.z += num
284
         camCube.localPosition.z += num
299
-    #if camHeightSet not in own:
300
-    #if 1 == 1:
301
     num = ccH_targetHeight - ccheight
285
     num = ccH_targetHeight - ccheight
302
-    #else:
303
-        #own['camHeightSet'] = True
286
+
304
     try:
287
     try:
305
         if dict['npause'] == False and controlcube['ragdoll_active'] == False:
288
         if dict['npause'] == False and controlcube['ragdoll_active'] == False:
306
             cont.activate(own.actuators['Camera'])
289
             cont.activate(own.actuators['Camera'])
307
             controlcube['camera'] = 0
290
             controlcube['camera'] = 0
308
         if controlcube['ragdoll_active'] == True:
291
         if controlcube['ragdoll_active'] == True:
309
-            #print('ragdoll_camera', own.actuators['Camera'].object)
310
             own.actuators['Camera'].object = scene.objects['ragdoll_parent']
292
             own.actuators['Camera'].object = scene.objects['ragdoll_parent']
311
             cont.activate(own.actuators['Camera'])
293
             cont.activate(own.actuators['Camera'])
312
             controlcube['camera'] = 0
294
             controlcube['camera'] = 0
366
             cam.max = new_max
348
             cam.max = new_max
367
         except:
349
         except:
368
             pass
350
             pass
369
-    #print(own.actuators['Camera'].object)        
351
+
370
     set_lens_dist()        
352
     set_lens_dist()        
371
     get_cam_state()
353
     get_cam_state()
372
     camFSM.main(cont)
354
     camFSM.main(cont)
373
     birds.main(cont, scene)
355
     birds.main(cont, scene)
374
     sound_man.main(cont)
356
     sound_man.main(cont)
375
     
357
     
376
-    #own['NpcPedFSM'].Execute()
377
     if own['life'] % 2 == 1:
358
     if own['life'] % 2 == 1:
378
         cars.Execute(cont)
359
         cars.Execute(cont)
379
         own['CamFSM'].Execute()
360
         own['CamFSM'].Execute()
380
-        #print('doing')
381
         walkers.Execute(cont)
361
         walkers.Execute(cont)
382
 
362
 
383
     else:
363
     else:

+ 4
- 74
scripts/cars.py View File

14
 			x['in_use'] = False
14
 			x['in_use'] = False
15
 			print('this is a parking spot')
15
 			print('this is a parking spot')
16
 			output = True
16
 			output = True
17
-	
18
 	return output
17
 	return output
19
 			
18
 			
20
 
19
 
41
 	car.applyMovement([0, -6, 0], True)
40
 	car.applyMovement([0, -6, 0], True)
42
 	car.suspendDynamics()
41
 	car.suspendDynamics()
43
 	car.suspendPhysics()	
42
 	car.suspendPhysics()	
44
-
45
 	car.name = 'lcar' + str(len(self.manager.cars))
43
 	car.name = 'lcar' + str(len(self.manager.cars))
46
 	color = random.choice(car_colors)
44
 	color = random.choice(car_colors)
47
 	car.color = color
45
 	car.color = color
49
 		y.color = color
47
 		y.color = color
50
 	print('setting car color to ', car.color)
48
 	print('setting car color to ', car.color)
51
 	x.status = 'in_use'
49
 	x.status = 'in_use'
52
-
53
-
54
 	return car
50
 	return car
55
 
51
 
56
 #====================================  
52
 #====================================  
76
 		self.path = None
72
 		self.path = None
77
 		self.path_index = 0
73
 		self.path_index = 0
78
 		self.path_display = []
74
 		self.path_display = []
79
-		#self.messages = observer.Subscriber(self)
80
 		self.manager.pub.register("path found", self)
75
 		self.manager.pub.register("path found", self)
81
 
76
 
82
 	def Execute(self):
77
 	def Execute(self):
84
 		self.life += 1
79
 		self.life += 1
85
 
80
 
86
 	def ReceiveMessage(self, message):
81
 	def ReceiveMessage(self, message):
87
-		#print('{} got message "{}"'.format(self, message))	
88
 		if self == message[1]:
82
 		if self == message[1]:
89
-			#print('unregistering observer')
90
-			#print(message[2])
91
 			self.path = message[2]
83
 			self.path = message[2]
92
 			self.FSM.FSM.ToTransition('toExitParallelPark')
84
 			self.FSM.FSM.ToTransition('toExitParallelPark')
93
-			
94
-			#self.manager.pub.unregister("path found", self)
95
-		#self.manager.pub.unregister("path found", self)	
96
-
85
+		
97
 class CarManager:
86
 class CarManager:
98
 	def __init__(self, own):
87
 	def __init__(self, own):
99
 		self.parent = own
88
 		self.parent = own
107
 		self.target_loc = None
96
 		self.target_loc = None
108
 		self.parking_spots = get_parking_spots()
97
 		self.parking_spots = get_parking_spots()
109
 		self.intersections = get_intersections()
98
 		self.intersections = get_intersections()
110
-		#self.active = car_run_check(self)
111
 		self.active = True
99
 		self.active = True
112
 		self.cars_active = []
100
 		self.cars_active = []
113
 		self.cars_loaded = False
101
 		self.cars_loaded = False
114
-		#self.max_active = 5
115
 		self.life = 0
102
 		self.life = 0
116
 		self.default_speed = 8.0#5.0
103
 		self.default_speed = 8.0#5.0
117
 		self.lane_position = 2.5#1.75
104
 		self.lane_position = 2.5#1.75
118
 		
105
 		
119
-		    
120
-
121
-
122
 	def load_cars(self):
106
 	def load_cars(self):
123
 		iter_ = 0
107
 		iter_ = 0
124
-		#look for car in scene
125
 		if 'car_collider' in bge.logic.getCurrentScene().objectsInactive:
108
 		if 'car_collider' in bge.logic.getCurrentScene().objectsInactive:
126
-
127
 			start_choices = self.parking_spots.copy()
109
 			start_choices = self.parking_spots.copy()
128
 			while len(self.cars) < self.max_cars:
110
 			while len(self.cars) < self.max_cars:
129
-				#get starting position
130
 				start_choice = random.choice(start_choices)
111
 				start_choice = random.choice(start_choices)
131
 				start_choices.remove(start_choice)
112
 				start_choices.remove(start_choice)
132
-
133
-				#add_car(self, start_choice.worldPosition)
134
 				car_ = Car(self, start_choice)
113
 				car_ = Car(self, start_choice)
135
-				self.cars.append(car_)
136
-
137
-			for x in self.parking_spots:
138
-			
139
-				
140
-				# print('put car here', x.worldPosition)
141
-				# car = bge.logic.getCurrentScene().addObject('car_collider', x, 0)
142
-				# car.worldOrientation = x.worldOrientation
143
-				# car.worldPosition.z += 1
144
-				# car.suspendDynamics()
145
-				# car.suspendPhysics()
146
-
147
-				# car['FSM'] = FSM.CarFSM(car)
148
-				# car['manager'] = self
149
-				# self.cars.append(car)
150
-				# car.name = 'lcar' + str(iter_)
151
-				# color = random.choice(car_colors)
152
-				# car.color = color
153
-				# for x in car.children:
154
-				# 	x.color = color
155
-				# print('setting car color to ', car.color)
156
-				iter_ += 1
157
-
158
-			# for x in bge.logic.getCurrentScene().objects:
159
-			# 	if 'carNavmesh' in x:
160
-			# 		self.navmesh = x
161
-				# if 'car_target' in x:
162
-				# 	self.targets.append(x)	
163
-				# 	print('adding target', x)
164
-				# if 'target_loc' in x:
165
-				# 	self.target_loc = x		
166
-
114
+				self.cars.append(car_)	
167
 			self.cars_loaded = True	
115
 			self.cars_loaded = True	
168
 
116
 
169
 		else:
117
 		else:
170
 			mainDir = bge.logic.expandPath("//")
118
 			mainDir = bge.logic.expandPath("//")
171
 			car = 'car1'
119
 			car = 'car1'
172
 			fileName = mainDir + "assets/" + str(car) + '.blend'    
120
 			fileName = mainDir + "assets/" + str(car) + '.blend'    
173
-			
174
 			path = bge.logic.expandPath(fileName)
121
 			path = bge.logic.expandPath(fileName)
175
 			print('loading car')
122
 			print('loading car')
176
 			try:
123
 			try:
188
 			self.cars_active.append(car)
135
 			self.cars_active.append(car)
189
 			car.active = True
136
 			car.active = True
190
 			car.FSM.FSM.ToTransition('toRequestPath')
137
 			car.FSM.FSM.ToTransition('toRequestPath')
191
-			#state
192
 			print('activate car', car)
138
 			print('activate car', car)
193
 
139
 
194
 	def update(self):
140
 	def update(self):
195
-		#print('car_manager_updating')
196
 		self.life += 1
141
 		self.life += 1
197
 		if self.cars_loaded:
142
 		if self.cars_loaded:
198
-			#check i f new car should be active
199
 			if self.life % 120 == 0:
143
 			if self.life % 120 == 0:
200
-
201
 				self.activator_check()
144
 				self.activator_check()
202
 
145
 
203
 			for car in self.cars_active:
146
 			for car in self.cars_active:
204
 				car.Execute()
147
 				car.Execute()
205
-				#print(car, 'is an acitve car')
206
-			self.navmesh2.update()
207
-			#print('updating navmesh from cars')	
208
-			
148
+			self.navmesh2.update()			
209
 
149
 
210
 		else:
150
 		else:
211
 			self.load_cars()
151
 			self.load_cars()
212
-			print('------------calling load cars')
213
-
214
-		# if self.life == 400:
215
-		# 	self.pub.dispatch('path found', 'found path for object')
216
-		# l = []
217
-		# for c in self.parking_spots:		
218
-		# 	if c.status == 'available':
219
-		# 		l.append(1)
220
-		# 	else:
221
-		# 		l.append(0)
222
-		#print(l, 'available spots')
152
+			
223
 def Execute(cont):
153
 def Execute(cont):
224
 	own = cont.owner
154
 	own = cont.owner
225
 	if 'car_manager' not in own:
155
 	if 'car_manager' not in own:

+ 0
- 41
scripts/walkers.py View File

12
 		if 'walker_idle_empty' in x.name:
12
 		if 'walker_idle_empty' in x.name:
13
 			self.idle_spots.append(x)
13
 			self.idle_spots.append(x)
14
 			x['in_use'] = False
14
 			x['in_use'] = False
15
-			#print('this is a parking spot')
16
 			output = True
15
 			output = True
17
-	
18
 	return output
16
 	return output
19
 			
17
 			
20
 
18
 
34
 	return op		
32
 	return op		
35
 
33
 
36
 def add_walker(self, x):
34
 def add_walker(self, x):
37
-	#print('put car here', x.obj.worldPosition)
38
 	walker = bge.logic.getCurrentScene().addObject('larryCube', x.obj, 0)
35
 	walker = bge.logic.getCurrentScene().addObject('larryCube', x.obj, 0)
39
 	walker.worldOrientation = x.obj.worldOrientation
36
 	walker.worldOrientation = x.obj.worldOrientation
40
 	walker.worldPosition.z += .8
37
 	walker.worldPosition.z += .8
41
-	#car.applyMovement([0, -6, 0], True)
42
-	#car.suspendDynamics()
43
-	#car.suspendPhysics()	
44
-
45
 	walker.name = 'lwalker' + str(len(self.manager.walkers))
38
 	walker.name = 'lwalker' + str(len(self.manager.walkers))
46
-	#color = random.choice(car_colors)
47
-	#walker.color = color
48
-	#for y in car.children:
49
-		#y.color = color
50
-	#print('setting car color to ', car.color)
51
 	x.status = 'in_use'
39
 	x.status = 'in_use'
52
 
40
 
53
-
54
 	return walker
41
 	return walker
55
 
42
 
56
 #====================================  
43
 #====================================  
76
 		self.path = None
63
 		self.path = None
77
 		self.path_index = 0
64
 		self.path_index = 0
78
 		self.path_display = []
65
 		self.path_display = []
79
-		#self.messages = observer.Subscriber(self)
80
 		self.manager.pub.register("path found", self)
66
 		self.manager.pub.register("path found", self)
81
 
67
 
82
 	def Execute(self):
68
 	def Execute(self):
84
 		self.life += 1
70
 		self.life += 1
85
 
71
 
86
 	def ReceiveMessage(self, message):
72
 	def ReceiveMessage(self, message):
87
-		#print('{} got message "{}"'.format(self, message))	
88
 		if self == message[1]:
73
 		if self == message[1]:
89
-			#print('unregistering observer')
90
-			#print(message[2])
91
 			self.path = message[2]
74
 			self.path = message[2]
92
 			self.FSM.FSM.ToTransition('toExitParallelPark')
75
 			self.FSM.FSM.ToTransition('toExitParallelPark')
93
-			
94
-			#self.manager.pub.unregister("path found", self)
95
-		#self.manager.pub.unregister("path found", self)	
96
 
76
 
97
 class WalkerManager:
77
 class WalkerManager:
98
 	def __init__(self, own):
78
 	def __init__(self, own):
106
 		self.targets = []
86
 		self.targets = []
107
 		self.target_loc = None
87
 		self.target_loc = None
108
 		self.idle_spots = get_idle_spots()
88
 		self.idle_spots = get_idle_spots()
109
-		#self.intersections = get_intersections()
110
-		#self.active = car_run_check(self)
111
 		self.active = True
89
 		self.active = True
112
 		self.walkers_active = []
90
 		self.walkers_active = []
113
 		self.walkers_loaded = False
91
 		self.walkers_loaded = False
114
-		#self.max_active = 5
115
 		self.life = 0
92
 		self.life = 0
116
 		self.default_speed = 1.0#5.0
93
 		self.default_speed = 1.0#5.0
117
 		self.lane_position = 0.5#1.75
94
 		self.lane_position = 0.5#1.75
118
-		
119
-		    
120
-
121
 
95
 
122
 	def load_walkers(self):
96
 	def load_walkers(self):
123
 		iter_ = 0
97
 		iter_ = 0
124
-		#look for car in scene
125
 		if 'larryCube' in bge.logic.getCurrentScene().objectsInactive:
98
 		if 'larryCube' in bge.logic.getCurrentScene().objectsInactive:
126
-
127
 			start_choices = self.idle_spots.copy()
99
 			start_choices = self.idle_spots.copy()
128
 			while len(self.walkers) < self.max_walkers:
100
 			while len(self.walkers) < self.max_walkers:
129
 				#get starting position
101
 				#get starting position
130
 				start_choice = random.choice(start_choices)
102
 				start_choice = random.choice(start_choices)
131
 				start_choices.remove(start_choice)
103
 				start_choices.remove(start_choice)
132
 
104
 
133
-				#add_car(self, start_choice.worldPosition)
134
 				walker_ = Walker(self, start_choice)
105
 				walker_ = Walker(self, start_choice)
135
 				self.walkers.append(walker_)
106
 				self.walkers.append(walker_)
136
 
107
 
143
 			mainDir = bge.logic.expandPath("//npc_walkers/")
114
 			mainDir = bge.logic.expandPath("//npc_walkers/")
144
 			npc = 'larry'
115
 			npc = 'larry'
145
 			fileName = mainDir + str(npc) + '.blend'    
116
 			fileName = mainDir + str(npc) + '.blend'    
146
-			
147
 			path = bge.logic.expandPath(fileName)
117
 			path = bge.logic.expandPath(fileName)
148
 			print('loading npc')
118
 			print('loading npc')
149
 			try:
119
 			try:
150
-				#bge.logic.LibLoad(path, 'Scene') 
151
 				bge.logic.LibLoad(fileName, 'Scene') 
120
 				bge.logic.LibLoad(fileName, 'Scene') 
152
 				print('larry loaded')
121
 				print('larry loaded')
153
 			except Exception as e:
122
 			except Exception as e:
163
 			self.walkers_active.append(walker)
132
 			self.walkers_active.append(walker)
164
 			walker.active = True
133
 			walker.active = True
165
 			walker.FSM.FSM.ToTransition('toRequestPath')
134
 			walker.FSM.FSM.ToTransition('toRequestPath')
166
-			#state
167
-			print('activate walker', walker)
168
 
135
 
169
 	def update(self):
136
 	def update(self):
170
-		#print('car_manager_updating')
171
 		self.life += 1
137
 		self.life += 1
172
 		if self.walkers_loaded:
138
 		if self.walkers_loaded:
173
-			#check i f new car should be active
174
 			if self.life % 180 == 0:
139
 			if self.life % 180 == 0:
175
-
176
 				self.activator_check()
140
 				self.activator_check()
177
 
141
 
178
 			for walker in self.walkers_active:
142
 			for walker in self.walkers_active:
179
 				walker.Execute()
143
 				walker.Execute()
180
-				#print(car, 'is an acitve car')
181
 			self.navmesh2.update()
144
 			self.navmesh2.update()
182
-			#print('updating navmesh from cars')	
183
-			
184
 
145
 
185
 		else:
146
 		else:
186
 			self.load_walkers()
147
 			self.load_walkers()
187
-			print('------------calling walkers')
188
 
148
 
189
 def Execute(cont):
149
 def Execute(cont):
190
 	own = cont.owner
150
 	own = cont.owner
191
 	if 'walker_manager' not in own:
151
 	if 'walker_manager' not in own:
192
 		own['walker_manager'] = WalkerManager(own)
152
 		own['walker_manager'] = WalkerManager(own)
193
 	walker_man = own['walker_manager']	
153
 	walker_man = own['walker_manager']	
194
-	#print('running walkers')
195
 	if walker_man.active:
154
 	if walker_man.active:
196
 
155
 
197
 		walker_man.update()
156
 		walker_man.update()

Loading…
Cancel
Save