shuvit 4 years ago
parent
commit
7cb7baabe8
12 changed files with 1304 additions and 211 deletions
  1. 2
    2
      assets/base_rink.blend
  2. 2
    2
      assets/zamboni.blend
  3. 2
    2
      game.blend
  4. 22
    9
      scripts/FSM.py
  5. 67
    6
      scripts/StatesCamera.py
  6. 149
    11
      scripts/StatesGame.py
  7. 613
    44
      scripts/StatesPlayer.py
  8. 76
    1
      scripts/StatesPuck.py
  9. 13
    3
      scripts/StatesTeam.py
  10. 198
    129
      scripts/player.py
  11. 69
    0
      scripts/puck.py
  12. 91
    2
      scripts/utils.py

+ 2
- 2
assets/base_rink.blend View File

@@ -1,3 +1,3 @@
1 1
 version https://git-lfs.github.com/spec/v1
2
-oid sha256:f4248ca39c2d32c545e75d17fae3b4c730433730931b5e4714aa03297997e3e4
3
-size 881784
2
+oid sha256:e5ee89bd0ef4d7e12cc7f6f286f83dda29c8d146f6e7bb558ab3f169c20ecef6
3
+size 1114940

+ 2
- 2
assets/zamboni.blend View File

@@ -1,3 +1,3 @@
1 1
 version https://git-lfs.github.com/spec/v1
2
-oid sha256:38172e9b08ff66a0ce1e7b33753f961a664c120e36b1cc68b8e251567add0077
3
-size 829356
2
+oid sha256:475a2962e3a863de3174cae6a1ff1c9a38de4eaf11e0e5ad9692ddca766caed9
3
+size 781908

+ 2
- 2
game.blend View File

@@ -1,3 +1,3 @@
1 1
 version https://git-lfs.github.com/spec/v1
2
-oid sha256:434338ac651552de5b165ea2c3931807ac4d9f1db0ad01da7f381f193570384d
3
-size 1681932
2
+oid sha256:00bbcdb5dad019245f500bea698b2e9775a46974507cd58d2151a23d8ea7ce62
3
+size 2096204

+ 22
- 9
scripts/FSM.py View File

@@ -3,6 +3,8 @@ import bge
3 3
 import StatesGame
4 4
 import StatesPlayer
5 5
 import StatesTeam
6
+import StatesCamera
7
+import StatesPuck
6 8
    
7 9
 #====================================
8 10
 class Transition(object):
@@ -66,7 +68,10 @@ class GameFSM(Char):
66 68
         'FaceOff',
67 69
         'FaceoffIntro',
68 70
         'InPlay',
69
-        'GoalScored']
71
+        'GoalScored', 
72
+        'Zamboni',
73
+        'TeamsOnIce', 
74
+        'TeamsOffIce']
70 75
         
71 76
         for s in state_list:
72 77
             self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
@@ -74,7 +79,7 @@ class GameFSM(Char):
74 79
             self.FSM.AddTransition(t, Transition(s))
75 80
         
76 81
         if self.FSM.curState == None:
77
-            self.FSM.SetState('MatchIntro')
82
+            self.FSM.SetState('Zamboni')
78 83
     
79 84
     def Execute(self):
80 85
         self.FSM.Execute(self.owner)    
@@ -138,7 +143,14 @@ class PlayerFSM(Char):
138 143
         'DefendNet',
139 144
         'DefendPursuePuck',
140 145
         'DefendThirdMan',
141
-        'OffencePuck']
146
+        'OffencePuck',
147
+        'Celebrate',
148
+        'Pout', 
149
+        'Benched', 
150
+        'GetOnIce',
151
+        'Hidden', 
152
+        'GetOffIce',
153
+        'ExitBench']
142 154
         
143 155
         for s in state_list:
144 156
             self.FSM.AddState(s, getattr(StatesPlayer, s)(self.FSM))
@@ -146,7 +158,7 @@ class PlayerFSM(Char):
146 158
             self.FSM.AddTransition(t, Transition(s))
147 159
         
148 160
         if self.FSM.curState == None:
149
-            self.FSM.SetState('MatchIntro')
161
+            self.FSM.SetState('Hidden')
150 162
     
151 163
     def Execute(self):
152 164
         self.FSM.Execute(self.owner)    
@@ -161,15 +173,16 @@ class CameraFSM(Char):
161 173
         state_list = [
162 174
         'Example',
163 175
         'Zamboni',
164
-        'GameOn']
176
+        'GameOn',
177
+        'BlackOn']
165 178
         
166 179
         for s in state_list:
167
-            self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
180
+            self.FSM.AddState(s, getattr(StatesCamera, s)(self.FSM))
168 181
             t = 'to' + s
169 182
             self.FSM.AddTransition(t, Transition(s))
170 183
         
171 184
         if self.FSM.curState == None:
172
-            self.FSM.SetState('Example')
185
+            self.FSM.SetState('Zamboni')
173 186
     
174 187
     def Execute(self):
175 188
         self.FSM.Execute(self.owner)    
@@ -188,12 +201,12 @@ class PuckFSM(Char):
188 201
         'NotPossessed']
189 202
         
190 203
         for s in state_list:
191
-            self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
204
+            self.FSM.AddState(s, getattr(StatesPuck, s)(self.FSM))
192 205
             t = 'to' + s
193 206
             self.FSM.AddTransition(t, Transition(s))
194 207
         
195 208
         if self.FSM.curState == None:
196
-            self.FSM.SetState('Example')
209
+            self.FSM.SetState('Invisible')
197 210
     
198 211
     def Execute(self):
199 212
         self.FSM.Execute(self.owner)    

+ 67
- 6
scripts/StatesCamera.py View File

@@ -1,4 +1,5 @@
1 1
 import utils
2
+import bge
2 3
 
3 4
 State = type("State", (object,), {})
4 5
 #====================================     
@@ -41,14 +42,17 @@ class GameOn(State):
41 42
         
42 43
     def Enter(self):
43 44
         self.FSM.stateLife = 1
45
+        o = self.FSM.owner
46
+        g = o.camera
47
+        
48
+        g.playAction('Camera_game', 200,0, layer=1, play_mode=0, speed=1, blendin=0)    
49
+
44 50
         super(GameOn, self).Enter()        
45 51
         
46 52
     def Execute(self):
47 53
         self.FSM.stateLife += 1
48
-        #o = self.FSM.owner
49
-        #g = o.me['game']
50
-        #self.FSM.ToTransition('toNewState')
51
-    
54
+        
55
+
52 56
     def Exit(self):
53 57
         pass
54 58
 
@@ -64,9 +68,66 @@ class Zamboni(State):
64 68
         
65 69
     def Execute(self):
66 70
         self.FSM.stateLife += 1
71
+        o = self.FSM.owner
72
+        g = o.camera
73
+
74
+        if self.FSM.stateLife == 2:
75
+            o.fade = bge.logic.getSceneList()['fade']
76
+            o.fade_obj = o.fade.objects['black']
77
+
78
+
79
+        if self.FSM.stateLife > 2:
80
+            dec = .01
81
+            if o.fade_obj.color[3] > 0:
82
+                o.fade_obj.color[3] -= dec
83
+            if o.fade_obj.color[3] < 0:
84
+                o.fade_obj.color[3] = 0
85
+
86
+        g.playAction('Camera_game', 200,200, layer=1, play_mode=1, speed=1, blendin=0)
67 87
         #o = self.FSM.owner
68
-        #g = o.me['game']
88
+        
89
+        #self.FSM.ToTransition('toNewState')
90
+    
91
+        if o.FSM.FSM.trans:
92
+            self.FSM.ToTransition('toGameOn')
93
+            print('exit intro')
94
+            o.fade_obj.color[3] = 0
95
+
96
+    def Exit(self):
97
+        pass                
98
+
99
+
100
+class BlackOn(State):
101
+    def __init__(self,FSM):
102
+        super(BlackOn, self).__init__(FSM)    
103
+        
104
+    def Enter(self):
105
+        self.FSM.stateLife = 1
106
+        super(BlackOn, self).Enter()        
107
+        
108
+    def Execute(self):
109
+        self.FSM.stateLife += 1
110
+        o = self.FSM.owner
111
+        g = o.camera
112
+
113
+        if self.FSM.stateLife > 2:
114
+            dec = .01
115
+            if o.fade_obj.color[3] < 1:
116
+                o.fade_obj.color[3] += dec
117
+            if o.fade_obj.color[3] > 1:
118
+                o.fade_obj.color[3] = 1
119
+
120
+        #g.playAction('Camera_game', 200,200, layer=1, play_mode=1, speed=1, blendin=0)
121
+        #o = self.FSM.owner
122
+        
69 123
         #self.FSM.ToTransition('toNewState')
70 124
     
125
+        #if o.FSM.FSM.trans:
126
+        print('BlackOn')
127
+        if self.FSM.stateLife == 120:    
128
+            self.FSM.ToTransition('toZamboni')
129
+            print('exit intro')
130
+            o.fade_obj.color[3] = 0
131
+
71 132
     def Exit(self):
72
-        pass                
133
+        pass              

+ 149
- 11
scripts/StatesGame.py View File

@@ -1,3 +1,6 @@
1
+import bge
2
+import utils
3
+
1 4
 State = type("State", (object,), {})
2 5
 
3 6
 class State(object):
@@ -25,7 +28,7 @@ class MatchIntro(State):
25 28
         self.FSM.stateLife += 1
26 29
         o = self.FSM.owner
27 30
     
28
-        if self.FSM.stateLife > 30:
31
+        if self.FSM.stateLife > 60:
29 32
             self.FSM.ToTransition('toFaceoffIntro')
30 33
         #print('intro')
31 34
     def Exit(self):
@@ -44,6 +47,9 @@ class FaceOff(State):
44 47
 
45 48
         g.a_team.FSM.FSM.ToTransition('toFaceoff')
46 49
         g.b_team.FSM.FSM.ToTransition('toFaceoff')
50
+        g.Puck_FSM.FSM.ToTransition('toNotPossessed')
51
+        g.puck.worldPosition = [0,0,1]
52
+        #g.puck.alignAxisToVect([1,0,0], 2, 1)
47 53
         
48 54
     def Execute(self):
49 55
         self.FSM.stateLife += 1
@@ -79,9 +85,15 @@ class FaceoffIntro(State):
79 85
         super(FaceoffIntro, self).Enter()  
80 86
         #push to players
81 87
         g = self.FSM.owner
82
-        
88
+        g.a_door.visible = True
89
+        g.b_door.visible = True
83 90
         for p in (g.b_team.players + g.a_team.players):
91
+            p.user = 0
84 92
             p.FSM.FSM.ToTransition('toFaceoffIntro')      
