shuvit 3 years ago
parent
commit
93959d24a8
10 changed files with 297 additions and 36 deletions
  1. 1
    1
      config.ini
  2. 32
    2
      scripts/FSM.py
  3. 8
    13
      scripts/Settings.py
  4. 1
    0
      scripts/Startup.py
  5. 133
    0
      scripts/StatesGame.py
  6. 93
    0
      scripts/StatesPlayer.py
  7. 12
    0
      scripts/game.py
  8. 1
    1
      scripts/inputs.py
  9. 2
    19
      scripts/logo_fades.py
  10. 14
    0
      scripts/player.py

+ 1
- 1
config.ini View File

@@ -143,7 +143,7 @@ pump_downforce = -0.0
143 143
 man_sens_l = 0.03
144 144
 man_sens_r = 0.08
145 145
 man_sens_side = 0.035
146
-turn_rotation = 0.025 #0.0175
146
+turn_rotation = 0.025#0.0175
147 147
 turn_addx = 0.004
148 148
 turn_air_rotation = 0.07
149 149
 grass_mult = 0.98

+ 32
- 2
scripts/FSM.py View File

@@ -1,5 +1,7 @@
1 1
 import bge
2 2
 
3
+import StatesGame
4
+import StatesPlayer
3 5
 import StatesWalker
4 6
 import StatesCamera
5 7
 import StatesCar
@@ -67,7 +69,11 @@ class GameFSM(Char):
67 69
         self.owner = owner
68 70
         
69 71
         state_list = [
70
-        'Example']
72
+        'Example',
73
+        'Startup',
74
+        'Initer',
75
+        'LoadLevel',
76
+        'GameOn']
71 77
         
72 78
         for s in state_list:
73 79
             self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
@@ -75,7 +81,31 @@ class GameFSM(Char):
75 81
             self.FSM.AddTransition(t, Transition(s))
76 82
         
77 83
         if self.FSM.curState == None:
78
-            self.FSM.SetState('Example')
84
+            self.FSM.SetState('Startup')
85
+    
86
+    def Execute(self):
87
+        self.FSM.Execute(self.owner)    
88
+
89
+#=================================== 
90
+        
91
+class PlayerFSM(Char):
92
+    def __init__(self, owner):
93
+        self.FSM = FSM(self, owner)
94
+        self.owner = owner
95
+        
96
+        state_list = [
97
+        'Example',
98
+        'Startup',
99
+        'Walk',
100
+        'Roll']
101
+        
102
+        for s in state_list:
103
+            self.FSM.AddState(s, getattr(StatesPlayer, s)(self.FSM))
104
+            t = 'to' + s
105
+            self.FSM.AddTransition(t, Transition(s))
106
+        
107
+        if self.FSM.curState == None:
108
+            self.FSM.SetState('Startup')
79 109
     
80 110
     def Execute(self):
81 111
         self.FSM.Execute(self.owner)    

+ 8
- 13
scripts/Settings.py View File

@@ -34,7 +34,7 @@ def readChar():
34 34
     
35 35
     
36 36
     def to_dict2(section, key):
37
-        dict = bge.logic.globalDict
37
+        #dict = bge.logic.globalDict
38 38
         value = char_config[key]
39 39
         if isinstance(value, str):
40 40
             if value.isdigit():
@@ -51,7 +51,7 @@ def readChar():
51 51
     char_config.walk(to_dict2, char_config)
52 52
     
53 53
 def writeChar():
54
-    dict = bge.logic.globalDict
54
+    #dict = bge.logic.globalDict
55 55
     mainDir = GameLogic.expandPath("//characters/")    
56 56
     fileName = mainDir + dict['character'] + ".ini"
57 57
     print('writing character settings', fileName)
@@ -70,21 +70,21 @@ def readSettings():
70 70
     readChar()
71 71
 
72 72
 def from_dict(section, key):
73
-    dict = bge.logic.globalDict
73
+    #dict = bge.logic.globalDict
74 74
     config[key] = dict[key]
75 75
 
76 76
 def writeSettings():
77 77
     config.walk(from_dict)  
