shuvit 4 years ago
parent
commit
a13ccb218b
3 changed files with 64 additions and 0 deletions
  1. 23
    0
      scripts/FSM.py
  2. 38
    0
      scripts/StatesGame.py
  3. 3
    0
      scripts/main.py

+ 23
- 0
scripts/FSM.py View File

@@ -56,6 +56,29 @@ Char = type("Char",(object,),{})
56 56
 
57 57
 #===================================
58 58
           
59
+
60
+#=================================== 
61
+
62
+class GameFSM(Char):
63
+    def __init__(self, owner):
64
+        self.FSM = FSM(self, owner)
65
+        self.owner = owner
66
+        
67
+        state_list = [
68
+        'Example']
69
+        
70
+        for s in state_list:
71
+            self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
72
+            t = 'to' + s
73
+            self.FSM.AddTransition(t, Transition(s))
74
+        
75
+        if self.FSM.curState == None:
76
+            self.FSM.SetState('Example')
77
+    
78
+    def Execute(self):
79
+        self.FSM.Execute(self.owner)    
80
+
81
+#=================================== 
59 82
         
60 83
 #=================================== 
61 84
 

+ 38
- 0
scripts/StatesGame.py View File

@@ -0,0 +1,38 @@
1
+import utils
2
+import bge
3
+
4
+State = type("State", (object,), {})
5
+#====================================     
6
+class State(object):
7
+    def __init__(self, FSM):
8
+        self.FSM = FSM
9
+        self.timer = 0
10
+        self.startTime = 0
11
+    def Enter(self):
12
+        self.timer = 0
13
+        self.startTime = 0
14
+    def Execute(self):
15
+        print('Executing')
16
+    def Exit(self):
17
+        print('Exiting')
18
+#==================================== 
19
+            
20
+class Example(State):
21
+    def __init__(self,FSM):
22
+        super(Example, self).__init__(FSM)    
23
+        
24
+    def Enter(self):
25
+        self.FSM.stateLife = 1
26
+        super(Example, self).Enter()        
27
+        
28
+    def Execute(self):
29
+        self.FSM.stateLife += 1
30
+        #o = self.FSM.owner
31
+        #g = o.me['game']
32
+        #self.FSM.ToTransition('toNewState')
33
+        #print('cam fsm')
34
+    
35
+    def Exit(self):
36
+        pass
37
+
38
+#====================================  

+ 3
- 0
scripts/main.py View File

@@ -0,0 +1,3 @@
1
+#main game loop
2
+
3
+def main(cont):

Loading…
Cancel
Save