93
+        if g.a_team.user_input.type != 0:
94
+            g.a_team.players[0].user = 1
95
+        if g.b_team.user_input.type != 0:
96
+            g.b_team.players[0].user = 1                    
85 97
         
86 98
     def Execute(self):
87 99
         self.FSM.stateLife += 1
@@ -113,19 +125,20 @@ class GoalScored(State):
113 125
 
114 126
         if g.a_team.scored == True:
115 127
             g.a_team.scored = False
116
-            self.FSM.ToTransition('toFaceoffIntro')
128
+            #self.FSM.ToTransition('toFaceoffIntro')
117 129
             g.a_team.FSM.FSM.ToTransition('toCelebrate')
118 130
             g.b_team.FSM.FSM.ToTransition('toPout')
119 131
 
120 132
         if g.b_team.scored == True:
121 133
             g.b_team.scored = False
122
-            self.FSM.ToTransition('toFaceoffIntro')
134
+            #self.FSM.ToTransition('toFaceoffIntro')
123 135
             g.b_team.FSM.FSM.ToTransition('toCelebrate')
124 136
             g.a_team.FSM.FSM.ToTransition('toPout')    
125 137
 
126 138
         #print('GOOOOOAAAALLL')
127
-        if self.FSM.stateLife > 340:
139
+        if self.FSM.stateLife > 600:
128 140
             self.FSM.ToTransition('toFaceoffIntro')
141
+            
129 142
         #print('goal')
130 143
     def Exit(self):
131 144
         pass        
@@ -143,11 +156,7 @@ class InPlay(State):
143 156
         g = self.FSM.owner
144 157
         g.clock_time += 1
145 158
         #print('clock_time', self.FSM.owner.clock_time)
146
-
147
-        #if self.FSM.stateLife > 20:
148
-            #self.FSM.ToTransition('toGoalScored')
149
-        #print('inplay')
150
-
159
+        g.score_overlay.update()
151 160
         #update possession
152 161
         ta = False
153 162
         tb = False
@@ -186,4 +195,133 @@ class InPlay(State):
186 195
 
187 196
     def Exit(self):
188 197
         pass      
189
-    
198
+    
199
+
200
+
201
+class Zamboni(State):
202
+    def __init__(self,FSM):
203
+        super(Zamboni, self).__init__(FSM)    
204
+        scene = bge.logic.getCurrentScene()
205
+        self.zam = scene.objects['zamboniEmpty']
206
+        self.zam.worldPosition = [0,0,0]
207
+
208
+    def Enter(self):
209
+        self.FSM.stateLife = 1
210
+        o = self.FSM.owner
211
+        o.goal_a_tubes.visible = False
212
+        o.goal_b_tubes.visible = False
213
+        o.a_door.visible = True
214
+        o.b_door.visible = True
215
+        self.zam.visible = True
216
+        for x in self.zam.children:
217
+            x.visible = True
218
+        o.Cam_FSM.FSM.ToTransition('toZamboni')  
219
+        o.Puck_FSM.FSM.ToTransition('toInvisible')  
220
+        
221
+        super(Zamboni, self).Enter() 
222
+               
223
+        
224
+    def Execute(self):
225
+        self.FSM.stateLife += 1
226
+        o = self.FSM.owner
227
+        
228
+        self.zam.playAction('zamboni2.001', 1,1400, layer=1, play_mode=1, speed=1, blendin=0)
229
+        o.goal_a_tubes.visible = False
230
+        o.goal_b_tubes.visible = False
231
+
232
+
233
+
234
+        #if self.FSM.stateLife > 3600:
235
+            
236
+        if o.a_team.user_input.i_sp == 1:
237
+            self.FSM.ToTransition('toTeamsOnIce')
238
+        #print('intro')
239
+    def Exit(self):
240
+        o = self.FSM.owner
241
+        self.zam.stopAction(1)
242
+        self.zam.visible = False
243
+        for x in self.zam.children:
244
+            x.visible = False
245
+        self.zam.worldPosition = [0,0,-20]
246
+        o.goal_a_tubes.visible = True
247
+        o.goal_b_tubes.visible = True 
248
+
249
+        o.a_team.active_bench = o.a_team.players.copy()
250
+        o.b_team.active_bench = o.b_team.players.copy()   
251
+        pass    
252
+
253
+class TeamsOnIce(State):
254
+    def __init__(self,FSM):
255
+        super(TeamsOnIce, self).__init__(FSM)    
256
+
257
+    def Enter(self):
258
+        self.FSM.stateLife = 1
259
+        o = self.FSM.owner
260
+        ps = o.a_team.players + o.b_team.players
261
+        o.a_door.visible = False
262
+        o.b_door.visible = False
263
+        for p in ps:
264
+            p.FSM.FSM.ToTransition('toExitBench')
265
+
266
+        super(TeamsOnIce, self).Enter() 
267
+               
268
+        
269
+    def Execute(self):
270
+        self.FSM.stateLife += 1
271
+        o = self.FSM.owner
272
+        
273
+
274
+        #print('doing the onice thing')
275
+        if self.FSM.stateLife > 260:
276
+            self.FSM.ToTransition('toMatchIntro')
277
+        #print('intro')
278
+    def Exit(self):  
279
+        pass    
280
+
281
+class TeamsOffIce(State):
282
+    def __init__(self,FSM):
283
+        super(TeamsOffIce, self).__init__(FSM)    
284
+
285
+    def Enter(self):
286
+        self.FSM.stateLife = 1
287
+        o = self.FSM.owner
288
+
289
+        #change player state
290
+        ps = o.a_team.players + o.b_team.players
291
+        for p in ps:
292
+            p.FSM.FSM.ToTransition('toGetOffIce')
293
+
294
+        o.a_door.visible = False
295
+        o.b_door.visible = False
296
+
297
+        o.sound_man.queue_sound(['goal', o.center_ice, o.camera])
298
+        super(TeamsOffIce, self).Enter() 
299
+               
300
+        
301
+    def Execute(self):
302
+        self.FSM.stateLife += 1
303
+        o = self.FSM.owner
304
+        bps = o.a_team_bench + o.b_team_bench
305
+        if self.FSM.stateLife == 280:
306
+            for o in bps:
307
+                pass
308
+                #utils.hide_player(o)
309
+                #o.stick.visible = True
310
+                #o.base.visible = True
311
+                #o.head.visible = True
312
+                #o.body.visible = True
313
+                #o.body.children['stripe'].visible = True 
314
+
315
+        #print('doing the onice thing')
316
+
317
+        if self.FSM.stateLife == 960 - 121:
318
+            o.Cam_FSM.FSM.ToTransition('toBlackOn')
319
+        if self.FSM.stateLife > 960:
320
+            self.FSM.ToTransition('toZamboni')
321
+            print('making the fucking list')
322
+                
323
+
324
+
325
+        #print('intro')
326
+    def Exit(self):  
327
+        pass    

+ 613
- 44
scripts/StatesPlayer.py View File

@@ -1,5 +1,6 @@
1 1
 import utils
2 2
 from mathutils import Vector
3
+import random
3 4
 
4 5
 State = type("State", (object,), {})
5 6
 #====================================     
@@ -68,7 +69,8 @@ class GetPuck(State):
68 69
         if o.orders != None:
69 70
             self.FSM.ToTransition(o.orders)
70 71
 
71
-        if o.team == 1:
72
+        #if o.team == 1:
73
+        if o.user == 0:    
72 74
             self.FSM.ToTransition('toDefendPuck')
73 75
     
74 76
     def Exit(self):
@@ -143,50 +145,56 @@ class PosesPuck(State):
143 145
         self.FSM.stateLife += 1
144 146
 
145 147
         #ai        
146
-        if o.mates.user == 0:
147
-            #print('why are we controlling this')
148
-            if self.FSM.stateLife < 26000:
149
-                g.puck.worldPosition = o.stick_empty.worldPosition
150
-                g.puck.linearVelocity = [0,0,0]  
151
-              
152
-            if self.FSM.stateLife > 26000:
153
-                g.puck.applyForce([1,0,0], True)
154
-                o.puck = False
155
-            if o.checked != None:
156
-                #self.FSM.ToTransition('toDefendPuck') 
157
-                o.mates.possession = False              
158
-                g.puck.worldOrientation = o.puck_empty.worldOrientation
159
-                g.puck.applyForce([50, 0, .5])
160
-                o.puck = False
161
-                self.FSM.ToTransition('toChecked')
148
+        #if o.mates.user == 0:
162 149
 
163 150
 
164
-    
165
-            if self.FSM.stateLife > 3000:
166
-                self.FSM.ToTransition('toDefendPuck') 
167
-                o.mates.possession = False              
168
-                o.puck = False
169
-        #user  
170 151
 
171
-        else:
172
-            #check inputs
173
-            o.update_inputs()    
152
+        #print('why are we controlling this')
153
+        if self.FSM.stateLife < 26000:
174 154
             g.puck.worldPosition = o.stick_empty.worldPosition
175
-            g.puck.linearVelocity = [0,0,0]             
176
-            #print(o.kb_da)             
177
-            #if o.kb_da == 1 and o.last_kb_da == 0:
178
-            if o.mates.user_input.i_da == 1 and o.mates.user_input.i_last_da == 0: 
179
-                #print('--- wind shot')
180
-                self.FSM.ToTransition('toWindShot')    
181
-            #if o.kb_ua == 1 and o.last_kb_ua == 0:
182
-            if o.mates.user_input.i_ua == 1 and o.mates.user_input.i_last_ua == 0:                 
183
-                #print('--- wind dump')
184
-                self.FSM.ToTransition('toWindDump')  
185
-
186
-            if (o.mates.user_input.i_ra == 1 and o.mates.user_input.i_last_ra == 0) or (o.mates.user_input.i_la == 1 and o.mates.user_input.i_last_la == 0): 
187
-                self.FSM.ToTransition('toWindPass')                             
188
-
189
-            o.user_movement()
155
+            g.puck.linearVelocity = [0,0,0]  
156
+          
157
+        if self.FSM.stateLife > 26000:
158
+            g.puck.applyForce([1,0,0], True)
159
+            o.puck = False
160
+        if o.checked != None:
161
+            #self.FSM.ToTransition('toDefendPuck') 
162
+            o.mates.possession = False              
163
+            g.puck.worldOrientation = o.puck_empty.worldOrientation
164
+            g.puck.applyForce([50, 0, .5])
165
+            o.puck = False
166
+            self.FSM.ToTransition('toChecked')
167
+
168
+
169
+
170
+        if self.FSM.stateLife > 300000:
171
+            self.FSM.ToTransition('toDefendPuck') 
172
+            o.mates.possession = False              
173
+            o.puck = False
174
+        #user  
175
+
176
+        #else:
177
+
178
+
179
+
180
+        #check inputs
181
+        o.update_inputs()    
182
+        g.puck.worldPosition = o.stick_empty.worldPosition
183
+        g.puck.linearVelocity = [0,0,0]             
184
+        #print(o.kb_da)             
185
+        #if o.kb_da == 1 and o.last_kb_da == 0:
186
+        if o.mates.user_input.i_da == 1 and o.mates.user_input.i_last_da == 0: 
187
+            #print('--- wind shot')
188
+            self.FSM.ToTransition('toWindShot')    
189
+        #if o.kb_ua == 1 and o.last_kb_ua == 0:
190
+        if o.mates.user_input.i_ua == 1 and o.mates.user_input.i_last_ua == 0:                 
191
+            #print('--- wind dump')
192
+            self.FSM.ToTransition('toWindDump')  
193
+
194
+        if (o.mates.user_input.i_ra == 1 and o.mates.user_input.i_last_ra == 0) or (o.mates.user_input.i_la == 1 and o.mates.user_input.i_last_la == 0): 
195
+            self.FSM.ToTransition('toWindPass')                             
196
+
197
+        o.user_movement()
190 198
 