78 78
     config.write()  
79
-    dict = bge.logic.globalDict
79
+    #dict = bge.logic.globalDict
80 80
      
81 81
 def setres():
82
-    import GameLogic
83
-    import bge
82
+    #import GameLogic
83
+    #import bge
84 84
     scenes = bge.logic.getSceneList()
85 85
     main_scene = [scene for scene in scenes if scene.name=="main"][0]
86 86
     own = main_scene.objects['Empty']
87
-    cont = GameLogic.getCurrentController()
87
+    cont = bge.logic.getCurrentController()
88 88
     own2 = cont.owner
89 89
     dict = bge.logic.globalDict 
90 90
     resx = int(dict["resx"])
@@ -104,8 +104,6 @@ def setres():
104 104
     #print("resolution = ", resx, resy)       
105 105
         
106 106
 def loadlevel():
107
-    import GameLogic
108
-    import bge
109 107
     scenes = bge.logic.getSceneList()
110 108
     main_scene = [scene for scene in scenes if scene.name=="main"][0]
111 109
     own = main_scene.objects['Empty']
@@ -127,10 +125,7 @@ def loadlevel():
127 125
     dict['npause'] = False 
128 126
     
129 127
 def timer():
130
-    import GameLogic
131
-    import bge    
132
-
133
-    dict = bge.logic.globalDict    
128
+    #dict = bge.logic.globalDict    
134 129
     
135 130
     if dict['reload_timer'] == 1:
136 131
         scene = bge.logic.getCurrentScene()

+ 1
- 0
scripts/Startup.py View File

@@ -2,6 +2,7 @@ import bge
2 2
 
3 3
 def main(cont):
4 4
     #cont = bge.logic.getCurrentController() 
5
+    print('Startup.py running ----------')
5 6
     own = cont.owner
6 7
     scenes = bge.logic.getSceneList()
7 8
 

+ 133
- 0
scripts/StatesGame.py View File

@@ -0,0 +1,133 @@
1
+import bge
2
+import random
3
+
4
+import Startup as S2
5
+import Settings
6
+import inputs
7
+import logo_fades
8
+#====================================     
9
+
10
+State = type("State", (object,), {})
11
+#====================================     
12
+class State(object):
13
+    def __init__(self, FSM):
14
+        self.FSM = FSM
15
+        self.timer = 0
16
+        self.startTime = 0
17
+    def Enter(self):
18
+        self.timer = 0
19
+        self.startTime = 0
20
+    def Execute(self):
21
+        print('Executing')
22
+    def Exit(self):
23
+        print('Exiting')
24
+
25
+#==================================== 
26
+            
27
+class Example(State):
28
+    def __init__(self,FSM):
29
+        super(Example, self).__init__(FSM)    
30
+        
31
+    def Enter(self):
32
+        self.FSM.stateLife = 1
33
+        super(Example, self).Enter()        
34
+        
35
+    def Execute(self):
36
+        self.FSM.stateLife += 1
37
+        #self.FSM.ToTransition('toLand')
38
+        
39
+    def Exit(self):
40
+        pass
41
+
42
+#==================================== 
43
+
44
+class Startup(State):
45
+    def __init__(self,FSM):
46
+        super(Startup, self).__init__(FSM)    
47
+        
48
+    def Enter(self):
49
+        self.FSM.stateLife = 1
50
+        super(Startup, self).Enter()        
51
+        
52
+    def Execute(self):
53
+        self.FSM.stateLife += 1
54
+
55
+        #if self.FSM.stateLife == 2:
56
+            #Startup.main(self.FSM.owner['cont'])
57
+
58
+        self.FSM.ToTransition('toIniter')
59
+        
60
+    def Exit(self):
61
+        pass
62
+
63
+#==================================== 
64
+
65
+class Initer(State):
66
+    def __init__(self,FSM):
67
+        super(Initer, self).__init__(FSM)    
68
+        
69
+    def Enter(self):
70
+        self.FSM.stateLife = 1
71
+        super(Initer, self).Enter()        
72
+        
73
+    def Execute(self):
74
+        self.FSM.stateLife += 1
75
+
76
+        if self.FSM.stateLife == 2:
77
+            print('--------- fsm running startup')
78
+            S2.main(self.FSM.owner['cont'])
79
+            #Settings.readSettings(self.FSM.owner['cont'])
80
+            Settings.readSettings()
81
+            Settings.setres()
82
+
83
+
84
+        if self.FSM.stateLife == 120:
85
+
86
+            self.FSM.ToTransition('toLoadLevel')
87
+        
88
+    def Exit(self):
89
+        pass
90
+
91
+
92
+#==================================== 
93
+
94
+class LoadLevel(State):
95
+    def __init__(self,FSM):
96
+        super(LoadLevel, self).__init__(FSM)    
97
+        
98
+    def Enter(self):
99
+        self.FSM.stateLife = 1
100
+        super(LoadLevel, self).Enter()        
101
+        
102
+    def Execute(self):
103
+        self.FSM.stateLife += 1
104
+        print('fsm loading level')
105
+        
106
+        Settings.loadlevel()
107
+        
108
+        self.FSM.ToTransition('toGameOn')
109
+    def Exit(self):
110
+        pass
111
+
112
+#==================================== 
113
+
114
+class GameOn(State):
115
+    def __init__(self,FSM):
116
+        super(GameOn, self).__init__(FSM)    
117
+        
118
+    def Enter(self):
119
+        self.FSM.stateLife = 1
120
+        super(GameOn, self).Enter()        
121
+        
122
+    def Execute(self):
123
+        self.FSM.stateLife += 1
124
+        #self.FSM.ToTransition('toLand')
125
+        #print('game on')
126
+
127
+        inputs.main()
128
+        logo_fades.main()
129
+
130
+    def Exit(self):
131
+        pass
132
+
133
+#==================================== 

