shuvit 11 months 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,21 +61,13 @@ def find_new_parking(self):
61 61
     for x in potentials:
62 62
         min_dist = 45
63 63
         dist = self.obj.getDistanceTo(x.obj)
64
-        #print('dist to potential', dist)
65 64
         if dist < min_dist:
66 65
             potentials.remove(x)
67
-            #print('----removing potential')
68 66
     if len(potentials) > 0:
69
-
70 67
         new_parking = random.choice(potentials)
71
-        #path = self.manager.navmesh.findPath(self.start_empty.obj.worldPosition, new_parking.obj.worldPosition)
72 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 69
         return new_parking, path2
77 70
     else:
78
-        #print('cant find parking for', self)
79 71
         self.FSM.FSM.ToTransition('toEnterParallelPark')
80 72
 
81 73
 def get_lane_point(self):
@@ -88,10 +80,8 @@ def get_lane_point(self):
88 80
         self.lane_point = self.point + self.manager.lane_position * nv
89 81
     else:
90 82
         pass
91
-        #print('skipping lane point')
92 83
 
93 84
 def update_point(self):
94
-    #print(self.path_index, 'path index', len(self.path))
95 85
     if self.path_index >= (len(self.path) ):
96 86
         self.FSM.FSM.ToTransition('toEnterParallelPark')
97 87
     else:
@@ -105,7 +95,6 @@ def update_point(self):
105 95
                 self.path_index += 1
106 96
          
107 97
 def align_to_point(self):
108
-    #print('lane_point', self.lane_point)
109 98
     v = self.obj.getVectTo(self.lane_point)[1]
110 99
     v.z = 0
111 100
     self.obj.alignAxisToVect(v, 0, .1)
@@ -175,13 +164,10 @@ class ExitParallelPark(State):
175 164
         self.FSM.owner.obj.restorePhysics()
176 165
         self.FSM.owner.obj.restoreDynamics()
177 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 167
         self.FSM.owner.path_index = 0
180 168
         self.FSM.owner.point = self.FSM.owner.path[self.FSM.owner.path_index]
181 169
         self.FSM.owner.target.status = 'targetted'
182 170
         self.FSM.owner.start_empty.status = 'available'
183
-        #mark_path(self.FSM.owner.path, self.FSM.owner)
184
-        print('physics resumed')
185 171
         super(ExitParallelPark, self).Enter()        
186 172
         
187 173
     def Execute(self):
@@ -203,7 +189,6 @@ class EnterParallelPark(State):
203 189
         
204 190
     def Enter(self):
205 191
         self.FSM.stateLife = 1
206
-        #print('entering parallel park')
207 192
         self.FSM.owner.obj.worldPosition = self.FSM.owner.target.obj.worldPosition.copy()
208 193
         self.FSM.owner.obj.worldOrientation = self.FSM.owner.target.obj.worldOrientation.copy()
209 194
         self.FSM.owner.obj.applyMovement([0, -6, 0], True)
@@ -217,12 +202,7 @@ class EnterParallelPark(State):
217 202
         self.FSM.owner.point = self.FSM.owner.target.obj.worldPosition.copy()
218 203
         self.FSM.owner.path_index = 0
219 204
         self.FSM.owner.path = None
220
-        #print('clearning last path')
221
-        
222 205
         clear_markers(self)
223
-        
224
-        #self.FSM.owner.obj.suspendDynamics()
225
-        #self.FSM.owner.obj.suspendPhysics()
226 206
         super(EnterParallelPark, self).Enter()        
227 207
         
228 208
     def Execute(self):
@@ -277,94 +257,6 @@ class Activate(State):
277 257
 
278 258
     def drive_to_point(self):
279 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 261
     def Execute(self):
370 262
         self.FSM.stateLife += 1
@@ -380,16 +272,12 @@ class RequestPath(State):
380 272
         
381 273
     def Enter(self):
382 274
         self.FSM.stateLife = 1
383
-
384 275
         self.FSM.owner.target, self.FSM.owner.path = find_new_parking(self.FSM.owner)
385 276
         self.FSM.owner.path_index = 0
386 277
         super(RequestPath, self).Enter()        
387 278
         
388 279
     def Execute(self):