191 199
         if o.mates.user_input.type == 0:
192 200
             utils.getPlayerOrders(o, g)        
@@ -234,6 +242,17 @@ class DefendPuck(State):
234 242
         if o.orders != None:
235 243
             #print(o.orders)
236 244
             self.FSM.ToTransition(o.orders)
245
+
246
+        if o.user == 1:
247
+            o.update_inputs() 
248
+            if self.FSM.stateLife > 2:
249
+                if o.mates.user_input.i_da == 1 and o.mates.user_input.i_last_da == 0:     
250
+                    o.switch_player()
251
+                    o.puck = False
252
+                    #o.user = 0
253
+                    self.FSM.stateLife = 0
254
+                    #print('fsm switch', o.user)
255
+                o.check_check()            
237 256
         
238 257
     def Exit(self):
239 258
         pass         
@@ -462,6 +481,11 @@ class FaceoffIntro(State):
462 481
         #print(g.FSM.FSM.curState is not g.FSM.FSM.lastState)
463 482
         if g.FSM.FSM.trans:
464 483
             self.FSM.ToTransition('toFaceoff')        
484
+            print('going to faceoff')
485
+
486
+        o.simple_align(.04) 
487
+        utils.whisker_turns(o)
488
+              
465 489
     
466 490
     def Exit(self):
467 491
         pass   
@@ -474,6 +498,8 @@ class Faceoff(State):
474 498
         
475 499
     def Enter(self):
476 500
         self.FSM.stateLife = 1
501
+        o = self.FSM.owner
502
+        o.cont.worldPosition = [o.faceoff_pos[0], o.faceoff_pos[1], o.cont.worldPosition.z]
477 503
         super(Faceoff, self).Enter()        
478 504
         
479 505
     def Execute(self):
@@ -1006,6 +1032,17 @@ class DefendNet(State):
1006 1032
         if o.orders != 'toDefendNet':
1007 1033
             self.FSM.ToTransition('toDefendPuck')
1008 1034
             #print('exiting defend')
1035
+
1036
+        if o.user == 1:
1037
+            o.update_inputs() 
1038
+            if self.FSM.stateLife > 2:
1039
+                if o.mates.user_input.i_da == 1 and o.mates.user_input.i_last_da == 0:     
1040
+                    o.switch_player()
1041
+                    o.puck = False
1042
+                    #o.user = 0
1043
+                    self.FSM.stateLife = 0
1044
+                    #print('fsm switch', o.user)
1045
+                o.check_check()            
1009 1046
     
1010 1047
     def Exit(self):
1011 1048
         pass
@@ -1064,6 +1101,17 @@ class DefendPursuePuck(State):
1064 1101
         if o.orders != 'toDefendPursuePuck':
1065 1102
             self.FSM.ToTransition('toDefendPuck')
1066 1103
             print('exiting pursue')
1104
+
1105
+        if o.user == 1:
1106
+            o.update_inputs() 
1107
+            if self.FSM.stateLife > 2:
1108
+                if o.mates.user_input.i_da == 1 and o.mates.user_input.i_last_da == 0:     
1109
+                    o.switch_player()
1110
+                    o.puck = False
1111
+                    #o.user = 0
1112
+                    self.FSM.stateLife = 0
1113
+                    #print('fsm switch', o.user)
1114
+                o.check_check()            
1067 1115
     
1068 1116
     def Exit(self):
1069 1117
         pass        
@@ -1141,6 +1189,17 @@ class DefendThirdMan(State):
1141 1189
         if o.orders != 'toDefendThirdMan':
1142 1190
             self.FSM.ToTransition('toDefendPuck')
1143 1191
             #print('exiting defend')
1192
+
1193
+        if o.user == 1:
1194
+            o.update_inputs() 
1195
+            if self.FSM.stateLife > 2:
1196
+                if o.mates.user_input.i_da == 1 and o.mates.user_input.i_last_da == 0:     
1197
+                    o.switch_player()
1198
+                    o.puck = False
1199
+                    #o.user = 0
1200
+                    self.FSM.stateLife = 0
1201
+                    #print('fsm switch', o.user)
1202
+                o.check_check()            
1144 1203
     
1145 1204
     def Exit(self):
1146 1205
         pass        
@@ -1194,7 +1253,7 @@ class OffencePuck(State):
1194 1253
             if teammates[0].cont == rc[0]:
1195 1254
                 v = o.cont.getVectTo(teammates[0].cont)
1196 1255
                 o.cont.alignAxisToVect(v[1], 0, .05)
1197
-                print('can pass to this dude')
1256
+                #print('can pass to this dude')
1198 1257
 
1199 1258
         # if g.puck.worldPosition.y > posy:
1200 1259
         #     target.y += 2
@@ -1224,9 +1283,519 @@ class OffencePuck(State):
1224 1283
         utils.check_puck_collision(self, o)
1225 1284
         utils.whisker_turns_goal(o)
1226 1285
 
1227
-        if o.orders != 'toOffencePuck':
1286
+        if (o.orders != 'toOffencePuck' and o.orders != None) or o.puck == 0:
1228 1287
             self.FSM.ToTransition('toDefendPuck')
1229
-            #print('exiting pursue')
1288
+            print('exiting pursue')
1230 1289
     
1231 1290
     def Exit(self):
1232 1291
         pass        
