shuvit 4 years ago
parent
commit
e15c0009bd

+ 2
- 2
assets/car1.blend View File

@@ -1,3 +1,3 @@
1 1
 version https://git-lfs.github.com/spec/v1
2
-oid sha256:8ebbd1f8f77a69ff03711a8286c0e0a8ade60e2a6dc327c9ab7457cf5dca857b
3
-size 2010100
2
+oid sha256:362449558c4995c81c9ab8593a98b97477cb436e5d2432a0be8351ed7a3f583a
3
+size 1999844

+ 2
- 2
assets/roads.blend View File

@@ -1,3 +1,3 @@
1 1
 version https://git-lfs.github.com/spec/v1
2
-oid sha256:784809674b518a6435240657168d882fc30d0dace8f4fdd643ecc4dc0189b4e4
3
-size 83642732
2
+oid sha256:7bca54bebf1841f270accc171b67350ad904324a6d4ab2f0dbb6b26988ad2531
3
+size 19632312

+ 3
- 0
assets/roads1.blend View File

@@ -0,0 +1,3 @@
1
+version https://git-lfs.github.com/spec/v1
2
+oid sha256:d9a849f17050b8d2343334386d20b8f84e93c0c8263081f918664c9867d2eab1
3
+size 83062088

+ 3
- 0
assets/roads4.blend View File

@@ -0,0 +1,3 @@
1
+version https://git-lfs.github.com/spec/v1
2
+oid sha256:ed2ab233152474e80d0e10406df1f6853b5a1c4ea5fdfeca97232ae82ea1e59b
3
+size 19659180

+ 2
- 2
assets/user2.blend View File

@@ -1,3 +1,3 @@
1 1
 version https://git-lfs.github.com/spec/v1
2
-oid sha256:55ccbcfd7471751baddd78f3c758c42b6c531ca7bae09a608628e889fcd527dd
3
-size 6498608
2
+oid sha256:646ea4d4c0554f2a357c06b54bab13bd8ab1926a692cb7d1da60b03c7fce6b28
3
+size 6393344

+ 3
- 0
assets/user2_working.blend View File

@@ -0,0 +1,3 @@
1
+version https://git-lfs.github.com/spec/v1
2
+oid sha256:d1316685d3683e430d6f5d0b4ff646caeab58d552f3b101f5c1d88d41e6c1ce1
3
+size 4902668

+ 28
- 0
scripts/FSM.py View File

@@ -2,6 +2,7 @@ import bge
2 2
 
3 3
 import StatesNpcPed
4 4
 import StatesCamera
5
+import StatesCar
5 6
    
6 7
 #====================================
7 8
 class Transition(object):
@@ -94,3 +95,30 @@ class CameraFSM(Char):
94 95
     
95 96
     def Execute(self):
96 97
         self.FSM.Execute(self.owner)    
98
+
99
+#=================================== 
100
+
101
+class CarFSM(Char):
102
+    def __init__(self, owner):
103
+        self.FSM = FSM(self, owner)
104
+        self.owner = owner
105
+
106
+        
107
+        state_list = [
108
+        'Example',
109
+        'Activate',
110
+        'ExitParallelPark',
111
+        'EnterParallelPark',
112
+        'NavigateToTarget']
113
+
114
+        
115
+        for s in state_list:
116
+            self.FSM.AddState(s, getattr(StatesCar, s)(self.FSM))
117
+            t = 'to' + s
118
+            self.FSM.AddTransition(t, Transition(s))
119
+        
120
+        if self.FSM.curState == None:
121
+            self.FSM.SetState('Example')
122
+    
123
+    def Execute(self):
124
+        self.FSM.Execute(self.owner)    

+ 432
- 0
scripts/StatesCar.py View File

