Browse Source

cam states setup

shuvit 3 years ago
parent
commit
0345b0794d
4 changed files with 111 additions and 62 deletions
  1. BIN
      scripts/__pycache__/controller2.cpython-36.pyc
  2. 69
    42
      scripts/camFSM.py
  3. 40
    18
      scripts/camera.py
  4. 2
    2
      scripts/controller2.py

BIN
scripts/__pycache__/controller2.cpython-36.pyc View File


+ 69
- 42
scripts/camFSM.py View File

@@ -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

+ 40
- 18
scripts/camera.py View File

@@ -58,30 +58,51 @@ def main(cont):
58 58
         dict['cur_ccH_min'] = dict['cam_walk_min']
59 59
         dict['cur_ccH_max'] = dict['cam_walk_max']
60 60
         cam.height = dict['cam_height']
61
+        dict['cam_state'] = 'walking'
62
+        controlcube['ragdoll_active'] = False
61 63
     acam = scene.active_camera
62 64
 
65
+    def get_cam_state():
66
+        if  dict['npause']:
67
+            if dict['menu_idle_timer'] > 300:
68
+                #dict['cam_state'] = 'pause_idle'
69
+                dict['cam_state'] = 'PauseIdleCam'
70
+            else:    
71
+                dict['cam_state'] = 'PauseCam'
72
+        elif walk == 1:
73
+            if controlcube['ragdoll_active']:
74
+                dict['cam_state'] = 'RagdollCam'
75
+            else:
76
+                dict['cam_state'] = 'WalkCam'
77
+        elif controlcube['driving']:
78
+            dict['cam_state'] = 'driving'
79
+        else:
80
+            dict['cam_state'] = 'RollCam'   
81
+        #print(dict['cam_state'])             
82
+
83
+
63 84
     if controlcube['driving'] == False:
64 85
         LAST_GRIND = False
65 86
         if down.triggered == True and LAST_GRIND == False and walk == 0:
66 87
             hitPosition = down.hitPosition
67 88
             distance = own.getDistanceTo(hitPosition)
68 89
             cam_moved = 1
69
-            if 'vert' not in down.hitObject:
70
-                if distance < .2:
71
-                    camempty['hitdown'] = True
72
-                    cam.height = cam_height + .3
73
-                    cam.damping = .0
74
-                    print("raise cam")
75
-                if zdist < -.2:
76
-                    cam.height = lastCamheight + .01
77
-                    cam.damping = .0
78
-                    raised = 1
79
-                if (distance > .4 and distance < .6) and zdist > -.2 and raised == 0:
80
-                    camheight2 = cam.height - .001
81
-                    if cam.height < .2:
82
-                        cam.height = camheight2
83
-                if distance >= .6 and zdist > -.2 and raised == 0:
84
-                    cam.height = cam.height - .02
90
+            # if 'vert' not in down.hitObject:
91
+            #     if distance < .2:
92
+            #         camempty['hitdown'] = True
93
+            #         cam.height = cam_height + .3
94
+            #         cam.damping = .0
95
+            #         print("raise cam")
96
+            #     if zdist < -.2:
97
+            #         cam.height = lastCamheight + .01
98
+            #         cam.damping = .0
99
+            #         raised = 1
100
+            #     if (distance > .4 and distance < .6) and zdist > -.2 and raised == 0:
101
+            #         camheight2 = cam.height - .001
102
+            #         if cam.height < .2:
103
+            #             cam.height = camheight2
104
+            #     if distance >= .6 and zdist > -.2 and raised == 0:
105
+            #         cam.height = cam.height - .02
85 106
         if down.triggered == False and LAST_GRIND == False and cam_moved == 0 and walk == 0:
86 107
             camempty['hitdown'] = False
87 108
             if cam_height > (cam_def_height + .06) and zdist > -.2 and raised == 0:
@@ -141,8 +162,7 @@ def main(cont):
141 162
         control = "control_cube.002"
142 163
         hitobj = hit[0]
143 164
         hitobj = str(hitobj)
144
-        if 'ragdoll_active' not in controlcube:
145
-            controlcube['ragdoll_active'] = False
165
+        
146 166
         if hit[0]:
147 167
             if hitobj != control and walk == 0 and 'vert' not in hit[0] and 'ground' in hit[0] and controlcube['ragdoll_active'] == False:
148 168
                 cam.damping = .0
@@ -352,3 +372,5 @@ def main(cont):
352 372
         cam.max = new_max
353 373
     except:
354 374
         pass
375
+    get_cam_state()
376
+    camFSM.main(cont)

+ 2
- 2
scripts/controller2.py View File

@@ -228,7 +228,7 @@ def main():
228 228
             #print('not on ground', localHitDist, own['jump_timer'])     
229 229
     else:
230 230
         onGround = False
231
-        print('not on ground', grindRay[0], own['LAST_GRIND'])
231
+        #print('not on ground', grindRay[0], own['LAST_GRIND'])
232 232
         if grindRay[0] and own['LAST_GRIND'] == True:
233 233
 
234 234
             onGround = True
@@ -4522,7 +4522,7 @@ def main():
4522 4522
         if 'transition' in localRay[0]:
4523 4523
             own['transition'] = True
4524 4524
             own['last_transition_frame'] = own['framenum']
4525
-            print('transition')
4525
+            #print('transition')
4526 4526
         localHitDist = (own.worldPosition - localRay[1]).length
4527 4527
         #print('gh', localHitDist)
4528 4528
         if localHitDist < .4:

Loading…
Cancel
Save