1292
+
1293
+class Celebrate(State):
1294
+    def __init__(self,FSM):
1295
+        super(Celebrate, self).__init__(FSM)    
1296
+        
1297
+    def Enter(self):
1298
+        self.FSM.stateLife = 1
1299
+        super(Celebrate, self).Enter() 
1300
+        o = self.FSM.owner 
1301
+        self.uplen = random.randint(60,90)
1302
+        #self.downlen = random.randint(15,90)
1303
+        o.stick.applyRotation([.4, 0, 0], True)
1304
+        self.dir = 1
1305
+        
1306
+    def Execute(self):
1307
+        self.FSM.stateLife += 1
1308
+        o = self.FSM.owner
1309
+        g = o.me['game']
1310
+        #self.FSM.ToTransition('toNewState')
1311
+        o.update_inputs()
1312
+        utils.update_whiskers(o)
1313
+        length = 5
1314
+        sr = -.3 * 2
1315
+        sm = .4 * 2
1316
+        x = .4
1317
+        print(self.FSM.stateLife % self.uplen, self.dir)
1318
+        #o.simple_align(.04) 
1319
+        if self.FSM.stateLife % self.uplen == 1:
1320
+            print('modding')
1321
+            if self.dir == 0:
1322
+                self.dir = 1
1323
+                self.uplen = random.randint(80,100)
1324
+            elif self.dir == 1:
1325
+                self.dir = 0
1326
+                self.uplen = random.randint(80,100)
1327
+
1328
+        if self.FSM.stateLife < length + 2:
1329
+            sr = sr * (self.FSM.stateLife / (length + 2))
1330
+            sm = sm * (self.FSM.stateLife / (length + 2))
1331
+            #print(sr, sm, 'hittting')  
1332
+
1333
+
1334
+        if self.dir == 0:
1335
+            o.stick.applyRotation([0, sr, 0], True)                    
1336
+            o.stick.applyMovement([sm, 0, 0], True)
1337
+    
1338
+        elif self.dir == 1:
1339
+            o.stick.worldOrientation = o.base.worldOrientation
1340
+        
1341
+        #v = o.base.getVectTo([0,0,0])
1342
+        #o.base.alignAxisToVect(v[1], , .5)
1343
+        #if o.base.worldPosition.x > 3 or o.base.worldPosition.x < -3:
1344
+            #o.kb_w = 1
1345
+        #print('celebrating....')
1346
+
1347
+
1348
+
1349
+        target = Vector([0,0,0])
1350
+        local = o.cont.worldOrientation.inverted() * (o.cont.worldPosition - target) 
1351
+        dist = o.cont.getDistanceTo(target)
1352
+        if dist > 3:
1353
+            if local.x > 0:                
1354
+                o.kb_s = 1
1355
+            else:
1356
+                o.kb_w = 1
1357
+            if local.y > 0:
1358
+                rot = 'right'
1359
+                o.kb_d = 1
1360
+            else:
1361
+                rot = 'left'  
1362
+                o.kb_a = 1
1363
+        else:
1364
+            v = o.cont.getVectTo(target)
1365
+            o.cont.alignAxisToVect(v[1], 0, .05)  
1366
+
1367
+        #utils.whisker_turns(o)    
1368
+        utils.whisker_turns(o)
1369
+            
1370
+
1371
+
1372
+    def Exit(self):
1373
+        pass
1374
+
1375
+
1376
+
1377
+class Pout(State):
1378
+    def __init__(self,FSM):
1379
+        super(Pout, self).__init__(FSM)    
1380
+        
1381
+    def Enter(self):
1382
+        self.FSM.stateLife = 1
1383
+        o = self.FSM.owner
1384
+        super(Pout, self).Enter() 
1385
+        #o = self.FSM.owner 
1386
+        #self.uplen = random.randint(60,90)
1387
+        #self.downlen = random.randint(15,90)
1388
+        #o.stick.applyRotation([.4, 0, 0], True)
1389
+        #self.dir = 1
1390
+        
1391
+    def Execute(self):
1392
+        self.FSM.stateLife += 1
1393
+        o = self.FSM.owner
1394
+        g = o.me['game']
1395
+        print('pouting')
1396
+        #self.FSM.ToTransition('toNewState')
1397
+        o.update_inputs()
1398
+        utils.update_whiskers(o)
1399
+
1400
+
1401
+        if o.team == 0:
1402
+            target = g.a_team_bench_loc
1403
+        else:
1404
+            target = g.b_team_bench_loc
1405
+        #target = Vector([0,0,0])
1406
+        local = o.cont.worldOrientation.inverted() * (o.cont.worldPosition - target) 
1407
+        dist = o.cont.getDistanceTo(target)
1408
+        if dist > 3:
1409
+            if local.x > 0:                
1410
+                o.kb_s = 1
1411
+            else:
1412
+                o.kb_w = 1
1413
+            if local.y > 0:
1414
+                rot = 'right'
1415
+                o.kb_d = 1
1416
+            else:
1417
+                rot = 'left'  
1418
+                o.kb_a = 1
1419
+        else:
1420
+            v = o.cont.getVectTo(target)
1421
+            o.cont.alignAxisToVect(v[1], 0, .05)  
1422
+
1423
+        #utils.whisker_turns(o)  
1424
+        #o.simple_align(.04)   
1425
+        utils.whisker_turns(o)
1426
+        if o.kb_a == 1 and o.kb_d == 1:
1427
+            o.kb_d = 0        
1428
+
1429
+
1430
+    def Exit(self):
1431
+        pass
1432
+
1433
+
1434
+
1435
+
1436
+#====================================             
1437
+class Benched(State):
1438
+    def __init__(self,FSM):
1439
+        super(Benched, self).__init__(FSM)    
1440
+        
1441
+    def Enter(self):
1442
+        self.FSM.stateLife = 1
1443
+        super(Benched, self).Enter()  
1444
+        print('entering bench')      
1445
+        
1446
+    def Execute(self):
1447
+        self.FSM.stateLife += 1
1448
+        o = self.FSM.owner
1449
+        g = o.me['game']
1450
+        # if o.team == 0:
1451
+        #     bps = g.a_team_bench_positions
1452
+        #     team = g.a_team_bench
1453
+        # else:
1454
+        #     bps = g.b_team_bench_positions
1455
+        #     team = g.b_team_bench    
1456
+        # if o in team:    
1457
+        #     ind = team.index(o)
1458
+        #     o.cont.worldPosition = bps[4-ind]        
1459
+        #print('i am benched', self.FSM.owner)
1460
+        #g = o.me['game']
1461
+        #self.FSM.ToTransition('toNewState')
1462
+    
1463
+    def Exit(self):
1464
+        pass
1465
+
1466
+#====================================     
1467
+
1468
+
1469
+#====================================             
1470
+        
1471
+class GetOnIce(State):
1472
+    def __init__(self,FSM):
1473
+        super(GetOnIce, self).__init__(FSM)    
1474
+        
1475
+    def Enter(self):
1476
+        self.FSM.stateLife = 1
1477
+        o = self.FSM.owner
1478
+        
1479
+        o.cont.linearVelocity = [0, 0, 0]
1480
+        super(GetOnIce, self).Enter()        
1481
+        
1482
+    def Execute(self):
1483
+        self.FSM.stateLife += 1
1484
+        o = self.FSM.owner
1485
+        g = o.me['game']
1486
+        # if o.team == 0:
1487
+        #     team = g.a_team
1488
+        #     bpos = g.a_team_bench_positions
1489
+        # else:
1490
+        #     team = g.b_team
1491
+        #     bpos = g.b_team_bench_positions    
1492
+        #fix jumping
1493
+        if self.FSM.stateLife == 2 or self.FSM.stateLife == 3:
1494
+            o.cont.linearVelocity = [0, 0, 0]
1495
+            o.cont.worldPosition.z = .1275
1496
+        #get the index of the player from o.mates.players
1497
+        # player_id = o.mates.players.index(o)
1498
+        # if player_id == 0:
1499
+        #     start_time = 3
1500
+        # else:
1501
+        #     start_time = player_id * 120
1502
+
1503
+        # if start_time == self.FSM.stateLife:
1504
+        #     #utils.show_player(o)
1505
+        #     o.cont.linearVelocity = [0, 0, 0]
1506
+
1507
+        #     #if o.team == 0:
1508
+        #         #x = -3
1509
+        #     #else:
1510
+        #        # x = 3
1511
+
1512
+        #     #y = -6#(player_id * 3) - 5
1513
+        #     #o.cont.worldPosition = [x, y, 3]
1514
+        #     #pos = bpos[0].copy()
1515
+        #     #pos.y += 2
1516
+        #     #o.cont.worldPosition = pos
1517
+            
1518
+        #     o.cont.alignAxisToVect([0,1,0], 0, 1)        
1519
+
1520
+        #if self.FSM.stateLife - start_time > 120:
1521
+        if 1 == 1:    
1522
+            o.cont.worldPosition.z = .1275
1523
+            o.kb_w = 1
1524
+            #o.cont.restorePhysics()
1525
+            ch = random.choice([True, False, False, False, False])
1526
+            if ch:
1527
+                if o.team == 0:
1528
+                    o.kb_a = 1
1529
+                if o.team == 1:
1530
+                    o.kb_d = 1
1531
+
1532
+        if g.FSM.FSM.trans:
1533
+            self.FSM.ToTransition('toMatchIntro')
1534
+            print('exit intro')
1535
+    
1536
+    def Exit(self):
1537
+        pass   
1538
+    
1539
+#====================================             
1540
+        
1541
+class Hidden(State):
1542
+    def __init__(self,FSM):
1543
+        super(Hidden, self).__init__(FSM)    
1544
+        
1545
+    def Enter(self):
1546
+        self.FSM.stateLife = 1
1547
+        #o.cont.worldPosition = [-0, 0, -10]  
1548
+        o = self.FSM.owner
1549
+        #o.stick.visible = False
1550
+        #o.base.visible = False
1551
+        #print('setting base')
1552
+        #o.stick.color = [1,0,0,1]
1553
+        #o.cont.suspendPhysics()
1554
+        #for x in o.children:
1555
+            #x.visible = False
1556
+
1557
+        super(Hidden, self).Enter()        
1558
+        
1559
+
1560
+
1561
+
1562
+    def Execute(self):
1563
+        o = self.FSM.owner
1564
+        g = o.me['game']
1565
+
1566
+        self.FSM.stateLife += 1
1567
+        if self.FSM.stateLife > 1:
1568
+            #utils.hide_player(o)
1569
+            #o.stick.visible = False
1570
+            #o.base.visible = False
1571
+            #o.head.visible = False
1572
+            #o.body.visible = False
1573
+            #o.indicator_obj.visible = False
1574
+            #o.body.children['stripe'].visible = False
1575
+            #print('setting base')
1576
+
1577
+            #get bench positions list
1578
+            if o.team == 0:
1579
+                bps = g.a_team_bench_positions
1580
+                team = g.a_team
1581
+            else:
1582
+                bps = g.b_team_bench_positions
1583
+                team = g.b_team
1584
+            #o.players.index(o)    
1585
+            o.cont.worldPosition = bps[team.players.index(o)]
1586
+            #print('doing wp')
1587
+
1588
+            o.cont.alignAxisToVect([0,1,0], 0, 1)
1589
+            o.align_to_base()
1590
+        if g.FSM.FSM.trans:
1591
+            self.FSM.ToTransition('toGetOnIce')
1592
+        
1593
+    def Exit(self):
1594
+        pass   
1595
+
1596
+class GetOffIce(State):
1597
+    def __init__(self,FSM):
1598
+        super(GetOffIce, self).__init__(FSM)    
1599
+        
1600
+    def Enter(self):
1601
+        self.FSM.stateLife = 1
1602
+        super(GetOffIce, self).Enter()        
1603
+        
1604
+    def Execute(self):
1605
+        self.FSM.stateLife += 1
1606
+        o = self.FSM.owner
1607
+        g = o.me['game']
1608
+        utils.update_whiskers(o)
1609
+        exit = False
1610
+        player_id = o.mates.players.index(o)
1611
+
1612
+
1613
+
1614
+        dist = 5000
1615
+        if self.FSM.stateLife > 160:
1616
+            if o.team == 0:
1617
+                target = g.a_team_bench_loc
1618
+            else:
1619
+                target = g.b_team_bench_loc
1620
+            
1621
+            local = o.cont.worldOrientation.inverted() * (o.cont.worldPosition - target) 
1622
+            dist = o.cont.getDistanceTo(target)
1623
+            if dist > 1.75:
1624
+                if local.x > 0:                
1625
+                    o.kb_s = 1
1626
+                else:
1627
+                    o.kb_w = 1
1628
+                if local.y > 0:
1629
+                    rot = 'right'
1630
+                    o.kb_d = 1
1631
+                else:
1632
+                    rot = 'left'  
1633
+                    o.kb_a = 1
1634
+            else: 
1635
+                exit = True
1636
+
1637
+            #utils.check_puck_collision(self, o)
1638
+            utils.whisker_turns_goal(o)
1639
+            utils.whisker_turns(o)
1640
+            if o.kb_a == 0 and o.kb_d == 0 and o.kb_s == 0 and o.kb_w == 0:
1641
+                #print('force align')
1642
+                v = o.cont.getVectTo(target)
1643
+                o.cont.alignAxisToVect(v[1], 0, .9) 
1644
+
1645
+        l = len(o.mates.active_bench)
1646
+        if (self.FSM.stateLife % 60) == 1:
1647
+            if l == 0:
1648
+                if dist < 1.95:
1649
+                    print('remove this guy', self)
1650
+                    o.mates.active_bench.append(self)
1651
+                    if o.team == 0:
1652
+                        bps = g.a_team_bench_positions
1653
+                    else:
1654
+                        bps = g.b_team_bench_positions 
1655
+                    o.cont.worldPosition = bps[2]
1656
+                    exit = True
1657
+                    
1658
+            elif l == 1:
1659
+                if dist < 1.95:
1660
+                    print('remove this guy', self)
1661
+                    o.mates.active_bench.append(self)
1662
+                    if o.team == 0:
1663
+                        bps = g.a_team_bench_positions
1664
+                    else:
1665
+                        bps = g.b_team_bench_positions 
1666
+                    o.cont.worldPosition = bps[1]
1667
+                    exit = True
1668
+                    
1669
+            elif l == 2:
1670
+                if dist < 1.95:
1671
+                    print('remove this guy', self)
1672
+                    o.mates.active_bench.append(self)
1673
+                    if o.team == 0:
1674
+                        bps = g.a_team_bench_positions
1675
+                    else:
1676
+                        bps = g.b_team_bench_positions 
1677
+                    o.cont.worldPosition = bps[0]
1678
+                    exit = True
1679
+                    
1680
+
1681
+        o.simple_align(.04)                                   
1682
+        if exit:
1683
+            o.cont.suspendPhysics()
1684
+            o.cont.suspendDynamics()
1685
+            self.FSM.ToTransition('toHidden')
1686
+            o.cont.alignAxisToVect([0,1,0], 0, 1)
1687
+            print('------ doing the exit')
1688
+
1689
+        if g.FSM.FSM.trans:
1690
+            self.FSM.ToTransition('toHidden')
1691
+            print('exit intro')
1692
+    
1693
+    def Exit(self):
1694
+        pass   
1695
+
1696
+class ExitBench(State):
1697
+    def __init__(self,FSM):
1698
+        self.curTime = 0
1699
+        self.og_pos = None
1700
+        super(ExitBench, self).__init__(FSM)    
1701
+        
1702
+    def Enter(self):
1703
+        self.FSM.stateLife = 1
1704
+        o = self.FSM.owner
1705
+        o.cont.suspendDynamics()
1706
+        self.curTime = 0
1707
+        super(ExitBench, self).Enter()        
1708
+        
1709
+    def Execute(self):
1710
+        self.FSM.stateLife += 1
1711
+        o = self.FSM.owner
1712
+        g = o.me['game']
1713
+        #print('exit bench')
1714
+
1715
+        if o.team == 0:
1716
+            bps = g.a_team_bench_positions.copy()
1717
+            team = g.a_team
1718
+        else:
1719
+            bps = g.b_team_bench_positions.copy()
1720
+            team = g.b_team
1721
+        #team.reverse()  
1722
+        b =  o.mates.active_bench.copy()
1723
+        #b.reverse()
1724
+        #print(bps[0])
1725
+        if o == b[0]:
1726
+            pos = bps[0].copy()
1727
+            pos = o.cont.worldPosition.copy()
1728
+            pos.y += .05
1729
+            #o.cont.worldPosition = pos
1730
+            o.cont.worldPosition.y += .05
1731
+
1732
+            if self.curTime > 100:
1733
+                self.curTime = 0
1734
+                
1735
+                o.mates.active_bench.remove(o)
1736
+                o.cont.restoreDynamics()
1737
+                o.cont.restorePhysics()
1738
+                o.cont.worldPosition.z = .1275
1739
+                self.og_pos = None
1740
+                self.FSM.ToTransition('toGetOnIce')
1741
+            self.curTime += 1
1742
+        elif o == b[1]:
1743
+            if self.og_pos == None:
1744
+                self.og_pos = o.cont.worldPosition.copy()
1745
+                self.cur_time = 0
1746
+                #o.cont.worldPosition = bps[1].copy()
1747
+            l1 = bps[1].copy()
1748
+            pos = l1.lerp(bps[0], (self.cur_time * .01))
1749
+            o.cont.worldPosition = pos
1750
+            self.cur_time += 1
1751
+        
1752
+            if self.cur_time == 102:
1753
+                    self.og_pos = None
1754
+                    self.cur_time = 0    
1755
+
1756
+
1757
+        elif o == b[2]:
1758
+            if self.og_pos == None:
1759
+                self.og_pos = o.cont.worldPosition.copy()
1760
+                self.cur_time = 0
1761
+                #o.cont.worldPosition = bps[2].copy()
1762
+            l1 = bps[2].copy()
1763
+            pos = l1.lerp(bps[1], (self.cur_time * .01))
1764
+            o.cont.worldPosition = pos
1765
+            self.cur_time += 1
1766
+            if self.cur_time == 102:
1767
+                self.og_pos = None
1768
+                self.cur_time = 0    
1769
+
1770
+        #if g.FSM.FSM.trans:
1771
+            #utils.hide_player(o)
1772
+            #self.FSM.ToTransition('toGetOnIce')
1773
+            #print('exit intro')
1774
+    
1775
+    def Exit(self):
1776
+        pass           
1777
+
1778
+
1779
+class EnterBench(State):
1780
+    def __init__(self,FSM):
1781
+        self.curTime = 0
1782
+        self.og_pos = None
1783
+        super(EnterBench, self).__init__(FSM)    
1784
+        
1785
+    def Enter(self):
1786
+        self.FSM.stateLife = 1
1787
+        o = self.FSM.owner
1788
+        #o.cont.suspendDynamics()
1789
+        self.curTime = 0
1790
+        super(EnterBench, self).Enter()        
1791
+        
1792
+    def Execute(self):
1793
+        self.FSM.stateLife += 1
1794
+        o = self.FSM.owner
1795
+        g = o.me['game']
1796
+        l = len(o.mates.active_bench)
1797
+
1798
+
1799
+
1800
+    def Exit(self):
1801
+        pass                   