@@ -0,0 +1,432 @@
1
+import utils
2
+import bge
3
+import random
4
+from mathutils import Vector
5
+
6
+#====================================     
7
+
8
+def mark_path(path, y):
9
+    iter_ = 0
10
+
11
+    for x in path:
12
+        pm = bge.logic.getCurrentScene().addObject('path_marker', y.obj, 0)
13
+        pm.worldPosition = path[iter_]    
14
+        iter_ += 1
15
+        if iter_ == 1:
16
+            pm.color = [0,1,0,.4]
17
+        if iter_ == (len(path) ):
18
+            pm.color = [1,0,0,.4]
19
+        if iter_ == (len(path) +1):
20
+            pm.color = [1,0,1,.4]    
21
+        y.path_display.append(pm)
22
+
23
+def clear_markers(self):
24
+    # for x in bge.logic.getCurrentScene().objects:
25
+    #     if 'path_marker' in x.name:
26
+    #         x.endObject()
27
+    for x in self.FSM.owner.path_display:
28
+        try:
29
+            x.endObject()
30
+        except:
31
+            pass
32
+def get_ground_ray(self):
33
+    Axis = 2
34
+    Distance = -10
35
+    end = self.obj.worldPosition + (self.obj.worldOrientation.col[Axis]*Distance)
36
+    start = self.obj.worldPosition.copy()
37
+    ground_ray = self.obj.rayCast(end, start, 6,'', 1, 0)
38
+    return ground_ray
39
+
40
+def set_height(self):
41
+    ground_ray = get_ground_ray(self)
42
+    target_height = 0.9
43
+    hitpoint = ground_ray[1]
44
+    try:
45
+        dist = self.obj.getDistanceTo(hitpoint)
46
+        if dist < target_height:
47
+            self.obj.worldPosition.z += target_height - dist
48
+            self.obj.linearVelocity.z = 0
49
+        self.obj.linearVelocity.y *= .1
50
+    except:
51
+        pass
52
+
53
+def align_to_road(self):
54
+    ground_ray = get_ground_ray(self)
55
+    try:
56
+        self.obj.alignAxisToVect(ground_ray[2], 2, .15)
57
+    except:
58
+        pass
59
+    
60
+def find_new_parking(self):
61
+    potentials = []
62
+    for x in self.manager.parking_spots:
63
+        if x.status == 'available':
64
+            potentials.append(x)
65
+    for x in potentials:
66
+        min_dist = 100
67
+        dist = self.obj.getDistanceTo(x.obj)
68
+        if dist < min_dist:
69
+            potentials.remove(x)
70
+            print('----removing potential')
71
+    if len(potentials) > 0:
72
+
73
+        new_parking = random.choice(potentials)
74
+        path = self.manager.navmesh.findPath(self.start_empty.obj.worldPosition, new_parking.obj.worldPosition)
75
+        print('parking added at', new_parking.obj.worldPosition)
76
+
77
+        mark_path(path, self)
78
+        return new_parking, path
79
+    else:
80
+        self.FSM.FSM.ToTransition('toEnterParallelPark')
81
+def get_lane_point(self):
82
+
83
+
84
+    self.point = self.path[self.path_index]
85
+    #print(self.path_index, 'path index')
86
+
87
+    v = Vector([self.last_lane_point.x - self.point.x, self.last_lane_point.y - self.point.y, 0])
88
+    tv = v.normalized()
89
+    nv = Vector([-tv.y, tv.x, 0]) #rotate 90 degrees
90
+    self.last_lane_point = self.lane_point
91
+    self.lane_point = self.point + self.manager.lane_position * nv
92
+
93
+
94
+
95
+def update_point(self):
96
+    
97
+    if self.path_index >= (len(self.path) ):
98
+        self.FSM.FSM.ToTransition('toEnterParallelPark')
99
+    else:
100
+        dist = self.obj.getDistanceTo(self.lane_point)
101
+        #print(dist, self.path_index)
102
+        self.point = self.path[self.path_index]
103
+        if dist < 2.5:
104
+            get_lane_point(self)   
105
+            if self.path_index > (len(self.path)):
106
+                pass
107
+            else:
108
+                
109
+                self.path_index += 1
110
+            
111
+
112
+         
113
+def align_to_point(self):
114
+    v = self.obj.getVectTo(self.lane_point)[1]
115
+    v.z = 0
116
+    self.obj.alignAxisToVect(v, 0, .1)
117
+
118
+def delta_to_vect(self):
119
+    v = self.obj.getVectTo(self.lane_point)[1]
120
+    #vt = Vector([self.last_lane_point.x - self.lane_point.x, self.last_lane_point.y - self.lane_point.y, 0])
121
+
122
+    delta = self.last_lane_point - self.lane_point
123
+    delta = delta.cross(v)
124
+    delta_mult = -.1
125
+    mult = 1.0
126
+    deltamove = delta[2] * delta_mult
127
+    self.obj.applyMovement([0, deltamove, 0], True)
128
+            
129
+              
130
+def apply_gas(self):
131
+    if self.obj.linearVelocity.x < self.speed_targ:
132
+        self.obj.applyForce([self.speed_inc, 0, 0], True)
133
+
134
+#====================================     
135
+
136
+State = type("State", (object,), {})
137
+#====================================     
138
+class State(object):
139
+    def __init__(self, FSM):
140
+        self.FSM = FSM
141
+        self.timer = 0
142
+        self.startTime = 0
143
+    def Enter(self):
144
+        self.timer = 0
145
+        self.startTime = 0
146
+    def Execute(self):
147
+        print('Executing')
148
+    def Exit(self):
149
+        print('Exiting')
150
+#==================================== 
151
+            
152
+class Example(State):
153
+    def __init__(self,FSM):
154
+        super(Example, self).__init__(FSM)    
155
+        
156
+    def Enter(self):
157
+        self.FSM.stateLife = 1
158
+        self.FSM.owner.resumePhysics()
159
+        self.FSM.owner.resumeDynamics()
160
+        print('physics resumed')
161
+        super(Example, self).Enter()        
162
+        
163
+    def Execute(self):
164
+        self.FSM.stateLife += 1
165
+        print('doing example')
166
+        #o = self.FSM.owner
167
+        #g = o.me['game']
168
+        #self.FSM.ToTransition('toActivate')
169
+        #print(self.FSM.owner)
170
+        #self.FSM.owner.applyRotation([0,0,.01], True)
171
+        #self.FSM.owner.worldPosition.z = 0
172
+        #self.FSM.owner.worldPosition.z += 0.1
173
+        #self.FSM.owner.worldPosition.x += 1.1
174
+        #print(self.FSM.owner.children)
175
+
176
+    def Exit(self):
177
+        pass
178
+
179
+class ExitParallelPark(State):
180
+    def __init__(self,FSM):
181
+        super(ExitParallelPark, self).__init__(FSM)    
182
+        
183
+    def Enter(self):
184
+        self.FSM.stateLife = 1
185
+        self.FSM.owner.obj.restorePhysics()
186
+        self.FSM.owner.obj.restoreDynamics()
187
+        self.FSM.owner.obj.linearVelocity = [0,0,0]
188
+        self.FSM.owner.target, self.FSM.owner.path = find_new_parking(self.FSM.owner)
189
+        self.FSM.owner.path_index = 0
190
+        self.FSM.owner.point = self.FSM.owner.path[self.FSM.owner.path_index]
191
+        self.FSM.owner.target.status = 'targetted'
192
+        self.FSM.owner.start_empty.status = 'available'
193
+        
194
+        #print('target is', self.FSM.owner.target)
195
+        print('physics resumed')
196
+        super(ExitParallelPark, self).Enter()        
197
+        
198
+    def Execute(self):
199
+        self.FSM.stateLife += 1
200
+        #print('doing ExitParallelPark')
201
+        v = self.FSM.owner.obj.getVectTo(self.FSM.owner.path[0])
202
+        #v.z = 0
203
+        self.FSM.owner.obj.alignAxisToVect(v[1], 0, .01)
204
+        self.FSM.owner.obj.alignAxisToVect([0,0,1], 2, 1)
205
+        if self.FSM.stateLife > 220:
206
+            self.FSM.ToTransition('toNavigateToTarget')
207
+        #self.FSM.owner.obj.applyForce([6, 0, 0], True)
208
+
209
+    def Exit(self):
210
+        pass        
211
+
212
+#====================================  
213
+            
214
+class EnterParallelPark(State):
215
+    def __init__(self,FSM):
216
+        
217
+        super(EnterParallelPark, self).__init__(FSM)    
218
+        
219
+    def Enter(self):
220
+        self.FSM.stateLife = 1
221
+        print('entering parallel park')
222
+        self.FSM.owner.obj.worldPosition = self.FSM.owner.target.obj.worldPosition
223
+        self.FSM.owner.obj.worldOrientation = self.FSM.owner.target.obj.worldOrientation
224
+        self.FSM.owner.obj.applyMovement([0, -6, 0], True)
225
+        self.FSM.owner.target.status = 'in_use'
226
+        self.FSM.owner.obj.worldPosition.z += .9
227
+        self.FSM.owner.obj.suspendDynamics()
228
+        self.FSM.owner.obj.suspendPhysics()
229
+        self.FSM.owner.manager.cars_active.remove(self.FSM.owner)
230
+        self.FSM.owner.active = False
231
+        self.FSM.owner.start_empty = self.FSM.owner.target
232
+        self.FSM.owner.last_point = self.FSM.owner.obj.worldPosition
233
+        self.FSM.owner.point = self.FSM.owner.obj.worldPosition
234
+        clear_markers(self)
235
+        super(EnterParallelPark, self).Enter()        
236
+        
237
+    def Execute(self):
238
+        self.FSM.stateLife += 1
239
+    
240
+        #self.FSM.ToTransition('toActivate')
241
+        
242
+
243
+    def Exit(self):
244
+        pass
245
+
246
+#==================================== 
247
+
248
+class NavigateToTarget(State):
249
+    def __init__(self,FSM):
250
+        super(NavigateToTarget, self).__init__(FSM)    
251
+        
252
+    def Enter(self):
253
+        self.FSM.stateLife = 1
254
+        
255
+        super(NavigateToTarget, self).Enter()        
256
+        
257
+    def Execute(self):
258
+        self.FSM.stateLife += 1
259
+        update_point(self.FSM.owner)
260
+
261
+        align_to_point(self.FSM.owner)
262
+        align_to_road(self.FSM.owner)
263
+        set_height(self.FSM.owner)
264
+        delta_to_vect(self.FSM.owner)
265
+        apply_gas(self.FSM.owner)
266
+        #print('target', self.FSM.owner.target.obj.worldPosition)
267
+
268
+        #emergency exit
269
+        if self.FSM.stateLife > 60 * 90:
270
+            self.FSM.ToTransition('toEnterParallelPark')
271
+
272
+        #print('doing NavigateToTarget')
273
+
274
+        #self.FSM.owner.obj.applyForce([6, 0, 0], True)
275
+
276
+    def Exit(self):
277
+        pass        
278
+
279
+#====================================  
280
+
281
+class Activate(State):
282
+    def __init__(self,FSM):
283
+        super(Activate, self).__init__(FSM)    
284
+        
285
+    def Enter(self):
286
+        self.FSM.stateLife = 1
287
+        # self.FSM.owner.restorePhysics()
288
+        # self.FSM.owner.restoreDynamics()
289
+        # self.FSM.owner.worldPosition.z = 2
290
+        # self.FSM.curTarget = None
291
+        # self.FSM.last_target = None
292
+        # #self.FSM.path = None
293
+        # self.point = None
294
+        # self.last_point = self.FSM.owner.worldPosition.copy()
295
+        # self.last_pos = self.FSM.owner.worldPosition.copy()
296
+        # self.backup = 0
297
+        # self.lane_point = None
298
+        # self.last_lane_point = self.last_pos
299
+        # self.lane_position = 1.75
300
+        # self.pos_his = []
301
+        # self.max_speed = 5.0
302
+        # self.FSM.path = None
303
+        # print('physics resumed')
304
+        super(Activate, self).Enter()        
305
+        
306
+    def find_target(self):
307
+        pass
308
+        # if self.FSM.curTarget == None:
309
+        #     choices = self.FSM.owner['manager'].targets
310
+        #     if self.FSM.last_target in choices:
311
+        #         choices.remove(self.FSM.last_target)
312
+        #     if choices:    
313
+        #         self.FSM.curTarget = random.choice(choices)
314
+        #         self.FSM.path = self.FSM.owner['manager'].navmesh.findPath(self.FSM.owner.worldPosition, self.FSM.curTarget.worldPosition)
315
+        #         self.FSM.path.remove(self.FSM.path[0])
316
+        #         self.point = self.FSM.path[0]
317
+        #         vt = Vector([self.last_point.x - self.point.x, self.last_point.y - self.point.y, 0])
318
+        #         tv = vt.normalized()
319
+        #         #rotate 90 degrees
320
+        #         nv = Vector([-tv.y, tv.x, 0])
321
+        #         distance = 3.5
322
+        #         self.lane_point = self.point + self.lane_position * nv
323
+        #     else:
324
+        #         print('no fucking choices')
325
+        #     return False
326
+        # else:
327
+        #     return True  
328
+
329
+    def drive_to_point(self):
330
+        if self.FSM.path:
331
+            ground_ray = get_ground_ray(self)
332
+            if ground_ray[0]:
333
+                set_height(self, ground_ray)
334
+                align_to_road(self, ground_ray) 
335
+
336
+            v = self.FSM.owner.getVectTo(self.lane_point)               
337
+            speed_force = 800.0
338
+            max_speed = 5.0
339
+            behind = False
340
+            local = self.FSM.owner.worldOrientation.inverted() * (self.lane_point - self.FSM.owner.worldPosition) 
341
+            v2 = v[1].copy()
342
+            v2.z = 0
343
+            delta = self.last_lane_point - self.lane_point
344
+            delta = delta.cross(v[1])
345
+            delta_mult = -.1
346
+            mult = 1.0
347
+            backup_time = 20
348
+
349
+            #change max speed
350
+            if self.FSM.stateLife % 180 == 0:
351
+                print('change speed force')
352
+                self.speed_force = random.choice([max_speed * 1.3, max_speed * 1.6, max_speed * .8, max_speed * .6, max_speed])
353
+
354
+            if local.x > 0 and self.backup == 0:
355
+
356
+                if self.FSM.owner.linearVelocity.x < self.max_speed:
357
+                    self.FSM.owner.applyForce([speed_force, 0, 0], True)
358
+
359
+                deltamove = delta[2] * delta_mult
360
+                #self.FSM.owner.applyMovement([0, deltamove, 0], True)
361
+
362
+                f = deltamove * 5000
363
+                self.FSM.owner.applyForce([0, f, 0], True)
364
+                v = self.FSM.owner.getVectTo(self.lane_point)
365
+                v2 = v[1].copy()
366
+                v2.z = 0
367
+                self.FSM.owner.alignAxisToVect(v2, 0, .05)
368
+
369
+
370
+            else:
371
+                if local.x < 0:
372
+                    self.backup = backup_time   
373
+
374
+                if self.backup > 0:
375
+                    print('backing up')
376
+                    v = self.FSM.owner.getVectTo(self.FSM.path[0])
377
+                    v2 = v[1].copy()
378
+                    v2.z = 0
379
+                    self.FSM.owner.alignAxisToVect(v2, 0, .02)
380
+                    if self.FSM.owner.linearVelocity.x > -max_speed / 2:
381
+                        self.FSM.owner.applyForce([-speed_force * .8, 0, 0], True)
382
+                    self.backup -= 1
383
+
384
+            dist = self.FSM.owner.getDistanceTo(self.lane_point)
385
+
386
+            if dist < 2.5 and (len(self.FSM.path) > 0):    
387
+                #print(self.FSM.path,'this is the path')
388
+                #print('navmesh point removed')
389
+                self.last_point = self.point
390
+                self.last_lane_point = self.lane_point
391
+                self.FSM.path.remove(self.FSM.path[0])
392
+
393
+                if len(self.FSM.path) > 0:
394
+                    self.point = self.FSM.path[0]
395
+                    v = Vector([self.last_point.x - self.point.x, self.last_point.y - self.point.y, 0])
396
+                    tv = v.normalized()
397
+                    nv = Vector([-tv.y, tv.x, 0]) #rotate 90 degrees
398
+                    self.lane_point = self.point + self.lane_position * nv
399
+
400
+                else:
401
+                    self.point = None
402
+
403
+            if self.FSM.path == []:
404
+                self.FSM.curTarget = None          
405
+
406
+            #progress
407
+            self.pos_his.append(self.FSM.owner.worldPosition.copy())
408
+            pos_his_len = len(self.pos_his)
409
+            if pos_his_len > 200:
410
+                #sum_ = abs(self.FSM.owner.worldPosition.x) + abs(self.pos_his[-1][0]) + abs(self.FSM.owner.worldPosition.y) + abs(self.pos_his[-1][1]) 
411
+                sum_ = abs(self.FSM.owner.worldPosition.x - self.pos_his[0][0]) + abs(self.FSM.owner.worldPosition.y - self.pos_his[0][1])
412
+                #print(sum_, 'sum')
413
+                if sum_ < .05:
414
+                    self.backup = backup_time
415
+                    print('progress stopped')
416
+                del self.pos_his[0]
417
+            
418
+
419
+    def Execute(self):
420
+        self.FSM.stateLife += 1
421
+
422
+        #if self.find_target():
423
+            #self.drive_to_point()
424
+
425
+        #self.FSM.owner.linearVelocity.y = 0
426
+        #self.last_pos = self.FSM.owner.worldPosition.copy()
427
+        #self.FSM.owner['manager'].target_loc.worldPosition = self.lane_point
428
+
429
+    def Exit(self):
430
+        pass
431
+
432
+#====================================  

