|
@@ -1,18 +1,14 @@
|
1
|
1
|
import bge
|
2
|
2
|
from random import randint
|
3
|
3
|
from time import clock
|
4
|
|
-
|
5
|
|
-
|
|
4
|
+
|
6
|
5
|
#====================================
|
7
|
6
|
class Transition(object):
|
8
|
7
|
def __init__(self, toState):
|
9
|
8
|
self.toState = toState
|
10
|
9
|
def Execute(self):
|
11
|
|
- #print('Transitioning ...', self.toState)
|
12
|
10
|
pass
|
13
|
|
-
|
14
|
|
-
|
15
|
|
-
|
|
11
|
+
|
16
|
12
|
#====================================
|
17
|
13
|
State = type("State", (object,), {})
|
18
|
14
|
|
|
@@ -23,27 +19,22 @@ class State(object):
|
23
|
19
|
self.startTime = 0
|
24
|
20
|
def Enter(self):
|
25
|
21
|
pass
|
26
|
|
- #print('entering')
|
27
|
22
|
def Execute(self):
|
28
|
23
|
pass
|
29
|
|
- #print('Executing')
|
30
|
24
|
def Exit(self):
|
31
|
25
|
pass
|
32
|
|
- #print('Exiting')
|
33
|
26
|
|
34
|
27
|
class Target1(State):
|
35
|
28
|
def __init__(self,npcFSM):
|
36
|
29
|
super(Target1, self).__init__(npcFSM)
|
37
|
30
|
|
38
|
31
|
def Enter(self):
|
39
|
|
- #print('Preparing to walk towards target 1.')
|
40
|
32
|
self.cont = bge.logic.getCurrentController()
|
41
|
33
|
self.npcFSM.stateLife = 1
|
42
|
34
|
self.own = self.cont.owner
|
43
|
35
|
self.target = 'larryTarget'
|
44
|
36
|
self.npcArm = self.own.children['npc']
|
45
|
37
|
self.scene = bge.logic.getCurrentScene()
|
46
|
|
-
|
47
|
38
|
|
48
|
39
|
nm = self.own['navMesh']
|
49
|
40
|
self.pt = nm.findPath(self.own.worldPosition, self.scene.objects[self.target].worldPosition)
|
|
@@ -52,10 +43,8 @@ class Target1(State):
|
52
|
43
|
super(Target1, self).Enter()
|
53
|
44
|
|
54
|
45
|
def Execute(self):
|
55
|
|
- #print('Tracking target 1.', self.npcFSM.stateLife)
|
56
|
46
|
self.npcFSM.stateLife += 1
|
57
|
47
|
duration = 50000
|
58
|
|
- #print('path', self.pt)
|
59
|
48
|
|
60
|
49
|
if len(self.pt) > 0:
|
61
|
50
|
target = self.pt[0]
|
|
@@ -76,24 +65,12 @@ class Target1(State):
|
76
|
65
|
print('goal reached')
|
77
|
66
|
self.npcFSM.ToTransition('toTarget2')
|
78
|
67
|
|
79
|
|
-
|
80
|
|
-
|
81
|
|
-
|
82
|
68
|
if self.npcFSM.stateLife > duration:
|
83
|
69
|
num = randint(1,2)
|
84
|
|
- # if num == 1:
|
85
|
|
- # self.npcFSM.ToTransition('toTarget2')
|
86
|
|
- # elif num ==2:
|
87
|
|
- # self.npcFSM.ToTransition('toTarget2')
|
88
|
|
- # else:
|
89
|
|
- # self.npcFSM.ToTransition('toIdle')
|
90
|
70
|
else:
|
91
|
|
- #self.cont.activate(self.actu)
|
92
|
71
|
self.npcArm.playAction('g_walk2', 1,62, layer=2, play_mode=0, speed=.5)
|
93
|
72
|
|
94
|
73
|
def Exit(self):
|
95
|
|
- #print('Finished target 1')
|
96
|
|
- #self.cont.deactivate(self.actu)
|
97
|
74
|
pass
|
98
|
75
|
|
99
|
76
|
class Target2(State):
|
|
@@ -101,7 +78,6 @@ class Target2(State):
|
101
|
78
|
super(Target2, self).__init__(npcFSM)
|
102
|
79
|
|
103
|
80
|
def Enter(self):
|
104
|
|
- #print('Preparing to walk towards target 2.')
|
105
|
81
|
self.cont = bge.logic.getCurrentController()
|
106
|
82
|
self.npcFSM.stateLife = 1
|
107
|
83
|
self.own = self.cont.owner
|
|
@@ -115,12 +91,9 @@ class Target2(State):
|
115
|
91
|
super(Target2, self).Enter()
|
116
|
92
|
|
117
|
93
|
def Execute(self):
|
118
|
|
- #print('Tracking target 2.', self.npcFSM.stateLife)
|
119
|
94
|
self.npcFSM.stateLife += 1
|
120
|
95
|
duration = 10000
|
121
|
96
|
|
122
|
|
-
|
123
|
|
-
|
124
|
97
|
if len(self.pt) > 0:
|
125
|
98
|
target = self.pt[0]
|
126
|
99
|
vg = self.own.getVectTo(target)
|
|
@@ -128,7 +101,6 @@ class Target2(State):
|
128
|
101
|
v = vg[1]
|
129
|
102
|
self.own.alignAxisToVect(v, 0, .5)
|
130
|
103
|
self.own.alignAxisToVect([0,0,1], 2, 1)
|
131
|
|
- #print(dist)
|
132
|
104
|
if dist > 1.5:
|
133
|
105
|
x = 10
|
134
|
106
|
max_vel = 1.5
|
|
@@ -142,20 +114,11 @@ class Target2(State):
|
142
|
114
|
|
143
|
115
|
if self.npcFSM.stateLife > duration:
|
144
|
116
|
num = randint(1,3)
|
145
|
|
- # if num == 1:
|
146
|
|
- # self.npcFSM.ToTransition('toTarget3')
|
147
|
|
- # elif num ==2:
|
148
|
|
- # self.npcFSM.ToTransition('toTarget3')
|
149
|
|
- # else:
|
150
|
|
- # self.npcFSM.ToTransition('toIdle')
|
151
|
117
|
else:
|
152
|
|
- #self.cont.activate(self.actu)
|
153
|
118
|
self.npcArm.playAction('g_walk2', 1,62, layer=2, play_mode=0, speed=.5)
|
154
|
119
|
|
155
|
120
|
|
156
|
121
|
def Exit(self):
|
157
|
|
- #print('Finished target 2')
|
158
|
|
- #self.cont.deactivate(self.actu)
|
159
|
122
|
pass
|
160
|
123
|
|
161
|
124
|
class Target3(State):
|
|
@@ -163,7 +126,6 @@ class Target3(State):
|
163
|
126
|
super(Target3, self).__init__(npcFSM)
|
164
|
127
|
|
165
|
128
|
def Enter(self):
|
166
|
|
- #print('Preparing to walk towards target 3.')
|
167
|
129
|
self.cont = bge.logic.getCurrentController()
|
168
|
130
|
self.npcFSM.stateLife = 1
|
169
|
131
|
self.own = self.cont.owner
|
|
@@ -173,7 +135,7 @@ class Target3(State):
|
173
|
135
|
|
174
|
136
|
nm = self.own['navMesh']
|
175
|
137
|
self.pt = nm.findPath(self.own.worldPosition, self.scene.objects[self.target].worldPosition)
|
176
|
|
-
|
|
138
|
+
|
177
|
139
|
print('target3')
|
178
|
140
|
super(Target3, self).Enter()
|
179
|
141
|
|
|
@@ -213,8 +175,6 @@ class Target3(State):
|
213
|
175
|
|
214
|
176
|
|
215
|
177
|
def Exit(self):
|
216
|
|
- #print('Finished target 3')
|
217
|
|
- #self.cont.deactivate(self.actu)
|
218
|
178
|
pass
|
219
|
179
|
|
220
|
180
|
|
|
@@ -224,7 +184,6 @@ class Idle(State):
|
224
|
184
|
super(Idle, self).__init__(npcFSM)
|
225
|
185
|
|
226
|
186
|
def Enter(self):
|
227
|
|
- #print('Starting to idle.')
|
228
|
187
|
self.cont = bge.logic.getCurrentController()
|
229
|
188
|
self.own = self.cont.owner
|
230
|
189
|
self.npcArm = self.own.children['npc']
|
|
@@ -233,33 +192,16 @@ class Idle(State):
|
233
|
192
|
super(Idle, self).Enter()
|
234
|
193
|
|
235
|
194
|
def Execute(self):
|
236
|
|
- #print('Idleing.', self.npcFSM.stateLife)
|
237
|
195
|
self.npcFSM.stateLife += 1
|
238
|
196
|
duration = 300
|
239
|
197
|
if self.npcFSM.stateLife > duration:
|
240
|
198
|
num = randint(1,4)
|
241
|
|
- #self.npcFSM.ToTransition('toImpatient')
|
242
|
199
|
self.npcFSM.ToTransition('toTarget1')
|
243
|
|
- # if num == 1:
|
244
|
|
- # self.npcFSM.ToTransition('toTarget1')
|
245
|
|
- # elif num == 2:
|
246
|
|
- # self.npcFSM.ToTransition('toTarget2')
|
247
|
|
- # elif num == 3:
|
248
|
|
- # self.npcFSM.ToTransition('toTarget3')
|
249
|
|
- # elif num == 4 or num == 5 or num == 6:
|
250
|
|
- # self.npcFSM.ToTransition('toImpatient')
|
251
|
|
- # else:
|
252
|
|
- # self.npcFSM.ToTransition('toIdle')
|
253
|
200
|
else:
|
254
|
|
- #pass
|
255
|
|
- #print(self.own.children)
|
256
|
|
- #print('idling')
|
257
|
201
|
self.npcArm.playAction('g_idle', 1,201, layer=2, play_mode=0, speed=.5)
|
258
|
202
|
|
259
|
203
|
def Exit(self):
|
260
|
204
|
pass
|
261
|
|
- ##print('Waking up from idle.')
|
262
|
|
-
|
263
|
205
|
|
264
|
206
|
class Startup(State):
|
265
|
207
|
|
|
@@ -288,7 +230,6 @@ class Impatient(State):
|
288
|
230
|
super(Impatient, self).__init__(npcFSM)
|
289
|
231
|
|
290
|
232
|
def Enter(self):
|
291
|
|
- #print('Starting to idle.')
|
292
|
233
|
self.npcFSM.stateLife = 1
|
293
|
234
|
self.cont = bge.logic.getCurrentController()
|
294
|
235
|
self.own = self.cont.owner
|
|
@@ -296,7 +237,6 @@ class Impatient(State):
|
296
|
237
|
super(Impatient, self).Enter()
|
297
|
238
|
|
298
|
239
|
def Execute(self):
|
299
|
|
- #print('being Impatient.', self.npcFSM.stateLife)
|
300
|
240
|
self.npcFSM.stateLife += 1
|
301
|
241
|
duration = 300
|
302
|
242
|
if self.npcFSM.stateLife > duration:
|
|
@@ -306,9 +246,7 @@ class Impatient(State):
|
306
|
246
|
self.npcArm.playAction('npcImpatient', 1,201, layer=2, play_mode=0, speed=.5)
|
307
|
247
|
|
308
|
248
|
def Exit(self):
|
309
|
|
- pass
|
310
|
|
- #print('stopping bening impatient.')
|
311
|
|
-
|
|
249
|
+ pass
|
312
|
250
|
|
313
|
251
|
#===================================
|
314
|
252
|
|
|
@@ -351,9 +289,6 @@ Char = type("Char",(object,),{})
|
351
|
289
|
class Walker(Char):
|
352
|
290
|
def __init__(self):
|
353
|
291
|
self.npcFSM = npcFSM(self)
|
354
|
|
- #cont = bge.logic.getCurrentController()
|
355
|
|
- #own = cont.owner
|
356
|
|
- #self.LightOn = own['state']
|
357
|
292
|
|
358
|
293
|
##STATES
|
359
|
294
|
self.npcFSM.AddState("Startup", Startup(self.npcFSM))
|
|
@@ -374,12 +309,10 @@ class Walker(Char):
|
374
|
309
|
|
375
|
310
|
if self.npcFSM.curState == None:
|
376
|
311
|
self.npcFSM.SetState('Startup')
|
377
|
|
- #self.npcFSM.ToTransition('toIdle')
|
378
|
|
- #print('setting npc state to startup')
|
379
|
312
|
|
380
|
313
|
def Execute(self):
|
381
|
314
|
self.npcFSM.Execute()
|
382
|
|
- #print('executing machine')
|
|
315
|
+
|
383
|
316
|
#====================================
|
384
|
317
|
r = Walker()
|
385
|
318
|
def main(cont):
|
|
@@ -394,7 +327,6 @@ def main(cont):
|
394
|
327
|
for x in scene.objects:
|
395
|
328
|
if 'npcNavmesh' in x:
|
396
|
329
|
own['navMesh'] = x
|
397
|
|
- #print('initing')
|
398
|
330
|
|
399
|
331
|
if own['frame'] == 40:
|
400
|
332
|
own.worldPosition = [0,0,50]
|
|
@@ -404,12 +336,8 @@ def main(cont):
|
404
|
336
|
to = scene.objects[ln]
|
405
|
337
|
own.worldPosition = to.worldPosition
|
406
|
338
|
own.worldOrientation = to.worldOrientation
|
407
|
|
- #own.worldPosition.z += 50
|
408
|
|
-
|
409
|
339
|
|
410
|
340
|
r.Execute()
|
411
|
|
- #print(r.npcFSM.curState)
|
412
|
|
-
|
413
|
341
|
|
414
|
342
|
own['frame'] += 1
|
415
|
343
|
yvel = own.linearVelocity.y
|