+ 76
- 1
scripts/StatesPuck.py View File

@@ -15,6 +15,7 @@ class State(object):
15 15
     def Exit(self):
16 16
         print('Exiting')
17 17
 #====================================             
18
+
18 19
 class Example(State):
19 20
     def __init__(self,FSM):
20 21
         super(Example, self).__init__(FSM)    
@@ -30,4 +31,78 @@ class Example(State):
30 31
         #self.FSM.ToTransition('toNewState')
31 32
     
32 33
     def Exit(self):
33
-        pass
34
+        pass
35
+
36
+#====================================             
37
+
38
+class Possessed(State):
39
+    def __init__(self,FSM):
40
+        super(Possessed, self).__init__(FSM)    
41
+        
42
+    def Enter(self):
43
+        self.FSM.stateLife = 1
44
+        super(Possessed, self).Enter()        
45
+        
46
+    def Execute(self):
47
+        self.FSM.stateLife += 1
48
+        #o = self.FSM.owner
49
+        #g = o.me['game']
50
+        #utils.puck()
51
+        #self.FSM.ToTransition('toNewState')
52
+    
53
+    def Exit(self):
54
+        pass
55
+
56
+#====================================             
57
+
58
+class NotPossessed(State):
59
+    def __init__(self,FSM):
60
+        super(NotPossessed, self).__init__(FSM)    
61
+        
62
+    def Enter(self):
63
+        self.FSM.stateLife = 1
64
+
65
+        p = self.FSM.owner
66
+        #p = p['game']
67
+        p.puck.visible = True
68
+        p.puck_update = True        
69
+        super(NotPossessed, self).Enter()        
70
+        
71
+    def Execute(self):
72
+        self.FSM.stateLife += 1
73
+        p = self.FSM.owner.puck
74
+        utils.puck_wall(p)
75
+        #print('----------not Possessed')
76
+        #o = self.FSM.owner
77
+        #g = o.me['game']
78
+        #self.FSM.ToTransition('toNewState')
79
+    
80
+    def Exit(self):
81
+        pass                
82
+
83
+#====================================             
84
+
85
+class Invisible(State):
86
+    def __init__(self,FSM):
87
+        super(Invisible, self).__init__(FSM)    
88
+        
89
+    def Enter(self):
90
+        self.FSM.stateLife = 1
91
+        p = self.FSM.owner
92
+        #g = p['game']
93
+        p.puck_update = False
94
+        p.puck.visible = False
95
+        super(Invisible, self).Enter()        
96
+        
97
+    def Execute(self):
98
+        self.FSM.stateLife += 1
99
+        p = self.FSM.owner.puck
100
+        p.worldPosition = [0,0,10]
101
+        #print('invisible puck')
102
+        #o = self.FSM.owner
103
+        #g = o.me['game']
104
+        #self.FSM.ToTransition('toNewState')
105
+    
106
+    def Exit(self):
107
+        pass                
108
+

+ 13
- 3
scripts/StatesTeam.py View File

@@ -60,6 +60,9 @@ class Pout(State):
60 60
         
61 61
     def Enter(self):
62 62
         self.FSM.stateLife = 1
63
+        o = self.FSM.owner
64
+        for t in o.players:
65
+            t.FSM.FSM.ToTransition('toPout') 
63 66
         super(Pout, self).Enter()        
64 67
         
65 68
     def Execute(self):
@@ -78,14 +81,17 @@ class Celebrate(State):
78 81
         
79 82
     def Enter(self):
80 83
         self.FSM.stateLife = 1
81
-        super(Celebrate, self).Enter()        
84
+        super(Celebrate, self).Enter()
85
+        o = self.FSM.owner
86
+        for t in o.players:
87
+            t.FSM.FSM.ToTransition('toCelebrate')        
82 88
         
83 89
     def Execute(self):
84 90
         self.FSM.stateLife += 1
85 91
         o = self.FSM.owner
86 92
         #g = o.me['game']
87 93
         #self.FSM.ToTransition('toNewState')
88
-        print('PARTY __')
94
+        #print('PARTY __')
89 95
     def Exit(self):
90 96
         pass
91 97
 
@@ -145,7 +151,9 @@ class Defense(State):
145 151
         
146 152
     def Enter(self):
147 153
         self.FSM.stateLife = 1
148
-        super(Defense, self).Enter()        
154
+        super(Defense, self).Enter() 
155
+        t = self.FSM.owner
156
+        t.possession = 0       
149 157
         
150 158
     def Execute(self):
151 159
         self.FSM.stateLife += 1
@@ -160,6 +168,8 @@ class Offence(State):
160 168
         
161 169
     def Enter(self):
162 170
         self.FSM.stateLife = 1
171
+        t = self.FSM.owner
172
+        t.possession = 1
163 173
         super(Offence, self).Enter()        
164 174
         
165 175
     def Execute(self):

+ 198
- 129
scripts/player.py View File

@@ -11,9 +11,6 @@ team_b_colors = [[.1,.9,.1,1], [.1,.1,.1,1], [.3, .3, .3, 1]]
11 11
 #team_a_colors = [[.7,.7,.3,1], [.9,.1,.1,1], [.1, .1, .1, 1]]           
12 12
 #team_b_colors = [[.1,.3,.9,1], [.4,.1,.1,1], [.3, .3, .3, 1]]
13 13
 import datetime
14
-#from datetime import datetime, timedelta
15
-#sec = timedelta(seconds=(input('Enter the number of seconds: ')))
16
-#time = str(sec)
17 14
 
18 15
 
19 16
 positions = [[3,0], [4,-3], [6, 3], [8, -4]]
@@ -29,7 +26,6 @@ def run_camera(self):
29 26
         cpos = self.camera.worldPosition.x
30 27
         dist = cpos - opos
31 28
         num = abs(dist - target_dist)
32
-        #print(opos + 10)
33 29
         if opos > - 3 and opos < 6:
34 30
             self.camera.worldPosition.x = opos + 10
35 31
 
@@ -37,21 +33,31 @@ class ScoreOverlay:
37 33
     def __init__(self, game):
38 34
         self.game = game
39 35
         self.life = 0
40
-        self.scene = bge.logic.addScene('ScoreOverlay')
36
+        self.scene = None
41 37
         
42 38
 
43 39
     def update(self):
44
-        if self.life == 1:
40
+
41
+        if self.scene == None:
42
+            self.scene = bge.logic.addScene('ScoreOverlay')
43
+        if self.life == 2:
45 44
             self.scene = bge.logic.getSceneList()['ScoreOverlay']
46 45
             txt_objs = ['score_a', 'score_b', 'home_title', 'away_title', 'time']
47 46
             for x in txt_objs:
48 47
                 self.scene.objects[x].resolution = 24