389 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 282
     def Exit(self):
395 283
         pass

+ 4
- 116
scripts/StatesWalker.py View File

@@ -25,6 +25,7 @@ def clear_markers(self):
25 25
             x.endObject()
26 26
         except:
27 27
             pass
28
+            
28 29
 def get_ground_ray(self):
29 30
     Axis = 2
30 31
     Distance = -10
@@ -61,21 +62,14 @@ def find_new_parking(self):
61 62
     for x in potentials:
62 63
         min_dist = 45
63 64
         dist = self.obj.getDistanceTo(x.obj)
64
-        #print('dist to potential', dist)
65 65
         if dist < min_dist:
66 66
             potentials.remove(x)
67
-            #print('----removing potential')
68
-    if len(potentials) > 0:
69 67
 
68
+    if len(potentials) > 0:
70 69
         new_parking = random.choice(potentials)
71
-        #path = self.manager.navmesh.findPath(self.start_empty.obj.worldPosition, new_parking.obj.worldPosition)
72 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 71
         return new_parking, path2
77 72
     else:
78
-        #print('cant find parking for', self)
79 73
         self.FSM.FSM.ToTransition('toEnterParallelPark')
80 74
 
81 75
 def get_lane_point(self):
@@ -88,10 +82,8 @@ def get_lane_point(self):
88 82
         self.lane_point = self.point + self.manager.lane_position * nv
89 83
     else:
90 84
         pass
91
-        #print('skipping lane point')
92 85
 
93 86
 def update_point(self):
94
-    #print(self.path_index, 'path index', len(self.path))
95 87
     if self.path_index >= (len(self.path) ):
96 88
         self.FSM.FSM.ToTransition('toEnterParallelPark')
97 89
     else:
@@ -105,7 +97,6 @@ def update_point(self):
105 97
                 self.path_index += 1
106 98
          
107 99
 def align_to_point(self):
108
-    #print('lane_point', self.lane_point)
109 100
     v = self.obj.getVectTo(self.lane_point)[1]
110 101
     v.z = 0
111 102
     self.obj.alignAxisToVect(v, 0, .1)
@@ -125,7 +116,6 @@ def delta_to_vect(self):
125 116
         f *= -1
126 117
     self.obj.applyForce([0, f, 0], True)
127 118
             
128
-              
129 119
 def apply_gas(self):
130 120
     if self.obj.linearVelocity.x < self.speed_targ:
131 121
         self.obj.applyForce([self.speed_inc, 0, 0], True)
@@ -175,12 +165,10 @@ class ExitParallelPark(State):
175 165
         self.FSM.owner.obj.restorePhysics()
176 166
         self.FSM.owner.obj.restoreDynamics()
177 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 168
         self.FSM.owner.path_index = 0
180 169
         self.FSM.owner.point = self.FSM.owner.path[self.FSM.owner.path_index]
181 170
         self.FSM.owner.target.status = 'targetted'
182 171
         self.FSM.owner.start_empty.status = 'available'
183
-        #mark_path(self.FSM.owner.path, self.FSM.owner)
184 172
         print('physics resumed')
185 173
         super(ExitParallelPark, self).Enter()        
186 174
         
@@ -203,7 +191,6 @@ class EnterParallelPark(State):
203 191
         
204 192
     def Enter(self):
205 193
         self.FSM.stateLife = 1
206
-        #print('entering parallel park')
207 194
         self.FSM.owner.obj.worldPosition = self.FSM.owner.target.obj.worldPosition.copy()
208 195
         self.FSM.owner.obj.worldOrientation = self.FSM.owner.target.obj.worldOrientation.copy()
209 196
         self.FSM.owner.obj.applyMovement([0, 0, 0], True)
@@ -217,12 +204,6 @@ class EnterParallelPark(State):
217 204
         self.FSM.owner.point = self.FSM.owner.target.obj.worldPosition.copy()
218 205
         self.FSM.owner.path_index = 0
219 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 207
         super(EnterParallelPark, self).Enter()        
227 208
         
228 209
     def Execute(self):
@@ -255,7 +236,6 @@ class NavigateToTarget(State):
255 236
         delta_to_vect(self.FSM.owner)