+ 93
- 0
scripts/StatesPlayer.py View File

@@ -0,0 +1,93 @@
1
+import bge
2
+
3
+#====================================     
4
+
5
+State = type("State", (object,), {})
6
+#====================================     
7
+class State(object):
8
+    def __init__(self, FSM):
9
+        self.FSM = FSM
10
+        self.timer = 0
11
+        self.startTime = 0
12
+    def Enter(self):
13
+        self.timer = 0
14
+        self.startTime = 0
15
+    def Execute(self):
16
+        print('Executing')
17
+    def Exit(self):
18
+        print('Exiting')
19
+
20
+#==================================== 
21
+            
22
+class Example(State):
23
+    def __init__(self,FSM):
24
+        super(Example, self).__init__(FSM)    
25
+        
26
+    def Enter(self):
27
+        self.FSM.stateLife = 1
28
+        super(Example, self).Enter()        
29
+        
30
+    def Execute(self):
31
+        self.FSM.stateLife += 1
32
+        #self.FSM.ToTransition('toLand')
33
+        
34
+    def Exit(self):
35
+        pass
36
+
37
+#==================================== 
38
+
39
+class Startup(State):
40
+    def __init__(self,FSM):
41
+        super(Startup, self).__init__(FSM)    
42
+        
43
+    def Enter(self):
44
+        self.FSM.stateLife = 1
45
+        super(Startup, self).Enter()        
46
+        
47
+    def Execute(self):
48
+        self.FSM.stateLife += 1
49
+
50
+        #if self.FSM.stateLife == 2:
51
+            #Startup.main(self.FSM.owner['cont'])
52
+
53
+        self.FSM.ToTransition('toWalk')
54
+        print('player FSM')
55
+        
56
+    def Exit(self):
57
+        pass
58
+
59
+#==================================== 
60
+            
61
+class Walk(State):
62
+    def __init__(self,FSM):
63
+        super(Walk, self).__init__(FSM)    
64
+        
65
+    def Enter(self):
66
+        self.FSM.stateLife = 1
67
+        super(Walk, self).Enter()        
68
+        
69
+    def Execute(self):
70
+        self.FSM.stateLife += 1
71
+        #self.FSM.ToTransition('toLand')
72
+        
73
+    def Exit(self):
74
+        pass
75
+
76
+#==================================== 
77
+            
78
+class Roll(State):
79
+    def __init__(self,FSM):
80
+        super(Roll, self).__init__(FSM)    
81
+        
82
+    def Enter(self):
83
+        self.FSM.stateLife = 1
84
+        super(Roll, self).Enter()        
85
+        
86
+    def Execute(self):
87
+        self.FSM.stateLife += 1
88
+        #self.FSM.ToTransition('toLand')
89
+        
90
+    def Exit(self):
91
+        pass
92
+
93
+#==================================== 