49
-        elif self.life > 1:
48
+        elif self.life > 2:
50 49
         #if self.game.score is not None:str(number).zfill(2)
51 50
             self.scene.objects['score_a'].text = str(self.game.score[0]).zfill(2)
52 51
             self.scene.objects['score_b'].text = str(self.game.score[1]).zfill(2)
53
-        
54
-            sec = datetime.timedelta(seconds=self.game.clock_time)
52
+            t = self.game.period_length - self.game.clock_time
53
+            #sec = datetime.timedelta(seconds=self.game.clock_time)
54
+            if t == 0:
55
+                self.game.period += 1
56
+                self.game.clock_time = 0
57
+                #self.game.FSM.FSM.ToTransition('toMatchIntro')
58
+                self.game.FSM.FSM.ToTransition('toTeamsOffIce')
59
+
60
+            sec = datetime.timedelta(seconds=t)
55 61
             sec = '0' + str(sec)[:-3]
56 62
             if len(sec) > 5:
57 63
                 sec = sec[1:]
@@ -196,7 +202,6 @@ class keyboard_input(user_input):
196 202
 
197 203
         keyboard = bge.logic.keyboard.inputs  
198 204
         
199
-
200 205
         self.i_ua = bge.logic.keyboard.inputs[bge.events.UPARROWKEY].values[-1]
201 206
         self.i_da = bge.logic.keyboard.inputs[bge.events.DOWNARROWKEY].values[-1]    
202 207
         self.i_la = bge.logic.keyboard.inputs[bge.events.LEFTARROWKEY].values[-1]
@@ -235,7 +240,6 @@ class joystick_input(user_input):
235 240
 
236 241
     def update(self):    
237 242
         if bge.logic.joysticks[self.stick]:
238
-            #print(bge.logic.joysticks[self.stick].activeButtons)
239 243
             sens = .4
240 244
             sens2 = .6
241 245
             if 0 in bge.logic.joysticks[self.stick].activeButtons:
@@ -249,7 +253,6 @@ class joystick_input(user_input):
249 253
             if 10 in bge.logic.joysticks[self.stick].activeButtons:
250 254
                 self.i_ls = 1
251 255
 
252
-
253 256
             if bge.logic.joysticks[self.stick].axisValues[0] < -sens2:
254 257
                 self.i_a = 1
255 258
             if bge.logic.joysticks[self.stick].axisValues[1] < -sens:
@@ -258,19 +261,7 @@ class joystick_input(user_input):
258 261
                 self.i_d = 1
259 262
             if bge.logic.joysticks[self.stick].axisValues[1] > sens:
260 263
                 self.i_s = 1                        
261
-            #print(bge.logic.joysticks[0].axisValues[2])    
262
-            # self.i_ua = bge.logic.keyboard.inputs[bge.events.UPARROWKEY].values[-1]
263
-            # self.i_da = bge.logic.keyboard.inputs[bge.events.DOWNARROWKEY].values[-1]    
264
-            # self.i_la = bge.logic.keyboard.inputs[bge.events.LEFTARROWKEY].values[-1]
265
-            # self.i_ra = bge.logic.keyboard.inputs[bge.events.RIGHTARROWKEY].values[-1]
266
-            # self.i_w = bge.logic.keyboard.inputs[bge.events.WKEY].values[-1]
267
-            # self.i_a = bge.logic.keyboard.inputs[bge.events.AKEY].values[-1]    
268
-            # self.i_s = bge.logic.keyboard.inputs[bge.events.SKEY].values[-1]
269
-            # self.i_d = bge.logic.keyboard.inputs[bge.events.DKEY].values[-1]  
270
-            # self.i_ls = bge.logic.keyboard.inputs[bge.events.LEFTSHIFTKEY].values[-1]    
271
-            # self.i_sp = bge.logic.keyboard.inputs[bge.events.SPACEKEY].values[-1]         
272
-
273
-            #inputs.JoystickButton(joystickIndex, buttonIndex)            
264
+           
274 265
 class team:
275 266
     def __init__(self, name, colors, user, game):
276 267
         self.name = name
@@ -286,31 +277,23 @@ class team:
286 277
         self.user_input = None
287 278
         self.FSM = FSM.TeamFSM(self)
288 279
         self.own_net = None
280
+        self.bench = []
281
+        self.active_bench = []
289 282
         
290 283
     def update(self, game):
291 284
         
292 285
         def sortClosestToPuck(e):
293 286
             return e.cont.getDistanceTo(game.puck.worldPosition)
294 287
         self.puck_closest.sort(reverse=False, key=sortClosestToPuck)
295
-        
296
-
297
-        # def sortClosestToGoal(e):
298
-        #     print('doing goal closest')
299
-        #     return e.cont.getDistanceTo(self.own_net.worldPosition)
300
-        # self.net_closest.sort(reverse=False, key=sortClosestToGoal)
301
-        
302
-
303 288
 
304 289
         self.FSM.Execute()
305
-        #print(self.FSM.FSM.curState.__class__.__name__, self.name)
306
-#self.FSM.FSM.curState.__class__.__name__ != 'PosesPuck':
290
+
307 291
         if self.name == 'b':
308 292
             a_list = []
309 293
             for x in self.players:
310
-                #a_list.append(x.puck)
311 294
                 a_list.append(x.FSM.FSM.curState.__class__)
312 295
             #print(a_list)
313
-        
296
+        #print(self.possession)
314 297
 class game:
315 298
     def __init__(self, obj, cont):
316 299
         self.scene = bge.logic.getCurrentScene()
@@ -329,6 +312,9 @@ class game:
329 312
         self.puck_update = False
330 313
         self.goal_a_e = self.scene.objects['goal_a_e']
331 314
         self.goal_b_e = self.scene.objects['goal_b_e']
315
+        self.goal_a_tubes = self.scene.objects['goal_a_tubes']
316
+        self.goal_b_tubes = self.scene.objects['goal_b_tubes']
317
+
332 318
         self.sound_man = sound_man.sound_manager()
333 319
         self.num_p_a = 3
334 320
         self.num_p_b = 3
@@ -341,15 +327,43 @@ class game:
341 327
         #team properties: name, colors, user
342 328
         self.a_team = team('a', team_a_colors, 1, self)
343 329
         self.b_team = team('b', team_b_colors, 0, self)
344
-        #self.a_team.user_input = keyboard_input(1)
345
-        self.a_team.user_input = joystick_input(2, 0)
330
+        self.a_team_bench = []
331
+        self.b_team_bench = []
332
+        self.a_team_bench_loc = mathutils.Vector([-1.5, -7, 0])
333
+        self.b_team_bench_loc = mathutils.Vector([1.5, -7, 0])
334
+        self.a_door = self.scene.objects['a_door']
335
+        self.b_door = self.scene.objects['b_door']
336
+        
337
+        self.a_team_bench_positions = [mathutils.Vector([-1.5, -8.4, .1275]),
338
+                                       mathutils.Vector([-2.6, -8.4, .1275]),
339
+                                       mathutils.Vector([-3.7, -8.4, .1275]),
340
+                                       mathutils.Vector([-4.7, -8.4, .1275]),
341
+                                       mathutils.Vector([-5.7, -8.4, .1275])]
342
+
343
+        self.b_team_bench_positions = [mathutils.Vector([1.5, -8.4, .1275]),
344
+                                       mathutils.Vector([2.6, -8.4, .1275]),
345
+                                       mathutils.Vector([3.7, -8.4, .1275]),
346
+                                       mathutils.Vector([4.7, -8.4, .1275]),
347
+                                       mathutils.Vector([5.7, -8.4, .1275])]
348
+
349
+        self.a_team.user_input = keyboard_input(1)
350
+        #self.a_team.user_input = cpu_input(0)
351
+        #self.b_team.user_input = keyboard_input(1)
352
+        #self.a_team.user_input = joystick_input(2, 0)
346 353
         #self.b_team.user_input = joystick_input(3, 1)
347 354
         self.b_team.user_input = cpu_input(0)
355
+        self.period_length = 7 * 60#2 * 60 * 60
356
+        self.period = 1
348 357
 
349 358
         self.a_team.own_net = self.goal_b_e
350 359
         self.b_team.own_net = self.goal_a_e
351 360
         
352 361
         self.FSM = FSM.GameFSM(self) 
362
+        self.Cam_FSM = FSM.CameraFSM(self)
363
+        #print(bge.logic.getSceneList())
364
+        self.fade = None
365
+        self.fade_obj = None
366
+        self.Puck_FSM = None
353 367
     
354 368
     def load_players(self):
355 369
         #do team a
@@ -357,7 +371,7 @@ class game:
357 371
             iter = self.num_p_a
358 372
             while iter > 0:
359 373
                 
360
-                p1 = hockey_player(0, self.obj, self.cont)
374
+                p1 = hockey_player(0, self.obj, self.cont, False)
361 375
                 p1.user = 0
362 376
                 pname = 'p' + str(iter)
363 377
                 aname = 'a' + str(iter)
@@ -369,21 +383,52 @@ class game:
369 383
                 self.team_a.append(p1)
370 384
                 self.players.append(p1)
371 385
                 self.a_team.players.insert(0, p1)
372
-
373 386
                 x = positions[iter -1][0] * -1
374 387
                 y = positions[iter -1][1] * -1 
375 388
                 p1.faceoff_pos = [x,y]               
376 389
 
377 390
                 p1.cont.worldPosition = [x, y, p1.cont.worldPosition.z]
378
-                
391
+                p1.cont.suspendDynamics(True)
392
+                #p1.mates.active_bench.append(p1)
393
+                  
394
+
379 395
                 iter -= 1
380 396
             self.a_team.puck_closest = self.a_team.players.copy()    
397
+            iter = 2
398
+            while iter > 0:
399
+                
400
+                    #put on bench
401
+                p1 = hockey_player(0, self.obj, self.cont, True)
402
+                p1.user = 0
403
+                pname = 'p' + str(iter)
404
+                aname = 'a' + str(iter)
405
+                p1.cont['name'] = aname
406
+                p1.stick['name'] = aname
407
+                p1.cont['pname'] = True
408
+                p1.stick['pname'] = True 
409
+                p1.cont['c_ref'] = p1 
410
+                self.a_team_bench.append(p1)
411
+                p1.team = None
412
+                #self.players.append(p1)
413
+                #self.a_team.players.insert(0, p1)
414
+                if iter == 2:
415
+                    #p1.cont.worldPosition = [-1.5, -8.3, p1.cont.worldPosition.z+1]
416
+                    p1.cont.worldPosition = self.a_team_bench_positions[3]
417
+                if iter == 1:
418
+                    #put on bench
419
+                    #p1.cont.worldPosition = [-3, -8.3, p1.cont.worldPosition.z+1]
420
+                    p1.cont.worldPosition = self.a_team_bench_positions[4]
421
+                p1.cont.suspendDynamics(True)  
422
+                p1.cont.applyRotation([0,0,(math.pi/4)], True)
423
+                print('bench player', iter)   
424
+                p1.FSM.FSM.ToTransition('toBenched') 
425
+                iter -= 1
381 426
         #do team b