256 237
         apply_gas(self.FSM.owner)
257 238
 
258
-        #emergency exit
259 239
         if self.FSM.stateLife > 30 * 180 * 3:
260 240
             self.FSM.ToTransition('toEnterParallelPark')
261 241
 
@@ -277,95 +257,7 @@ class Activate(State):
277 257
 
278 258
     def drive_to_point(self):
279 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 261
     def Execute(self):
370 262
         self.FSM.stateLife += 1
371 263
 
@@ -387,9 +279,5 @@ class RequestPath(State):
387 279
         
388 280
     def Execute(self):
389 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 283
     def Exit(self):
395
-        pass

+ 2
- 78
scripts/astar.py View File

@@ -9,37 +9,8 @@ def chrono(function):
9 9
         return value
10 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 12
 def draw_all(self):
41 13
     for x in self.points:
42
-
43 14
         pm = bge.logic.getCurrentScene().addObject('path_marker')
44 15
         pm.worldPosition = x.loc
45 16
         pm.color = [1,1,0,1]
@@ -50,7 +21,6 @@ class IterRegistry(type):
50 21
         return iter(cls._registry)
51 22
 
52 23
 def load_points(points_file):        
53
-    #mainDir = bge.logic.expandPath("//")
54 24
     mainDir = bge.logic.expandPath("//assets/")
55 25
     fileName = mainDir + points_file    
56 26
     with open(fileName, 'r') as filehandle:        
@@ -70,8 +40,6 @@ def get_distance(start, end):
70 40
     length = (end - start).magnitude
71 41
     return length
72 42
 
73
-
74
-
75 43
 class Point(object):
76 44
     __metaclass__ = IterRegistry
77 45
     _registry = []
@@ -131,18 +99,14 @@ class Astar:
131 99
         self.life += 1
132 100
         if self.state == 'searching':
133 101
             self.search()
134
-            #print('life', self.life)
135 102
             if self.life > 5000:
136
-                #print('path failed')
137 103
                 self.state = 'idle'
138 104
         else:
139
-            #print('updating pathfinder queue')
140 105
             self.update_queue()        
141 106
              
142 107
     def get_results(self):
143 108
         result_locs = []
144 109
         results = []
145
-        #print('self.end', self.end, self.end.id)
146 110
         cp = self.end   
147 111
         breaker = 0
148 112
         while cp != self.start:
@@ -154,18 +118,9 @@ class Astar:
154 118
                 cp = cp.prev
155 119
             breaker += 1
156 120
             if breaker > 2000:
157
-                #print('breaking results')
158 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 122
         results.reverse()
167 123
         self.messenger.dispatch('path found', ['found path for object', self.current_searcher, results])
168
-        #draw_all(self)
169 124
 
170 125
     def smallest_f(self):
171 126
         if len(self.open) > 1:
@@ -175,38 +130,31 @@ class Astar:
175 130
                 l.append(x)
176 131
                 lfs.append(x.f)
177 132
             ind = lfs.index(min(lfs))  
178
-            #print(ind, lfs, l[ind]) 
179 133
             return l[ind]
180 134
         else:
181 135
             return self.start
182 136
             
183 137
     #@chrono    
184 138
     def search(self):
185
-        #Loop until you find the end
186 139
         tries = 0
187 140
         if self.open == []:
188
-            draw_mesh(self)
189 141
             self.state = 'inactive'
190 142
 
191 143
         while self.open != []:
192
-            #Get the current node from open list with smallest fval
193 144
             try:
194 145
                 self.open.remove(self.current)
195 146
             except:
196 147
                 pass
197
-                #print('current is not in open, cant remove')
198 148
             current_node = self.smallest_f()
199 149
             self.current = current_node
200 150
             self.searched.append(current_node)
201
-             #remove from open
202 151
             self.closed.append(current_node) #add to closed
203 152
             if current_node == self.end:
204
-                #print('path found')
205 153
                 path = self.get_results()
206
-                #print('p', path)
207 154
                 self.state = 'inactive'
208 155
                 self.open = []
209 156
                 break                
157
+
210 158
             else:
211 159
                 children = current_node.neighbors
212 160
                 for child in children:
@@ -229,10 +177,6 @@ class Astar:
229 177
                         self.closed[:] = [x for x in self.closed if x != child]    
230 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 180
             tries += 1
237 181
             if tries >= 5:
238 182
                 break                      
@@ -244,9 +188,7 @@ class Astar:
244 188
                 num = iter
245 189
             else:
246 190
                 pass
247
-                #print('cant get navmesh neighbor id')    
248 191
             iter += 1    
249
-        #print(num, 'id')
250 192
         
251 193
     def set_gscore(self):
252 194
         self.gscores = []
@@ -267,12 +209,9 @@ class Astar:
267 209
 
268 210
     def queue_path(self, start_in, end_in, obj):
269 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 213
     def update_queue(self):
274 214
         if self.queue != []:
275
-            #print('--getting next path in queue')
276 215
             self.get_path(self.queue[0][0], self.queue[0][1], self.queue[0][2])
277 216
             self.queue.remove(self.queue[0])           
278 217
                          
@@ -289,27 +228,12 @@ class Astar:
289 228
         self.open.append(self.start)
290 229
         self.set_gscore()
291 230
         self.current = self.start
292
-        #beginning search
293
-        #Initialize both open and closed list
294 231
         self.open = []
295 232
         self.closed = []
296 233
         self.searched = []
297
-
298
-        #Add the start node
299 234
         self.open.append(self.start)
300 235
         self.current = self.start
301 236
         self.current.g = 0
302 237
         self.current.f = 0
303 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,8 +1,6 @@
1 1
 import bge
2 2
 import random
3 3
 
4
-
5
-        
6 4
 def bird(cont):
7 5
     own = cont.owner
8 6
     if 'inited' not in own:
@@ -12,13 +10,10 @@ def bird(cont):
12 10
         act.target = own['end']
13 11
         act.velocity = 2
14 12
         cont.activate(act)
15
-        #print('doing bird')
16 13
     if own.getDistanceTo(own['end']) < 1:
17 14
         own.endObject()
18
-        #print('kill bird') 
19 15
 
20 16
 def main(cont, scene):
21
-
22 17
     def build_bird_list(scene,own):
23 18
         own['bird_list'] = []
24 19
         for x in scene.objects:
@@ -30,7 +25,6 @@ def main(cont, scene):
30 25
             if own['life'] % 50 == 0:
31 26
                 num = random.randint(0,2)
32 27
                 if num == 1:
33
-                    #print('add bird')
34 28
                     top = len(own['bird_list']) - 1
35 29
                     start = random.randint(0, top)
36 30
                     end = start
@@ -40,7 +34,6 @@ def main(cont, scene):
40 34
                     obj['start'] = own['bird_list'][start]
41 35
                     obj['end'] = own['bird_list'][end]
42 36
                     obj.worldPosition = obj['start'].worldPosition
43
-                    #print(obj['start'], obj['end'])
44 37
                 
45 38
     def life(own):
46 39
         if 'life' in own:
@@ -48,13 +41,10 @@ def main(cont, scene):
48 41
         else:
49 42
             own['life'] = 0    
50 43
         
51
-  
52
-
53 44
     own = cont.owner
54 45
     if 'binited' not in own:
55 46
         build_bird_list(scene, own)            
56 47
         own['binited'] = True
57 48
 
58 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,7 +11,6 @@ import cars
11 11
 import walkers
12 12
 
13 13
 def main(cont):
14
-    #camFSM.main(cont)
15 14
     own = cont.owner
16 15
     dict = bge.logic.globalDict
17 16
     camempty = scene.objects['camEmpty.001']
@@ -87,8 +86,6 @@ def main(cont):
87 86
             dict['cam_state'] = 'driving'
88 87
         else:
89 88
             dict['cam_state'] = 'RollCam'   
90
-        #print(dict['cam_state'])             
91
-
92 89
 
93 90
     if controlcube['driving'] == False:
94 91
         LAST_GRIND = False
@@ -101,33 +98,27 @@ def main(cont):
101 98
             camempty['hitdown'] = False
102 99
             if cam_height > (cam_def_height + .08) and zdist > -.2 and raised == 0:
103 100
                 cam.height = cam_height - .02
