|
@@ -1,21 +1,28 @@
|
1
|
1
|
import bge
|
2
|
2
|
from random import randint
|
3
|
3
|
from time import clock
|
|
4
|
+dict = bge.logic.globalDict
|
4
|
5
|
|
5
|
|
-
|
6
|
|
-
|
7
|
6
|
|
|
7
|
+def get_request_state(cur_state):
|
|
8
|
+ if dict['cam_state'] != cur_state:
|
|
9
|
+ print(cur_state)
|
|
10
|
+ print('change cam')
|
|
11
|
+ return 'to' + str(dict['cam_state'])
|
|
12
|
+ else:
|
|
13
|
+ return None
|
8
|
14
|
|
9
|
15
|
#camera - (Target Object, Min Distance, Max Distance, Height)
|
10
|
16
|
def activate_camera(cobj, cmin, cmax, cheight):
|
11
|
|
- cont = bge.logic.getCurrentController()
|
12
|
|
- scene = bge.logic.getCurrentScene()
|
13
|
|
- camActu = cont.actuators['Camera']
|
14
|
|
- camActu.object = scene.objects[cobj]
|
15
|
|
- camActu.min = cmin
|
16
|
|
- camActu.max = cmax
|
17
|
|
- camActu.height = cheight
|
18
|
|
- cont.activate(camActu)
|
|
17
|
+ pass
|
|
18
|
+ # cont = bge.logic.getCurrentController()
|
|
19
|
+ # scene = bge.logic.getCurrentScene()
|
|
20
|
+ # camActu = cont.actuators['Camera']
|
|
21
|
+ # camActu.object = scene.objects[cobj]
|
|
22
|
+ # camActu.min = cmin
|
|
23
|
+ # camActu.max = cmax
|
|
24
|
+ # camActu.height = cheight
|
|
25
|
+ # cont.activate(camActu)
|
19
|
26
|
|
20
|
27
|
|
21
|
28
|
|
|
@@ -65,13 +72,12 @@ class WalkCam(State):
|
65
|
72
|
#print('walk cam state', self.FSM.stateLife)
|
66
|
73
|
self.FSM.stateLife += 1
|
67
|
74
|
duration = 50
|
68
|
|
- activate_camera('camCube', 2, 3, 1)
|
69
|
|
- # if self.FSM.stateLife > duration:
|
70
|
|
- # if not (randint(1,3) % 2):
|
71
|
|
- # self.FSM.ToTransition('toRollCam')
|
72
|
|
- # else:
|
73
|
|
- # self.FSM.ToTransition('toRagdollCam')
|
74
|
|
-
|
|
75
|
+ #activate_camera('camCube', 2, 3, 1)
|
|
76
|
+ new_state = get_request_state(self.__class__.__name__)
|
|
77
|
+ if new_state:
|
|
78
|
+ self.FSM.ToTransition(new_state)
|
|
79
|
+ print('call new state')
|
|
80
|
+
|
75
|
81
|
def Exit(self):
|
76
|
82
|
print('walk cam state')
|
77
|
83
|
|
|
@@ -88,12 +94,11 @@ class RollCam(State):
|
88
|
94
|
#print('Eating Breakfast.', self.FSM.stateLife)
|
89
|
95
|
self.FSM.stateLife += 1
|
90
|
96
|
duration = 500
|
91
|
|
- activate_camera('camCube', 1.5, 3, 2)
|
92
|
|
- if self.FSM.stateLife > duration:
|
93
|
|
- if not (randint(1,3) % 2):
|
94
|
|
- self.FSM.ToTransition('toRagdollCam')
|
95
|
|
- else:
|
96
|
|
- self.FSM.ToTransition('toWalkCam')
|
|
97
|
+ #activate_camera('camCube', 1.5, 3, 2)
|
|
98
|
+ new_state = get_request_state(self.__class__.__name__)
|
|
99
|
+ if new_state:
|
|
100
|
+ self.FSM.ToTransition(new_state)
|
|
101
|
+ print('call new state')
|
97
|
102
|
|
98
|
103
|
def Exit(self):
|
99
|
104
|
print('Finished RollCaming')
|
|
@@ -111,12 +116,10 @@ class RagdollCam(State):
|
111
|
116
|
#print('Vacumming.', self.FSM.stateLife)
|
112
|
117
|
self.FSM.stateLife += 1
|
113
|
118
|
duration = 6
|
114
|
|
- if self.FSM.stateLife > duration:
|
115
|
|
- #if (self.startTime + self.timer <= clock()):
|
116
|
|
- if not (randint(1,3) % 2):
|
117
|
|
- self.FSM.ToTransition('toWalkCam')
|
118
|
|
- else:
|
119
|
|
- self.FSM.ToTransition('toPauseCam')
|
|
119
|
+ new_state = get_request_state(self.__class__.__name__)
|
|
120
|
+ if new_state:
|
|
121
|
+ self.FSM.ToTransition(new_state)
|
|
122
|
+ print('call new state')
|
120
|
123
|
|
121
|
124
|
def Exit(self):
|
122
|
125
|
print('Finished RagdollCaming')
|
|
@@ -135,12 +138,34 @@ class PauseCam(State):
|
135
|
138
|
def Execute(self):
|
136
|
139
|
print('PauseCaming.', self.FSM.stateLife)
|
137
|
140
|
self.FSM.stateLife += 1
|
138
|
|
- duration = 10
|
139
|
|
- if self.FSM.stateLife > duration:
|
140
|
|
- self.FSM.ToTransition('toWalkCam')
|
141
|
|
-
|
|
141
|
+ new_state = get_request_state(self.__class__.__name__)
|
|
142
|
+ if new_state != None:
|
|
143
|
+ self.FSM.ToTransition(new_state)
|
|
144
|
+ print('call new state')
|
|
145
|
+
|
|
146
|
+ def Exit(self):
|
|
147
|
+ print('Finished PauseCaming.')
|
|
148
|
+
|
|
149
|
+class PauseIdleCam(State):
|
|
150
|
+
|
|
151
|
+ def __init__(self,FSM):
|
|
152
|
+ super(PauseIdleCam, self).__init__(FSM)
|
|
153
|
+
|
|
154
|
+ def Enter(self):
|
|
155
|
+ print('Starting to PauseIdleCam.')
|
|
156
|
+ super(PauseCam, self).Enter()
|
|
157
|
+ self.FSM.stateLife = 1
|
|
158
|
+
|
|
159
|
+ def Execute(self):
|
|
160
|
+ print('PauseIdleCaming.', self.FSM.stateLife)
|
|
161
|
+ self.FSM.stateLife += 1
|
|
162
|
+ new_state = get_request_state(self.__class__.__name__)
|
|
163
|
+ if new_state != None:
|
|
164
|
+ self.FSM.ToTransition(new_state)
|
|
165
|
+ print('call new state')
|
|
166
|
+
|
142
|
167
|
def Exit(self):
|
143
|
|
- print('Finished PauseCaming.')
|
|
168
|
+ print('Finished PauseIdleCaming.')
|
144
|
169
|
|
145
|
170
|
#===================================
|
146
|
171
|
|
|
@@ -189,9 +214,11 @@ class CameraFSM(Char):
|
189
|
214
|
self.FSM.AddState('RollCam', RollCam(self.FSM))
|
190
|
215
|
self.FSM.AddState('RagdollCam', RagdollCam(self.FSM))
|
191
|
216
|
self.FSM.AddState("PauseCam", PauseCam(self.FSM))
|
|
217
|
+ self.FSM.AddState("PauseIdleCam", PauseIdleCam(self.FSM))
|
192
|
218
|
|
193
|
219
|
#TRANSITIONS
|
194
|
220
|
self.FSM.AddTransition('toPauseCam', Transition('PauseCam'))
|
|
221
|
+ self.FSM.AddTransition('toPauseIdleCam', Transition('PauseIdleCam'))
|
195
|
222
|
self.FSM.AddTransition('toWalkCam', Transition('WalkCam'))
|
196
|
223
|
self.FSM.AddTransition('toRollCam', Transition('RollCam'))
|
197
|
224
|
self.FSM.AddTransition('toRagdollCam', Transition('RagdollCam'))
|
|
@@ -203,16 +230,16 @@ class CameraFSM(Char):
|
203
|
230
|
def Execute(self):
|
204
|
231
|
self.FSM.Execute()
|
205
|
232
|
#====================================
|
206
|
|
-r = CameraFSM()
|
|
233
|
+machine = CameraFSM()
|
207
|
234
|
def main(cont):
|
208
|
235
|
own = cont.owner
|
209
|
236
|
|
210
|
|
- if 'inited' not in own:
|
211
|
|
- own['inited'] = True
|
212
|
|
- own['frame'] = 0
|
213
|
|
- own['state'] = 'On'
|
214
|
|
- print('initing')
|
|
237
|
+ if 'FSMinited' not in own:
|
|
238
|
+ own['FSMinited'] = True
|
|
239
|
+ #own['frame'] = 0
|
|
240
|
+ #own['state'] = 'On'
|
|
241
|
+ print('FSMiniting')
|
215
|
242
|
|
216
|
|
- r.Execute()
|
|
243
|
+ machine.Execute()
|
217
|
244
|
|
218
|
|
- own['frame'] += 1
|
|
245
|
+ #own['frame'] += 1
|