+ 12
- 6
scripts/actionPlayer.py View File

@@ -140,13 +140,17 @@ state_a = ['reg_idle',
140 140
 'fak_frigid',
141 141
 'fak_fsonefoot',
142 142
 'fak_onefoot',
143
-'reg_back_invert']
143
+'reg_back_invert',
144
+'reg_onboard', 
145
+'reg_offboard',
146
+'fak_onboard', 
147
+'fak_offboard']
144 148
 
145 149
 state_b = ['reg_jump',
146 150
 'reg_walk_air',
147 151
 'reg_walk_air_out',
148
-'reg_onboard',
149
-'reg_offboard',
152
+#'reg_onboard',
153
+#'reg_offboard',
150 154
 'reg_brfoot',
151 155
 'reg_frfoot',
152 156
 'reg_blfoot',
@@ -165,8 +169,8 @@ state_b = ['reg_jump',
165 169
 'fak_jump',
166 170
 'fak_walk_air',
167 171
 'fak_walk_air_out',
168
-'fak_onboard',
169
-'fak_offboard',
172
+#'fak_onboard',
173
+#'fak_offboard',
170 174
 'fak_brfoot',
171 175
 'fak_frfoot',
172 176
 'fak_blfoot',
@@ -239,7 +243,7 @@ def check_exit(aState, rA, timer, ac):
239 243
 		rv = aState
240 244
 
241 245
 	if force != None and fe >= timer:
242
-		print('doing exit timer')
246
+		print('doing exit timer', force)
243 247
 		rv = force
244 248
 
245 249
 	return rv
@@ -295,6 +299,8 @@ def main(cont):
295 299
 		else:
296 300
 			actionPlayer(action)
297 301
 		newState = check_exit(aState, rA, timer, action)
302
+		if aState == 'reg_onboard':
303
+			print('onboarding..')
298 304
 
299 305
 		if aState == 'reg_back_invert':
300 306
 			print('fffffffffffffffffffffffffffffffff')		

+ 14
- 14
scripts/actionsFSMlist.py View File

@@ -33,7 +33,7 @@ class a_class:
33 33
 
34 34
 reg_walk = a_class(
35 35
 	#player armature action name, start, end frames
36
-	'reg_nwalk', 0, 35,
36
+	'reg_nwalk2', 0, 30,
37 37
 	#deck action name, start, end frames  
38 38
 	'b_reg_walk', 0, 35,
39 39
 	#layer, speed, mode (0 = play, 1 = loop), blendin
@@ -49,11 +49,11 @@ reg_walk = a_class(
49 49
 
50 50
 reg_walkFast = a_class(
51 51
 	#player armature action name, start, end frames, start, end frames
52
-	'reg_nwalk', 0, 35,
52
+	'reg_run', 0, 30,
53 53
 	#deck action name, start, end frames  
54 54
 	'b_reg_walk', 0, 35,
55 55
 	#layer, speed, mode (0 = play, 1 = loop), blendin
56
-	1, 1, 0, 0, 
56
+	1, 1, 0, 10, 
57 57
 	#intro, length
58 58
 	None, 0,
59 59
 	#exits
@@ -73,7 +73,7 @@ reg_idle = a_class(
73 73
 	#intro, length
74 74
 	None, 0,
75 75
 	#exits
76
-	['reg_walk', 'reg_idle2', 'reg_idle3', 'reg_idle4', 'reg_idle5', 'reg_idle6', 'reg_idle7', 'reg_jump', 'reg_sit', 'reg_onboard'],
76
+	['reg_walk', 'reg_walkFast', 'reg_idle2', 'reg_idle3', 'reg_idle4', 'reg_idle5', 'reg_idle6', 'reg_idle7', 'reg_jump', 'reg_sit', 'reg_onboard'],
77 77
 	#force exit, frame
78 78
 	None, 0,
79 79
 	#opposite
@@ -201,7 +201,7 @@ reg_walk_air = a_class(
201 201
 	#intro, length
202 202
 	None, 0,
203 203
 	#exits
204
-	['reg_walk_air_out', 'reg_onboard'],
204
+	['reg_walk_air_out', 'reg_onboard', 'reg_walk', 'reg_walkFast'],
205 205
 	#force exit, frame
206 206
 	None, 0,
207 207
 	#opposite
@@ -263,13 +263,13 @@ reg_onboard = a_class(
263 263
 	#'b_reg_offboard', 24, 1,
264 264
 	'b_reg_onboard', 1, 100,
265 265
 	#layer, speed, mode (0 = play, 1 = loop), blendin
266
-	1, 2, 0, 5,
266
+	4, 2, 0, 5,
267 267
 	#intro, length
268 268
 	None, 0,
269 269
 	#exits
270 270
 	['reg_roll'],
271 271
 	#force exit, frame
272
-	'reg_roll', 48,
272
+	'reg_roll', 98,
273 273
 	#opposite
274 274
 	None)
275 275
 
@@ -279,13 +279,13 @@ reg_offboard = a_class(
279 279
 	#deck action name, start, end frames  
280 280
 	'b_reg_offboard', 1, 40,
281 281
 	#layer, speed, mode (0 = play, 1 = loop), blendin
282
-	1, 1, 1, 5,
282
+	4, 1, 0, 5,
283 283
 	#intro, length
284 284
 	None, 0,
285 285
 	#exits
286 286
 	['reg_idle', 'reg_walkFast', 'reg_walk', 'reg_onboard'],
287 287
 	#force exit, frame
288
-	None, 0,
288
+	'reg_idle', 39,
289 289
 	#opposite
290 290
 	None)
291 291
 
@@ -454,11 +454,11 @@ reg_pump_right = a_class(
454 454
 
455 455
 reg_push = a_class(
456 456
 	#player armature action name, start, end frames
457
-	'reg_push', 1, 35,
457
+	'reg_push2', 1, 70,
458 458
 	#deck action name, start, end frames  
459 459
 	'b_reg', 1, 1,
460 460
 	#layer, speed, mode (0 = play, 1 = loop), blendin
461
-	1, .5, 0, 10,
461
+	1, 1, 0, 10,
462 462
 	#intro, length
463 463
 	None, 0,
464 464
 	#exits
@@ -2267,7 +2267,7 @@ fak_onboard = a_class(
2267 2267
 	#deck action name, start, end frames  
2268 2268
 	'b_fak_offboard', 10, 1,
2269 2269
 	#layer, speed, mode (0 = play, 1 = loop), blendin
2270
-	1, .5, 0, 5,
2270
+	4, .5, 0, 5,
2271 2271
 	#intro, length
2272 2272
 	None, 0,
2273 2273
 	#exits
@@ -2283,13 +2283,13 @@ fak_offboard = a_class(
2283 2283
 	#deck action name, start, end frames  
2284 2284
 	'b_fak_offboard', 1, 30,
2285 2285
 	#layer, speed, mode (0 = play, 1 = loop), blendin
2286
-	1, .5, 0, 5,
2286
+	4, .5, 0, 5,
2287 2287
 	#intro, length
2288 2288
 	None, 0,
2289 2289
 	#exits
2290 2290
 	['fak_idle', 'fak_walkFast', 'fak_walk', 'fak_onboard'],
2291 2291
 	#force exit, frame
2292
-	None, 0,
2292
+	'fak_idle', 28,
2293 2293
 	#opposite
2294 2294
 	None)
2295 2295
 

+ 10
- 2
scripts/camera.py View File

@@ -7,6 +7,7 @@ import camFSM
7 7
 import birds
8 8
 import sound_man
9 9
 import FSM
10
+import cars
10 11
 
11 12
 def main(cont):
12 13
     #camFSM.main(cont)
@@ -66,6 +67,7 @@ def main(cont):
66 67
         dict['camera'] = cam1
67 68
         own['NpcPedFSM'] = FSM.NpcPed(own)
68 69
         own['CamFSM'] = FSM.CameraFSM(own)
70
+        own['life'] = 0
69 71
     acam = scene.active_camera
70 72
 
71 73
     def get_cam_state():
@@ -369,5 +371,11 @@ def main(cont):
369 371
     camFSM.main(cont)
370 372
     birds.main(cont, scene)
371 373
     sound_man.main(cont)
372
-    own['NpcPedFSM'].Execute()
373
-    own['CamFSM'].Execute()
374
+    
375
+    #own['NpcPedFSM'].Execute()
376
+    if own['life'] % 2 == 1:
377
+        cars.Execute(cont)
378
+        own['CamFSM'].Execute()
379
+
380
+
381
+    own['life'] += 1

+ 206
- 0
scripts/cars.py View File

@@ -0,0 +1,206 @@
1
+import bge
2
+import random
3
+import FSM
4
+
5
+car_colors = [[.2,.01,.01,1], [.5,.5,.4,1], [.005,.01,.015,1], [.005, .1, 0.003, 1], [.1, .1, .1, 1]]
6
+
7
+def car_run_check(self):
8
+	output = False
9
+	for x in bge.logic.getCurrentScene().objects:
10
+		if 'car_park_empty' in x.name:
11
+			self.parking_spots.append(x)
12
+			x['in_use'] = False
13
+			print('this is a parking spot')
14
+			output = True
15
+	
16
+	return output
17
+			
18
+
19
+def get_parking_spots():
20
+	op = []
21
+	for obj in bge.logic.getCurrentScene().objects:
22
+		if 'parking' in obj:
23
+			ps = ParkingSpot(obj, 'available')
24
+			op.append(ps)
25
+	return op
26
+
27
+def get_intersections():
28
+	op = []
29
+	for obj in bge.logic.getCurrentScene().objects:
30
+		if 'intersection' in obj:
31
+			op.append(obj)
32
+	return op		
33
+
34
+def add_car(self, x):
35
+	print('put car here', x.obj.worldPosition)
36
+	car = bge.logic.getCurrentScene().addObject('car_collider', x.obj, 0)
37
+	car.worldOrientation = x.obj.worldOrientation
38
+	car.worldPosition.z += .8
39
+	car.applyMovement([0, -6, 0], True)
40
+	car.suspendDynamics()
41
+	car.suspendPhysics()	
42
+
43
+	car.name = 'lcar' + str(len(self.manager.cars))
44
+	color = random.choice(car_colors)
45
+	car.color = color
46
+	for y in car.children:
47
+		y.color = color
48
+	print('setting car color to ', car.color)
49
+	x.status = 'in_use'
50
+
51
+
52
+	return car
53
+
54
+#====================================  
55
+
56
+class ParkingSpot:
57
+	def __init__(self, obj, status):
58
+		self.obj = obj
59
+		self.status = status
60
+
61
+class Car:
62
+	def __init__(self, own, start_empty):
63
+		self.manager = own
64
+		self.life = 0
65
+		self.start_empty = start_empty
66
+		self.obj = add_car(self, self.start_empty)
67
+		self.speed_targ = self.manager.default_speed
68
+		self.speed_inc = 800
69
+		self.FSM = FSM.CarFSM(self)
70
+		self.active = False
71
+		self.target = None
72
+		self.lane_point = self.obj.worldPosition
73
+		self.last_lane_point = self.obj.worldPosition
74
+		self.path = None
75
+		self.path_index = 0
76
+		self.path_display = []
77
+
78
+	def Execute(self):
79
+		self.FSM.Execute()
80
+		self.life += 1
81
+
82
+class CarManager:
83
+	def __init__(self, own):
84
+		self.parent = own
85
+		self.navmesh =None
86
+		self.cars = []
87
+		self.max_cars = 15
88
+		self.max_active = 7
89
+		self.targets = []
90
+		self.target_loc = None
91
+		self.parking_spots = get_parking_spots()
92
+		self.intersections = get_intersections()
93
+		#self.active = car_run_check(self)
94
+		self.active = True
95
+		self.cars_active = []
96
+		self.cars_loaded = False
97
+		#self.max_active = 5
98
+		self.life = 0
99
+		self.default_speed = 5.0
100
+		self.lane_position = 2.5#1.75
101
+
102
+
103
+	def load_cars(self):
104
+		iter_ = 0
105
+		#look for car in scene
106
+		if 'car_collider' in bge.logic.getCurrentScene().objectsInactive:
107
+
108
+			start_choices = self.parking_spots.copy()
109
+			while len(self.cars) < self.max_cars:
110
+				#get starting position
111
+				start_choice = random.choice(start_choices)
112
+				start_choices.remove(start_choice)
113
+
114
+				#add_car(self, start_choice.worldPosition)
115
+				car_ = Car(self, start_choice)
116
+				self.cars.append(car_)
117
+
118
+			for x in self.parking_spots:
119
+			
120
+				
121
+				# print('put car here', x.worldPosition)
122
+				# car = bge.logic.getCurrentScene().addObject('car_collider', x, 0)
123
+				# car.worldOrientation = x.worldOrientation
124
+				# car.worldPosition.z += 1
125
+				# car.suspendDynamics()
126
+				# car.suspendPhysics()
127
+
128
+				# car['FSM'] = FSM.CarFSM(car)
129
+				# car['manager'] = self
130
+				# self.cars.append(car)
131
+				# car.name = 'lcar' + str(iter_)
132
+				# color = random.choice(car_colors)
133
+				# car.color = color
134
+				# for x in car.children:
135
+				# 	x.color = color
136
+				# print('setting car color to ', car.color)
137
+				iter_ += 1
138
+
139
+			for x in bge.logic.getCurrentScene().objects:
140
+				if 'carNavmesh' in x:
141
+					self.navmesh = x
142
+				# if 'car_target' in x:
143
+				# 	self.targets.append(x)	
144
+				# 	print('adding target', x)
145
+				# if 'target_loc' in x:
146
+				# 	self.target_loc = x		
147
+
148
+			self.cars_loaded = True	
149
+
150
+		else:
151
+			mainDir = bge.logic.expandPath("//")
152
+			car = 'car1'
153
+			fileName = mainDir + "assets/" + str(car) + '.blend'    
154
+			
155
+			path = bge.logic.expandPath(fileName)
156
+			print('loading car')
157
+			try:
158
+				bge.logic.LibLoad(path, 'Scene') 
159
+			except:
160
+				print('loading', fileName, 'failed')   
161
+
162
+	def activator_check(self):
163
+		if len(self.cars_active) < self.max_active:
164
+			l = []
165
+			for c in self.cars:
166
+				if not c.active:
167
+					l.append(c)
168
+			car = random.choice(l)
169
+			self.cars_active.append(car)
170
+			car.active = True
171
+			car.FSM.FSM.ToTransition('toExitParallelPark')
172
+			#state
173
+			print('activate car', car)
174
+
175
+	def update(self):
176
+		#print('car_manager_updating')
177
+		self.life += 1
178
+		if self.cars_loaded:
179
+			#check i f new car should be active
180
+			if self.life % 360 == 0:
181
+
182
+				self.activator_check()
183
+
184
+			for car in self.cars_active:
185
+				car.Execute()
186
+				#print(car, 'is an acitve car')
187
+			
188
+
189
+		else:
190
+			self.load_cars()
191
+			print('------------calling load cars')
192
+		# l = []
193
+		# for c in self.parking_spots:		
194
+		# 	if c.status == 'available':
195
+		# 		l.append(1)
196
+		# 	else:
197
+		# 		l.append(0)
198
+		#print(l, 'available spots')
199
+def Execute(cont):
200
+	own = cont.owner
201
+	if 'car_manager' not in own:
202
+		own['car_manager'] = CarManager(own)
203
+	car_man = own['car_manager']	
204
+	if car_man.active:
205
+
206
+		car_man.update()

+ 1
- 1
scripts/controller2.py View File

@@ -2010,7 +2010,7 @@ def main():
2010 2010
                 rotation = [0.0, 0.0, ((-rotamt * 1.6) * multer)]
2011 2011
             local = True # use world axis
2012 2012
             own.applyRotation( rotation, local)
2013
-            print('rotation = ', rotation)
2013
+            #print('rotation = ', rotation)
2014 2014
             if onGround:
2015 2015
                 #print("med turn")
2016 2016
                 if STANCE == 0:

+ 2
- 2
scripts/scene_init.py View File

@@ -133,9 +133,9 @@ def main():
133 133
         own['last_roty'] = 0.0
134 134
         
135 135
         own['walk_targ_speed'] = 2
136
-        own['walk_fast_targ_speed'] = 5
136
+        own['walk_fast_targ_speed'] = 8
137 137
         own['walk_speed'] = 0
138
-        own['walk_inc'] = .05
138
+        own['walk_inc'] = .2
139 139
         own['walk_jump_timer'] = 0
140 140
         own['no_grind_timer'] = 0
141 141
         own['last_jump_frame'] = 0

+ 2
- 1
scripts/walk.py View File

@@ -326,7 +326,8 @@ def main(cont):
326 326
            
327 327
     elif (((lup == 1 and aBut == 1) or (dict['kb_lsh'] == 2 and dict['kb_ua'] == 2)) and yBut == False and (r_ground.positive or own['stair_counter'] > 0) and xBut == 0) or (turning == True and aBut == 1):
328 328
         own.actuators["walkondirt"].volume = .2
329
-        own.actuators["walkondirt"].pitch = 1.3
329
+        #own.actuators["walkondirt"].pitch = 1.3
330
+        own.actuators["walkondirt"].pitch = 2
330 331
         cont.activate(own.actuators["walkondirt"])
331 332
         #print('fastwalk')
332 333
         if stance == 0 and skater.isPlayingAction(fliplay) == False:        

+ 12
- 12
scripts/walker_states.py View File

@@ -39,7 +39,7 @@ class Target1(State):
39 39
 		nm = self.own['navMesh']
40 40
 		self.pt = nm.findPath(self.own.worldPosition, self.scene.objects[self.target].worldPosition)
41 41
 		
42
-		print('target1')
42
+		#print('target1')
43 43
 		super(Target1, self).Enter()
44 44
 		
45 45
 	def Execute(self):
@@ -62,7 +62,7 @@ class Target1(State):
62 62
 			else:
63 63
 				self.pt.remove(self.pt[0])
64 64
 		else:
65
-			print('goal reached')	
65
+			#print('goal reached')	
66 66
 			self.npcFSM.ToTransition('toTarget2')	
67 67
 
68 68
 		if self.npcFSM.stateLife > duration:
@@ -87,7 +87,7 @@ class Target2(State):
87 87
 		
88 88
 		nm = self.own['navMesh']
89 89
 		self.pt = nm.findPath(self.own.worldPosition, self.scene.objects[self.target].worldPosition)
90
-		print('target2')
90
+		#print('target2')
91 91
 		super(Target2, self).Enter()
92 92
 		
93 93
 	def Execute(self):
@@ -109,7 +109,7 @@ class Target2(State):
109 109
 			else:
110 110
 				self.pt.remove(self.pt[0])
111 111
 		else:
112
-			print('goal reached')	
112
+			#print('goal reached')	
113 113
 			self.npcFSM.ToTransition('toTarget3')
114 114
 
115 115
 		if self.npcFSM.stateLife > duration:
@@ -136,7 +136,7 @@ class Target3(State):
136 136
 		nm = self.own['navMesh']
137 137
 		self.pt = nm.findPath(self.own.worldPosition, self.scene.objects[self.target].worldPosition)
138 138
 
139
-		print('target3')
139
+		#print('target3')
140 140
 		super(Target3, self).Enter()
141 141
 
142 142
 		
@@ -160,7 +160,7 @@ class Target3(State):
160 160
 			else:
161 161
 				self.pt.remove(self.pt[0])
162 162
 		else:
163
-			print('goal reached')	
163
+			#print('goal reached')	
164 164
 			self.npcFSM.ToTransition('toTarget1')	
165 165
 
166 166
 		if self.npcFSM.stateLife > duration:
@@ -194,11 +194,11 @@ class Idle(State):
194 194
 	def Execute(self):
195 195
 		self.npcFSM.stateLife += 1
196 196
 		duration = 300
197
-		if self.npcFSM.stateLife > duration:
198
-			num = randint(1,4)
199
-			self.npcFSM.ToTransition('toTarget1')
200
-		else:
201
-			self.npcArm.playAction('g_idle', 1,201, layer=2, play_mode=0, speed=.5)	
197
+		# if self.npcFSM.stateLife > duration:
198
+		# 	num = randint(1,4)
199
+		# 	self.npcFSM.ToTransition('toTarget1')
200
+		# else:
201
+		# 	self.npcArm.playAction('g_idle', 1,201, layer=2, play_mode=0, speed=.5)	
202 202
 			
203 203
 	def Exit(self):
204 204
 		pass
@@ -210,7 +210,7 @@ class Startup(State):
210 210
 		
211 211
 	def Enter(self):
212 212
 		self.npcFSM.stateLife = 1
213
-		print('npc startup enter')
213
+		#print('npc startup enter')
214 214
 		super(Startup, self).Enter()
215 215
 		
216 216
 	def Execute(self):

+ 2
- 2
shuvit.blend View File

@@ -1,3 +1,3 @@
1 1
 version https://git-lfs.github.com/spec/v1
2
-oid sha256:36b5868936935dc6e4cf8f2d4e321ff29c83909338c0a9f6a90c4e72d112b0d3
3
-size 112662748
2
+oid sha256:523757d0949b01bbfb40acc234a2165018eaac6af35797146e1dc8301ec79b68
3
+size 113390952

BIN
shuvit.blend~2 View File


Loading…
Cancel
Save