104
-                #print('raising a')
101
+
105 102
         if cam_height < -.6 and cam_moved == 0 and LAST_GRIND == False and zdist > -.2 and raised == 0 and walk == 0:
106 103
             cam_height = .1
107
-            #print('raising b')
108 104
         if LAST_GRIND == True and walk == 0:
109 105
             if cam.height < -.5 or zdist < -.2:
110 106
                 cam.height = cam.height + .013
111
-                #print('raising c')
112 107
             if cam.height >= -.5 and not down.triggered:
113 108
                 pass
114 109
 
115 110
         controlcube['lastCamheight'] = cam.height
116
-        #activating######
117 111
         cont.activate(own.actuators['Camera'])
118
-        #################
112
+
119 113
         if near.triggered == True and walk == 0:
120
-            #print("near")
121 114
             if cam.min < 1:
122 115
                 cam.min = cam.min + .1
123 116
                 cam.max = cam.max + .1
124 117
             cam.height = cam_height + .01
125
-            print('moving cam up')
126 118
             cam.damping = .001
127 119
             cont.activate(move)
128 120
 
129 121
         else:
130
-            #print("far")
131 122
             cont.deactivate(move)
132 123
             if cam.min > cam_def_min:
133 124
                 cam.min = cam.min - .05
@@ -156,17 +147,14 @@ def main(cont):
156 147
         hitobj = str(hitobj)
157 148
         
158 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 150
             if hitobj != control and walk == 0 and 'vert' not in hit[0] and 'ground' in hit[0]:
161 151
                 cam.damping = .01
162 152
                 if cam.height < 2:
163 153
                     cam.height = cam_height + .1
164 154
                     cam.max = cam.max - .2
165
-                    #print('small move', cam.height, dict['cam_height'])
166 155
                 elif cam.height >= 2 and cam.height < 4:
167 156
                     cam.height = cam_height + .05
168 157
                     cam.max = cam.max - .05
169
-                    #print('big move')
170 158
 
171 159
     if dict['menu_idle_timer'] > 300:
172 160
         move_len = 2048
@@ -285,28 +273,22 @@ def main(cont):
285 273
             if dict['cur_ccH_targetHeight'] < dict['cch_targetHeight'] + .001:
286 274
                 dict['cur_ccH_targetHeight'] = dict['cch_targetHeight']
287 275
 
288
-
289 276
     ccH_targetHeight = dict['cur_ccH_targetHeight']
290
-
291 277
     ccH = camCube.worldPosition.z
292 278
     pH = camCube.parent.worldPosition.z
293 279
     ccheight = (round((ccH - pH), 2) - .4)
294
-
295 280
     localPos = camCube.localPosition.z
281
+
296 282
     if localPos != ccH_targetHeight:
297 283
         num = ccH_targetHeight - localPos
298 284
         camCube.localPosition.z += num
299
-    #if camHeightSet not in own:
300
-    #if 1 == 1:
301 285
     num = ccH_targetHeight - ccheight
302
-    #else:
303
-        #own['camHeightSet'] = True
286
+
304 287
     try:
305 288
         if dict['npause'] == False and controlcube['ragdoll_active'] == False:
306 289
             cont.activate(own.actuators['Camera'])
307 290
             controlcube['camera'] = 0
308 291
         if controlcube['ragdoll_active'] == True:
309
-            #print('ragdoll_camera', own.actuators['Camera'].object)
310 292
             own.actuators['Camera'].object = scene.objects['ragdoll_parent']
311 293
             cont.activate(own.actuators['Camera'])
312 294
             controlcube['camera'] = 0
@@ -366,18 +348,16 @@ def main(cont):
366 348
             cam.max = new_max
367 349
         except:
368 350
             pass
369
-    #print(own.actuators['Camera'].object)        
351
+
370 352
     set_lens_dist()        
371 353
     get_cam_state()
372 354
     camFSM.main(cont)
373 355
     birds.main(cont, scene)
374 356
     sound_man.main(cont)
375 357
     
376
-    #own['NpcPedFSM'].Execute()
377 358
     if own['life'] % 2 == 1:
378 359
         cars.Execute(cont)
379 360
         own['CamFSM'].Execute()