382 427
         if self.num_p_b > 0:
383 428
             iter = self.num_p_b
384 429
             while iter > 0:
385 430
                 
386
-                p1 = hockey_player(1, self.obj, self.cont)
431
+                p1 = hockey_player(1, self.obj, self.cont, False)
387 432
                 p1.user = 0
388 433
                 pname = 'p' + str(iter)
389 434
                 aname = 'b' + str(iter)
@@ -399,15 +444,44 @@ class game:
399 444
                 y = positions[iter -1][1]
400 445
                 p1.faceoff_pos = [x,y] 
401 446
                 p1.cont.worldPosition = [x, y, p1.cont.worldPosition.z]
447
+                p1.cont.suspendDynamics(True)
448
+                #p1.mates.active_bench.append(p1)
402 449
                 iter -= 1                
403 450
             self.b_team.puck_closest = self.b_team.players.copy()  
404
-            
451
+            iter = 2
452
+            while iter > 0:
405 453
                 
454
+                    #put on bench
455
+                p1 = hockey_player(1, self.obj, self.cont, True)
456
+                p1.user = 0
457
+                pname = 'p' + str(iter)
458
+                aname = 'a' + str(iter)
459
+                p1.cont['name'] = aname
460
+                p1.stick['name'] = aname
461
+                p1.cont['pname'] = True
462
+                p1.stick['pname'] = True 
463
+                p1.cont['c_ref'] = p1 
464
+                self.b_team_bench.append(p1)
465
+                p1.team = None
466
+                #self.players.append(p1)
467
+                #self.a_team.players.insert(0, p1)
468
+                if iter == 2:
469
+                    #p1.cont.worldPosition = [1.5, -8.3, p1.cont.worldPosition.z+1]
470
+                    p1.cont.worldPosition = self.b_team_bench_positions[3]
471
+                if iter == 1:
472
+                    #put on benchtoBench
473
+                    #p1.cont.worldPosition = [3, -8.3, p1.cont.worldPosition.z+1]
474
+                    p1.cont.worldPosition = self.b_team_bench_positions[4]
475
+                p1.cont.suspendDynamics(True)  
476
+                p1.cont.applyRotation([0,0,(math.pi/4)], True)
477
+                print('bench player', iter)   
478
+                p1.FSM.FSM.ToTransition('toBenched') 
479
+                iter -= 1
406 480
     def load_puck(self):
407
-        #scene = bge.logic.getCurrentScene()
408 481
         o = self.scene.objectsInactive['puck']
409 482
         self.puck = self.scene.addObject(o, self.obj, 0) 
410 483
         self.puck['game'] = self
484
+        self.Puck_FSM = FSM.PuckFSM(self)
411 485
         
412 486
     def run(self):
413 487
         #pass    
@@ -430,14 +504,17 @@ class game:
430 504
         for t in self.team_a + self.team_b:
431 505
             t.update()
432 506
                  
433
-        p = []
434
-        for x in self.team_a:
435
-            p.append(x.state)
436
-        #print(p)
507
+        for t in self.a_team_bench + self.b_team_bench:
508
+            t.update()         
509
+        # p = []
510
+        # for x in self.team_b:
511
+        #     p.append(x.state)
512
+        # print(p)
437 513
                     
438 514
         self.FSM.Execute() 
515
+        self.Cam_FSM.Execute()
439 516
         self.sound_man.update() 
440
-        self.score_overlay.update()
517
+        #self.score_overlay.update()
441 518
         #print(self.team_a_user_input.i_w)
442 519
         #print(self.team_b_user_input.i_da)
443 520
         
@@ -446,12 +523,13 @@ class game:
446 523
 
447 524
         # l = []
448 525
         # for x in self.a_team.players:
449
-        #     l.append(x.orders)
450
-        #     #l.append(x.FSM.FSM.curState)
526
+        #     #l.append(x.orders)
527
+        #     l.append([x.FSM.FSM.curState, x.user, x.puck])
451 528
         # print(l, 'orders')
529
+        #print(self.a_team.possession, self.a_team.FSM.FSM.curState.__class__.__name__ )
452 530
 
453 531
 class hockey_player():
454
-    def __init__(self, team, other, contr):
532
+    def __init__(self, team, other, contr, bench):
455 533
         scene = bge.logic.getCurrentScene()
456 534
         self.me = other
457 535
         g = self.me['game']
@@ -474,12 +552,6 @@ class hockey_player():
474 552
                         self.cont.children['whisker3'], 
475 553
                         self.cont.children['whisker4']]
476 554
         self.whiskers = [None, None, None, None, None]                
477
-        #self.whisker_c_obj = self.cont.children['whisker0'] 
478
-        #self.whisker_r_obj = self.cont.children['whisker_r'] 
479
-        #self.whisker_l_obj = self.cont.children['whisker_l']                 
480
-        self.whisker_c = None
481
-        self.whisker_r = None
482
-        self.whisker_l = None        
483 555
         
484 556
         self.stick_empty = self.stick.children['stick_empty']   
485 557
         self.indicator_obj = self.cont.children['indicator']  
@@ -538,6 +610,17 @@ class hockey_player():
538 610
         
539 611
         self.FSM = FSM.PlayerFSM(self)
540 612
 
613
+
614
+        for x in self.mates.players:
615
+            if x.bench:
616
+                self.mates.players.remove(x)
617
+        #put on bench
618
+        self.bench = bench
619
+        if bench:
620
+            #state on bench
621
+            print('benching', self)
622
+            self.FSM.FSM.ToTransition('toBenched')
623
+
541 624
     def update_inputs(self):
542 625
         keyboard = bge.logic.keyboard.inputs  
543 626
         
@@ -689,21 +772,16 @@ class hockey_player():
689 772
             m.user = 0
690 773
         if since_switch_a is not 0:
691 774
             if since_switch_a > 40:
692
-                
693 775
                 mates[0].user = 1
694 776
                 mates[0].orders = None
695
-                #self.user = 0
696
-                #print('p1')
697 777
                 mates[0].FSM.FSM.ToTransition('toGetPuckUser')
698 778
             else:
699 779
                 mates[1].user = 1            
700 780
                 mates[1].orders = None
701
-                #print('p2', since_switch_a)
702 781
                 mates[0].FSM.FSM.ToTransition('toGetPuckUser')
703 782
             self.orders = None    
704 783
             self.FSM.FSM.ToTransition('toGetPuck')
705 784
             self.user = 0  
706
-            #print('switch player', round(since_switch_a), self.user, self)  
707 785
             
708 786
     def check_puck(self):
709 787
         if self.FSM.FSM.stateLife > 120:
@@ -723,9 +801,6 @@ class hockey_player():
723 801
     def check_check(self):
724 802
         #if self.kb_ua == 1:
725 803
         if self.mates.user_input.i_ua == 1:     
726
-
727
-            #sorted(listasdf, key=lambda x: x[1])
728
-
729 804
             distances = []
730 805
             for w in self.whiskers:
731 806
                 if w[0] is not None:
@@ -736,11 +811,9 @@ class hockey_player():
736 811
             if distances != []:
737 812
                 #sort list of whiskers
738 813
                 nd = sorted(distances, key=lambda x: x[1])
739
-                
740 814
                 #sort list of whiskers
741 815
                 if nd[0][1] < 1.1:
742 816
                     self.FSM.FSM.ToTransition('toCheckOn') 
743
-                    #print(nd[0][0][0]['c_ref'])
744 817
                     nd[0][0][0]['c_ref'].checked = self                          
745 818
                 else:    
746 819
                     self.FSM.FSM.ToTransition('toCheckMissOn')        
@@ -749,8 +822,6 @@ class hockey_player():
749 822
 
750 823
     def check_checked(self):
751 824
         if self.checked == True:
752
-            #self.checked = False
753
-            #print('--------checked')
754 825
             return True    
755 826
         else:
756 827
             return False  
@@ -832,66 +903,64 @@ def game_main(cont):
832 903
     if 'inited' not in own:
833 904
         own['inited'] = True
834 905
         own['game'] = game(own, cont)
906
+        #scene = bge.logic.getCurrentScene()
907
+        bge.logic.addScene('fade', 1)
835 908
         
836 909
     own['game'].run()    
837 910
     
838
-def puck(cont):
839
-    own = cont.owner
840
-    g = own['game']
841
-
842
-    if g.puck_update:  
843
-        if own.worldPosition.z < 0: 
844
-           own.worldPosition.z = 0.5 
845
-           print('puck out of bounds -z')            
846
-        if own.worldPosition.z > .5: 
847
-           own.worldPosition.z = .5           
848
-        if own.worldPosition.x > 12:
849
-            own.worldPosition.x = 11.5
850
-            print('puck out of bounds +x')            
851
-        if own.worldPosition.x < -12:
852
-            own.worldPosition.x = -11.5
853
-            print('puck out of bounds -x')
854
-        if own.worldPosition.y > 8.15:
855
-            own.worldPosition.y = 7.0
856
-            #own.linearVelocity.x *= -1
857
-            print('puck out of bounds +y')
858
-        if own.worldPosition.y < -8.15:
859
-            own.worldPosition.y = -7.0
860
-            print('puck out of bounds -y')
861
-            #own.linearVelocity.x *= -1  
911
+# def puck(cont):
912
+#     own = cont.owner
913
+#     g = own['game']
914
+
915
+#     if g.puck_update:  
916
+#         if own.worldPosition.z < 0: 
917
+#            own.worldPosition.z = 0.5 
918
+#            print('puck out of bounds -z')            
919
+#         if own.worldPosition.z > .5: 
920
+#            own.worldPosition.z = .5           
921
+#         if own.worldPosition.x > 12:
922
+#             own.worldPosition.x = 11.5
923
+#             print('puck out of bounds +x')            
924
+#         if own.worldPosition.x < -12:
925
+#             own.worldPosition.x = -11.5
926
+#             print('puck out of bounds -x')
927
+#         if own.worldPosition.y > 8.15:
928
+#             own.worldPosition.y = 7.0
929
+#             #own.linearVelocity.x *= -1
930
+#             print('puck out of bounds +y')
931
+#         if own.worldPosition.y < -8.15:
932
+#             own.worldPosition.y = -7.0
933
+#             print('puck out of bounds -y')
862 934
             