+ 12
- 0
scripts/game.py View File

@@ -0,0 +1,12 @@
1
+import bge
2
+import FSM
3
+
4
+def main(cont):
5
+	own = cont.owner
6
+	dict = bge.logic.globalDict
7
+	if 'game_inited' not in own:
8
+		own['game_inited'] = True
9
+		own['cont'] = cont
10
+		dict['gameFSM'] = FSM.GameFSM(own)
11
+
12
+	dict['gameFSM'].Execute()

+ 1
- 1
scripts/inputs.py View File

@@ -311,5 +311,5 @@ def main():
311 311
             cube.restoreDynamics()
312 312
             print(cube.isSuspendDynamics)
313 313
 
314
-main()
314
+#main()
315 315
 

+ 2
- 19
scripts/logo_fades.py View File

@@ -1,5 +1,5 @@
1 1
 import bge
2
-import Settings
2
+#import Settings
3 3
 
4 4
 def main():
5 5
 
@@ -9,43 +9,26 @@ def main():
9 9
     scene = bge.logic.getCurrentScene()
10 10
     black = scene.objects['black']
11 11
     shuvit_logo = scene.objects['shuvit_logo']
12
-    levels = ['garage18', 'mini_scene']
13 12
     scenes = bge.logic.getSceneList()
14
-    #print(dict['load_timer'])
15 13
     
16 14
     if dict['overlay_fadein'] == 1:
17
-        #dict['overlay_fadein'] = 0
18
-        #black.playAction('black_fade', 0,60, layer=0, play_mode=0)
19
-        #print("---add fade")
20
-        #fade_in
21
-        
22 15
         for i in scenes:
23 16
             if i.name == "fade_in":
24 17
                 scene2 = i
25 18
                 scene2.end()         
26 19
         cont.activate(own.actuators['add_fade'])  
27 20
         
28
-        #skater.playAction("reg_noses", 30,40, layer=trans_layer, play_mode=0, speed=.5)
29 21
     if dict['overlay_fadeout'] == 1:
30 22
         dict['overlay_fadeout'] = 0    
31 23
         black.playAction('black_fade', 100,200, layer=2, play_mode=0) 
32 24
         shuvit_logo.playAction('logo_fade', 100,200, layer=0, play_mode=0)  
33
-        #print('fade out black and logo') 
34 25
         
35 26
     if dict['load_timer'] > 0:
36 27
         dict['load_timer'] -= 1
37 28
     if dict['load_timer'] == 3:
38
-        #load   
39 29
         scenes = bge.logic.getSceneList()
40
-        #print('scenes: ', scenes)
41 30
 
42
-                 
43
-        #Settings.loadlevel()
44
-        #print('----reloading----')
45 31
         dict['load_timer'] == 0
46 32
         cont.activate(own.actuators['reload_game'])
47
-        
48
-        #cont.activate(own.actuators["loading"])
49
-        #print('loading', dict['level'])
50 33
     
51
-main()
34
+#main()

+ 14
- 0
scripts/player.py View File

@@ -0,0 +1,14 @@
1
+import bge
2
+import FSM
3
+
4
+
5
+
6
+def update(cont):
7
+	#print('-------------player updating----------------')
8
+	dict = bge.logic.globalDict
9
+	own = cont.owner
10
+
11
+	if 'playerFSM' not in dict:
12
+		dict['playerFSM'] = FSM.PlayerFSM(own)
13
+
14
+	dict['playerFSM'].Execute()

Loading…
Cancel
Save