380
-        #print('doing')
381 361
         walkers.Execute(cont)
382 362
 
383 363
     else:

+ 4
- 74
scripts/cars.py View File

@@ -14,7 +14,6 @@ def car_run_check(self):
14 14
 			x['in_use'] = False
15 15
 			print('this is a parking spot')
16 16
 			output = True
17
-	
18 17
 	return output
19 18
 			
20 19
 
@@ -41,7 +40,6 @@ def add_car(self, x):
41 40
 	car.applyMovement([0, -6, 0], True)
42 41
 	car.suspendDynamics()
43 42
 	car.suspendPhysics()	
44
-
45 43
 	car.name = 'lcar' + str(len(self.manager.cars))
46 44
 	color = random.choice(car_colors)
47 45
 	car.color = color
@@ -49,8 +47,6 @@ def add_car(self, x):
49 47
 		y.color = color
50 48
 	print('setting car color to ', car.color)
51 49
 	x.status = 'in_use'
52
-
53
-
54 50
 	return car
55 51
 
56 52
 #====================================  
@@ -76,7 +72,6 @@ class Car:
76 72
 		self.path = None
77 73
 		self.path_index = 0
78 74
 		self.path_display = []
79
-		#self.messages = observer.Subscriber(self)
80 75
 		self.manager.pub.register("path found", self)
81 76
 
82 77
 	def Execute(self):
@@ -84,16 +79,10 @@ class Car:
84 79
 		self.life += 1
85 80
 
86 81
 	def ReceiveMessage(self, message):
87
-		#print('{} got message "{}"'.format(self, message))	
88 82
 		if self == message[1]:
89
-			#print('unregistering observer')
90
-			#print(message[2])
91 83
 			self.path = message[2]
92 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 86
 class CarManager:
98 87
 	def __init__(self, own):
99 88
 		self.parent = own
@@ -107,70 +96,28 @@ class CarManager:
107 96
 		self.target_loc = None
108 97
 		self.parking_spots = get_parking_spots()
109 98
 		self.intersections = get_intersections()
110
-		#self.active = car_run_check(self)
111 99
 		self.active = True
112 100
 		self.cars_active = []
113 101
 		self.cars_loaded = False
114
-		#self.max_active = 5
115 102
 		self.life = 0
116 103
 		self.default_speed = 8.0#5.0
117 104
 		self.lane_position = 2.5#1.75
118 105
 		
119
-		    
120
-
121
-
122 106
 	def load_cars(self):
123 107
 		iter_ = 0
124
-		#look for car in scene
125 108
 		if 'car_collider' in bge.logic.getCurrentScene().objectsInactive:
126
-
127 109
 			start_choices = self.parking_spots.copy()
128 110
 			while len(self.cars) < self.max_cars:
129
-				#get starting position
130 111
 				start_choice = random.choice(start_choices)
131 112
 				start_choices.remove(start_choice)
132
-
133
-				#add_car(self, start_choice.worldPosition)
134 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 115
 			self.cars_loaded = True	
168 116
 
169 117
 		else:
170 118
 			mainDir = bge.logic.expandPath("//")
171 119
 			car = 'car1'
172 120
 			fileName = mainDir + "assets/" + str(car) + '.blend'    
173
-			
174 121
 			path = bge.logic.expandPath(fileName)
175 122
 			print('loading car')
176 123
 			try:
@@ -188,38 +135,21 @@ class CarManager:
188 135
 			self.cars_active.append(car)
189 136
 			car.active = True
190 137
 			car.FSM.FSM.ToTransition('toRequestPath')
191
-			#state
192 138
 			print('activate car', car)
193 139
 
194 140
 	def update(self):
195
-		#print('car_manager_updating')
196 141
 		self.life += 1
197 142
 		if self.cars_loaded:
198
-			#check i f new car should be active
199 143
 			if self.life % 120 == 0:
200
-
201 144
 				self.activator_check()
202 145
 
203 146
 			for car in self.cars_active:
204 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 150
 		else:
211 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 153
 def Execute(cont):
224 154
 	own = cont.owner
225 155
 	if 'car_manager' not in own:

+ 0
- 41
scripts/walkers.py View File

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

Loading…
Cancel
Save