863
-        if cont.sensors['puck-player'].hitObject is not None:
864
-            ho = cont.sensors['puck-player'].hitObject
865
-            if 'post' in ho:
866
-                print('POST!!!!')
867
-                g.sound_man.queue_sound(['post', g.puck, g.camera]) 
868
-            if 'board' in ho:
869
-                print('BOARD!!!!')
870
-                if g.frame - g.sound_man.board_played > 30:
871
-                    g.sound_man.queue_sound(['board', g.puck, g.camera])                                                
872
-                    g.sound_man.board_played = g.frame 
873
-        #if not g.a_team.possession and not g.b_team.possession:                  
874
-        #print(g.a_team.FSM.FSM.curState.__class__.__name__, g.b_team.FSM.FSM.__class__)
875
-        if g.a_team.FSM.FSM.curState.__class__.__name__ == 'Chase' and g.b_team.FSM.FSM.curState.__class__.__name__ == 'Chase': 
876
-            if cont.sensors['puck-player'].hitObject is not None:
877
-                ho = cont.sensors['puck-player'].hitObject
878
-                for p in g.a_team.players + g.b_team.players:
879
-                    if ho == p.cont or ho == p.stick:
880
-                        p.puck_trigger = True
881
-                    else:
882
-                        p.puck_trigger = False
935
+#         if cont.sensors['puck-player'].hitObject is not None:
936
+#             ho = cont.sensors['puck-player'].hitObject
937
+#             if 'post' in ho:
938
+#                 print('POST!!!!')
939
+#                 g.sound_man.queue_sound(['post', g.puck, g.camera]) 
940
+#             if 'board' in ho:
941
+#                 print('BOARD!!!!')
942
+#                 if g.frame - g.sound_man.board_played > 30:
943
+#                     g.sound_man.queue_sound(['board', g.puck, g.camera])                                                
944
+#                     g.sound_man.board_played = g.frame 
945
+
946
+#         if g.a_team.FSM.FSM.curState.__class__.__name__ == 'Chase' and g.b_team.FSM.FSM.curState.__class__.__name__ == 'Chase':
947
+#             if cont.sensors['puck-player'].hitObject is not None:
948
+#                 ho = cont.sensors['puck-player'].hitObject
949
+#                 for p in g.a_team.players + g.b_team.players:
950
+#                     if ho == p.cont or ho == p.stick:
951
+#                         p.puck_trigger = True
952
+#                         print(p.puck_trigger, p)
953
+#                     else:
954
+#                         p.puck_trigger = False
883 955
                 
884
-                o = cont.sensors['puck-player'].hitObject
885
-                if 'goal' in o:
886
-
887
-                    print('GOOOAAAALLL!!', o['team'])
888
-                    if o['team'] == 'a':
889
-                        g.score[0] += 1
890
-                        g.a_team.scored = True
891
-                    if o['team'] == 'b':
892
-                        g.score[1] += 1 
893
-                        g.b_team.scored = True   
894
-                    g.FSM.FSM.ToTransition('toGoalScored')
895
-
896
-                    #if 'a2' in cont.sensors['puck-player'].hitObject['name']:
897
-                        #pass
956
+#                 o = cont.sensors['puck-player'].hitObject
957
+#                 if 'goal' in o:
958
+
959
+#                     print('GOOOAAAALLL!!', o['team'])
960
+#                     if o['team'] == 'a':
961
+#                         g.score[0] += 1
962
+#                         g.a_team.scored = True
963
+#                     if o['team'] == 'b':
964
+#                         g.score[1] += 1 
965
+#                         g.b_team.scored = True   
966
+#                     g.FSM.FSM.ToTransition('toGoalScored')

+ 69
- 0
scripts/puck.py View File

@@ -0,0 +1,69 @@
1
+
2
+
3
+
4
+def puck(cont):
5
+    own = cont.owner
6
+    g = own['game']
7
+    if 'inited' not in own:
8
+        own['inited'] = True
9
+        own['lastpos'] = [0,0,0]
10
+
11
+    if g.Puck_FSM:
12
+        g.Puck_FSM.Execute()
13
+
14
+    if g.puck_update:  
15
+        if own.worldPosition.z < .120: 
16
+           own.worldPosition.z = 0.120 
17
+           own.linearVelocity.z = 0
18
+           #print('puck out of bounds -z')            
19
+        if own.worldPosition.z > 1.5: 
20
+           own.worldPosition.z = 1.5           
21
+        if own.worldPosition.x > 12:
22
+            own.worldPosition.x = 11.5
23
+            print('puck out of bounds +x')            
24
+        if own.worldPosition.x < -12:
25
+            own.worldPosition.x = -11.5
26
+            print('puck out of bounds -x')
27
+        if own.worldPosition.y > 8.15:
28
+            own.worldPosition.y = 7.0
29
+            #own.linearVelocity.x *= -1
30
+            print('puck out of bounds +y')
31
+        if own.worldPosition.y < -8.15:
32
+            own.worldPosition.y = -7.0
33
+            print('puck out of bounds -y')
34
+            
35
+        if cont.sensors['puck-player'].hitObject is not None:
36
+            ho = cont.sensors['puck-player'].hitObject
37
+            if 'post' in ho or 'goal' in ho:
38
+                print('POST!!!!')
39
+                g.sound_man.queue_sound(['post', g.puck, g.camera]) 
40
+            elif 'board' in ho:
41
+                print('BOARD!!!!')
42
+                if g.frame - g.sound_man.board_played > 30:
43
+                    g.sound_man.queue_sound(['board', g.puck, g.camera])                                                
44
+                    g.sound_man.board_played = g.frame 
45
+
46
+        if g.a_team.FSM.FSM.curState.__class__.__name__ == 'Chase' and g.b_team.FSM.FSM.curState.__class__.__name__ == 'Chase':
47
+            if cont.sensors['puck-player'].hitObject is not None:
48
+                ho = cont.sensors['puck-player'].hitObject
49
+                for p in g.a_team.players + g.b_team.players:
50
+                    if ho == p.cont or ho == p.stick:
51
+                        p.puck_trigger = True
52
+                        print(p.puck_trigger, p)
53
+                    else:
54
+                        p.puck_trigger = False
55
+                
56
+                o = cont.sensors['puck-player'].hitObject
57
+                if 'goal' in o:
58
+
59
+                    print('GOOOAAAALLL!!', o['team'])
60
+                    if o['team'] == 'a':
61
+                        g.score[0] += 1
62
+                        g.a_team.scored = True
63
+                    if o['team'] == 'b':
64
+                        g.score[1] += 1 
65
+                        g.b_team.scored = True   
66
+                    g.FSM.FSM.ToTransition('toGoalScored')
67
+
68
+    own.alignAxisToVect([0,0,1], 2, 1)                
69
+    own['lastpos'] = own.worldPosition.copy()

+ 91
- 2
scripts/utils.py View File

@@ -1,4 +1,5 @@
1 1
 import bge
2
+from mathutils import Vector
2 3
 
3 4
 def update_whiskers(self):
4 5
     o = self
@@ -96,10 +97,98 @@ def whisker_turns_goal(o):
96 97
         if 'goal' in o.whiskers[0][0]:
97 98
             o.kb_d = 1
98 99
             o.kb_a = 0
99
-            print('whisker turn d')
100
+            #print('whisker turn d')
100 101
 
101 102
     if o.whiskers[4][0] and not o.whiskers[0][0]:
102 103
         if 'goal' in o.whiskers[4][0]:
103 104
             o.kb_a = 1
104 105
             o.kb_d = 0                
105
-            print('whisker turn a')
106
+            #print('whisker turn a')
107
+
108
+def whisker_turns(o):
109
+
110
+    if o.me['game'].frame % 30 == 1:
111
+
112
+        if o.whiskers[0][0] and not o.whiskers[4][0]:
113
+            if 'player' in o.whiskers[0][0]:
114
+                o.kb_d = 1
115
+                o.kb_a = 0
116
+                o.kb_w = 1
117
+                #print('whisker turn d')
118
+
119
+        if o.whiskers[4][0] and not o.whiskers[0][0]:
120
+            if 'player' in o.whiskers[4][0]:
121
+                o.kb_a = 1
122
+                o.kb_d = 0
123
+                o.kb_w = 1                
124
+                #print('whisker turn a')    
125
+
126
+        if o.whiskers[0][0] and o.whiskers[1][0] and o.whiskers[3][0] and o.whiskers[4][0]:
127
+            if 'player' in o.whiskers[0][0] and 'player' in o.whiskers[4][0]:
128
+                o.kb_s = 1
129
+                if o.kb_a == 1:
130
+                    o.kb_a = 0
131
+                    o.kb_d = 1
132
+                elif o.kb_d == 1:
133
+                    o.kb_d = 0
134
+                    o.kb_a = 1
135
+                else:
136
+                    o.kb_a = 1    
137
+                o.kb_a = 0
138
+                o.kb_d = 0
139
+                o.kb_s = 0
140
+                o.kb_w = 0
141
+                print('backing up')                
142
+
143
+    # else:
144
+    #     o.kb_d = o.last_kb_d
145
+    #     o.kb_a = o.last_kb_a
146
+    #     o.kb_s = o.last_kb_s
147
+    #     o.kb_w = o.last_kb_w
148
+
149
+def hide_player(o):
150
+    o.stick.visible = False
151
+    o.base.visible = False
152
+    o.head.visible = False
153
+    o.body.visible = False
154
+    o.indicator_obj.visible = False
155
+    o.body.children['stripe'].visible = False            
156
+
157
+def show_player(o):
158
+    o.stick.visible = True
159
+    o.base.visible = True
160
+    o.head.visible = True
161
+    o.body.visible = True
162
+    o.indicator_obj.visible = True
163
+    o.body.children['stripe'].visible = True   
164
+
165
+        
166
+def puck_wall(own):
167
+        
168
+        worldvel = own.worldLinearVelocity.normalized()
169
+        damping = .8
170
+        #wall_damping = .5
171
+        start2 = own['lastpos']
172
+        #start2.x += 5
173
+        end2 = own.worldPosition.copy()
174
+        #end2.x -= 5
175
+        ray2 = own.rayCast(end2, start2, 0, 'board', 1, 1, 0, mask=4)
176
+        color = [0,0,1]
177
+        
178
+        #print(start2, end2)
179
+        if ray2[0] != None:
180
+            print('------------wall')
181
+            own.worldPosition = own['lastpos']
182
+            #own.alignAxisToVect([0,0,1], 2, 1)        
183
+            own.worldLinearVelocity = damping * (own.worldLinearVelocity - 2 * own.worldLinearVelocity.dot(ray2[2]) * ray2[2])
184
+            color = [0,1,1]
185
+        #bge.render.drawLine(start2, end2, color)
186
+        #else:
187
+            #print('no wall')
188
+        #don't align if not moving 
189
+        
190
+        worldvel.z = 0           
191
+        if worldvel != Vector([0, 0, 0]):        
192
+            own.alignAxisToVect(own.worldLinearVelocity, 0, .05)        
193
+
194
+

Loading…
Cancel
Save