Browse Source

third commit

shuvit 4 years ago
parent
commit
dc45224f31
14 changed files with 1573 additions and 0 deletions
  1. 3
    0
      README.md
  2. 3
    0
      assets/base_rink.blend
  3. 3
    0
      assets/net.png
  4. 3
    0
      game.blend
  5. 112
    0
      scripts/FSM.py
  6. 125
    0
      scripts/StatesGame.py
  7. 581
    0
      scripts/StatesPlayer.py
  8. 3
    0
      scripts/linkEmpty.blend
  9. 530
    0
      scripts/player.py
  10. 137
    0
      scripts/sound_man.py
  11. 64
    0
      scripts/utils.py
  12. 3
    0
      sounds/check.wav
  13. 3
    0
      sounds/post.wav
  14. 3
    0
      sounds/shoot.wav

+ 3
- 0
README.md View File

@@ -0,0 +1,3 @@
1
+Mighty Mites is a free and open pc hockey game for Linux and Windows systems.
2
+
3
+The work is currently in progress.

+ 3
- 0
assets/base_rink.blend View File

@@ -0,0 +1,3 @@
1
+version https://git-lfs.github.com/spec/v1
2
+oid sha256:6fd35c828bc9f4a9cedd4a0cbabfe4c73b4f631a6f9ac40a7a9ce8d43d99768d
3
+size 879696

+ 3
- 0
assets/net.png View File

@@ -0,0 +1,3 @@
1
+version https://git-lfs.github.com/spec/v1
2
+oid sha256:1d6832f13974ab842354ebd4d072e6fe57315bc9d966e262d3eda9788060c60f
3
+size 5360

+ 3
- 0
game.blend View File

@@ -0,0 +1,3 @@
1
+version https://git-lfs.github.com/spec/v1
2
+oid sha256:623320f4905f17477c58d6a559e9f76470a0f7dad220fd39ea196c4df59ffa90
3
+size 1483712

+ 112
- 0
scripts/FSM.py View File

@@ -0,0 +1,112 @@
1
+import bge
2
+
3
+import StatesGame
4
+import StatesPlayer
5
+   
6
+#====================================
7
+class Transition(object):
8
+    def __init__(self, toState):
9
+        self.toState = toState
10
+    def Execute(self):
11
+        pass
12
+                        
13
+#===================================
14
+                        
15
+class FSM(object):
16
+    def __init__ (self, character, owner):
17
+        self.char = character
18
+        self.states = {}
19
+        self.transitions = {}
20
+        self.curState = None
21
+        self.prevState = None
22
+        self.trans = None
23
+        self.stateLife = 0
24
+        self.owner = owner
25
+        self.name = None
26
+        
27
+    def AddTransition(self, transName, transition):
28
+        self.transitions[transName] = transition
29
+    
30
+    def AddState(self, stateName, state):
31
+        self.states[stateName] = state
32
+        self.states[stateName].name = state        
33
+        
34
+    def SetState(self, stateName):
35
+        self.prevState = self.curState
36
+        self.curState = self.states[stateName]
37
+        
38
+    def ToTransition(self, toTrans):
39
+        self.trans = self.transitions[toTrans]
40
+        
41
+    def Execute(self, owner):
42
+        if (self.trans):
43
+            self.owner = owner
44
+            self.curState.Exit()
45
+            self.trans.Execute()
46
+            self.SetState(self.trans.toState)
47
+            self.curState.Enter()
48
+            self.trans = None        
49
+            
50
+        self.curState.Execute()    
51
+                
52
+#====================================
53
+
54
+Char = type("Char",(object,),{})
55
+
56
+#===================================
57
+
58
+class PlayerFSM(Char):
59
+    def __init__(self, owner):
60
+        self.FSM = FSM(self, owner)
61
+        self.owner = owner
62
+        
63
+        state_list = [
64
+        'Shooting',
65
+        'GetPuck',
66
+        'Passing',
67
+        'DefendPuck',
68
+        'PosesPuck',
69
+        'MatchIntro',
70
+        'FaceoffIntro',
71
+        'Faceoff', 
72
+        'ShootShot',
73
+        'WindShot']
74
+        
75
+        for s in state_list:
76
+            self.FSM.AddState(s, getattr(StatesPlayer, s)(self.FSM))
77
+            t = 'to' + s
78
+            self.FSM.AddTransition(t, Transition(s))
79
+        
80
+        if self.FSM.curState == None:
81
+            self.FSM.SetState('MatchIntro')
82
+    
83
+    def Execute(self):
84
+        self.FSM.Execute(self.owner)    
85
+        
86
+#===================================
87
+        
88
+class GameFSM(Char):
89
+    def __init__(self, owner):
90
+        self.FSM = FSM(self, owner)
91
+        self.owner = owner
92
+        
93
+        state_list = [
94
+        'MatchIntro',
95
+        'FaceOff',
96
+        'FaceoffIntro',
97
+        'InPlay',
98
+        'GoalScored']
99
+        
100
+        for s in state_list:
101
+            self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
102
+            t = 'to' + s
103
+            self.FSM.AddTransition(t, Transition(s))
104
+        
105
+        if self.FSM.curState == None:
106
+            self.FSM.SetState('MatchIntro')
107
+    
108
+    def Execute(self):
109
+        self.FSM.Execute(self.owner)       
110
+             
111
+#====================================     
112
+

+ 125
- 0
scripts/StatesGame.py View File

@@ -0,0 +1,125 @@
1
+State = type("State", (object,), {})
2
+
3
+class State(object):
4
+    def __init__(self, FSM):
5
+        self.FSM = FSM
6
+        self.timer = 0
7
+        self.startTime = 0
8
+    def Enter(self):
9
+        self.timer = 0
10
+        self.startTime = 0
11
+    def Execute(self):
12
+        print('Executing')
13
+    def Exit(self):
14
+        print('Exiting')
15
+        
16
+class MatchIntro(State):
17
+    def __init__(self,FSM):
18
+        super(MatchIntro, self).__init__(FSM)    
19
+        
20
+    def Enter(self):
21
+        self.FSM.stateLife = 1
22
+        super(MatchIntro, self).Enter()        
23
+        
24
+    def Execute(self):
25
+        self.FSM.stateLife += 1
26
+        o = self.FSM.owner
27
+    
28
+        if self.FSM.stateLife > 30:
29
+            self.FSM.ToTransition('toFaceoffIntro')
30
+        #print('intro')
31
+    def Exit(self):
32
+        pass
33
+    
34
+class FaceOff(State):
35
+    def __init__(self,FSM):
36
+        super(FaceOff, self).__init__(FSM)    
37
+        
38
+    def Enter(self):
39
+        self.FSM.stateLife = 1
40
+        super(FaceOff, self).Enter()        
41
+        
42
+    def Execute(self):
43
+        self.FSM.stateLife += 1
44
+        g = self.FSM.owner
45
+        
46
+        
47
+        if self.FSM.stateLife < 140:
48
+            g.puck.worldPosition = [0,0,1000]
49
+        if self.FSM.stateLife == 140:
50
+            g.puck.worldPosition = [0,0,4]
51
+            g.puck.linearVelocity = [0,0,0]            
52
+
53
+        if self.FSM.stateLife > 180:
54
+            #g.puck.worldPosition = [0,0,40]
55
+            g.puck_update = True
56
+            self.FSM.ToTransition('toInPlay')
57
+
58
+                
59
+            
60
+        print('faceoff')
61
+    def Exit(self):
62
+        pass   
63
+    
64
+class FaceoffIntro(State):
65
+    def __init__(self,FSM):
66
+        super(FaceoffIntro, self).__init__(FSM)    
67
+        
68
+    def Enter(self):
69
+        self.FSM.stateLife = 1
70
+        super(FaceoffIntro, self).Enter()  
71
+        #push to players
72
+        g = self.FSM.owner
73
+        
74
+        for p in (g.b_team.players + g.a_team.players):
75
+            p.FSM.FSM.ToTransition('toFaceoffIntro')      
76
+        
77
+    def Execute(self):
78
+        self.FSM.stateLife += 1
79
+        print('faceoff intro')
80
+        if self.FSM.stateLife > 240:
81
+
82
+            self.FSM.ToTransition('toFaceOff')
83
+                
84
+            
85
+        print('faceoff')
86
+    def Exit(self):
87
+        pass        
88
+    
89
+class GoalScored(State):
90
+    def __init__(self,FSM):
91
+        super(GoalScored, self).__init__(FSM)    
92
+        
93
+    def Enter(self):
94
+        self.FSM.stateLife = 1
95
+        super(GoalScored, self).Enter()        
96
+        self.FSM.owner.puck_update = False
97
+        
98
+    def Execute(self):
99
+        self.FSM.stateLife += 1
100
+        o = self.FSM.owner
101
+        print('GOOOOOAAAALLL')
102
+        if self.FSM.stateLife > 340:
103
+            self.FSM.ToTransition('toFaceoffIntro')
104
+        #print('goal')
105
+    def Exit(self):
106
+        pass        
107
+    
108
+class InPlay(State):
109
+    def __init__(self,FSM):
110
+        super(InPlay, self).__init__(FSM)    
111
+        
112
+    def Enter(self):
113
+        self.FSM.stateLife = 1
114
+        super(InPlay, self).Enter()        
115
+        
116
+    def Execute(self):
117
+        self.FSM.stateLife += 1
118
+        o = self.FSM.owner
119
+
120
+        #if self.FSM.stateLife > 20:
121
+            #self.FSM.ToTransition('toGoalScored')
122
+        #print('inplay')
123
+    def Exit(self):
124
+        pass      
125
+    

+ 581
- 0
scripts/StatesPlayer.py View File

@@ -0,0 +1,581 @@
1
+import utils
2
+
3
+State = type("State", (object,), {})
4
+#====================================     
5
+class State(object):
6
+    def __init__(self, FSM):
7
+        self.FSM = FSM
8
+        self.timer = 0
9
+        self.startTime = 0
10
+    def Enter(self):
11
+        self.timer = 0
12
+        self.startTime = 0
13
+    def Execute(self):
14
+        print('Executing')
15
+    def Exit(self):
16
+        print('Exiting')
17
+#====================================             
18
+class Example(State):
19
+    def __init__(self,FSM):
20
+        super(Example, self).__init__(FSM)    
21
+        
22
+    def Enter(self):
23
+        self.FSM.stateLife = 1
24
+        super(Example, self).Enter()        
25
+        
26
+    def Execute(self):
27
+        self.FSM.stateLife += 1
28
+        o = self.FSM.owner
29
+        g = o.me
30
+        self.FSM.ToTransition('toNewState')
31
+    
32
+    def Exit(self):
33
+        pass
34
+
35
+#====================================     
36
+        
37
+class GetPuck(State):
38
+    def __init__(self,FSM):
39
+        super(GetPuck, self).__init__(FSM)    
40
+        
41
+    def Enter(self):
42
+        self.FSM.stateLife = 1
43
+        super(GetPuck, self).Enter()  
44
+        o = self.FSM.owner      
45
+        o.puck_trigger = False
46
+        #o.last_kb_da = 0
47
+        
48
+    def Execute(self):
49
+        self.FSM.stateLife += 1
50
+        o = self.FSM.owner
51
+        g = o.me['game']
52
+        if self.FSM.stateLife > 30:
53
+            if o.puck_trigger:
54
+                o.puck_trigger = False
55
+                o.puck = True
56
+                for x in o.mates.players:
57
+                    x.user = 0
58
+                o.user = 1
59
+                #print('trigger hit')
60
+                self.FSM.ToTransition('toPosesPuck')
61
+        #o.check_puck()
62
+        #print(o.puck, o.mates.possession, o.puck_trigger)
63
+        #print(o.player_col)
64
+        if o.user == 1:
65
+            o.update_inputs() 
66
+            if self.FSM.stateLife > 10:
67
+                if o.kb_da == 0 and o.last_kb_da == 1:
68
+                    o.switch_player()
69
+                    print('fsm switch')
70
+        if o.team == 1:
71
+            self.FSM.ToTransition('toDefendPuck')
72
+    
73
+    def Exit(self):
74
+        pass
75
+
76
+#====================================     
77
+    
78
+class PosesPuck(State):
79
+    def __init__(self,FSM):
80
+        super(PosesPuck, self).__init__(FSM)    
81
+        
82
+    def Enter(self):
83
+        self.FSM.stateLife = 1
84
+        super(PosesPuck, self).Enter()
85
+        self.FSM.stateLife = 1
86
+        o = self.FSM.owner
87
+        g = o.me['game'] 
88
+        o.puck_trigger = False       
89
+        if o.team == 0:
90
+            g.team_possession = 1
91
+        if o.team == 1:
92
+            g.team_possession = 2          
93
+        
94
+    def Execute(self):
95
+        o = self.FSM.owner
96
+        g = o.me['game']
97
+        self.FSM.stateLife += 1
98
+        #print('possessing')
99
+        #print(o.kb_da, o.state)
100
+        #ai        
101
+        if o.mates.user == 0:
102
+            if self.FSM.stateLife < 260:
103
+                g.puck.worldPosition = o.stick_empty.worldPosition
104
+                g.puck.linearVelocity = [0,0,0]  
105
+              
106
+            #print('doing puck ai', self.FSM.stateLife)
107
+            if self.FSM.stateLife > 260:
108
+                g.puck.applyForce([1,0,0], True)
109
+                o.puck = False
110
+            if self.FSM.stateLife > 300:
111
+                self.FSM.ToTransition('toDefendPuck') 
112
+                o.mates.possession = False              
113
+                o.puck = False
114
+        #user  
115
+#        elif o.state != 'chasing':
116
+#            g.puck.worldPosition = o.stick_empty.worldPosition
117
+#            g.puck.linearVelocity = [0,0,0]  
118
+        else:
119
+            #check inputs
120
+            o.update_inputs()    
121
+            g.puck.worldPosition = o.stick_empty.worldPosition
122
+            g.puck.linearVelocity = [0,0,0]             
123
+            #print(o.kb_da)             
124
+            if o.kb_da == 1 and o.last_kb_da == 0:
125
+                print('--- wind shot')
126
+                self.FSM.ToTransition('toWindShot')         
127
+                
128
+            o.user_movement()
129
+                
130
+    def Exit(self):
131
+        o = self.FSM.owner
132
+        g = o.me['game']        
133
+        g.team_possession = 0
134
+        o.puck_trigger = False
135
+        o.puck = False
136
+
137
+#====================================     
138
+
139
+class DefendPuck(State):
140
+    def __init__(self,FSM):
141
+        super(DefendPuck, self).__init__(FSM)    
142
+        
143
+    def Enter(self):
144
+        print('Preparing to defend.')
145
+        self.FSM.stateLife = 1
146
+        super(DefendPuck, self).Enter()
147
+        
148
+    def Execute(self):
149
+        self.FSM.stateLife += 1
150
+
151
+        o = self.FSM.owner
152
+        
153
+        g = o.me['game']
154
+
155
+        d = o.cont.getDistanceTo(g.puck)  
156
+        
157
+        utils.update_whiskers(o)  
158
+                  
159
+        if g.puck.worldPosition.y > 0:
160
+            y = -4
161
+        else:
162
+            y = 4
163
+        if o.player_col:
164
+            #print('hitting', o.player_col) 
165
+            pass   
166
+        if o == g.players[1]:
167
+            poi = [0, y, o.cont.worldPosition.z]
168
+            if g.puck.worldPosition.x > 4:
169
+                poi = [-6, y, o.cont.worldPosition.z]    
170
+            if g.puck.worldPosition.x < -4:
171
+                poi = [4, y, o.cont.worldPosition.z]                    
172
+            #distance to point of interest
173
+            dto_poi = o.cont.getDistanceTo(poi)
174
+            if dto_poi > .5:
175
+                v = o.cont.getVectTo(poi)
176
+                o.cont.alignAxisToVect(v[1], 0, .1)
177
+                if o.cont.linearVelocity.x < 2:
178
+                    o.cont.applyForce([o.speed, 0, 0], True)
179
+            else:
180
+                v = o.cont.getVectTo(g.puck)
181
+                o.cont.alignAxisToVect(v[1], 0, .05)                
182
+                o.cont.linearVelocity = [0, 0, 0]
183
+                
184
+            o.align_to_base()
185
+            if abs(o.cont.linearVelocity.y) > .5:
186
+                o.cont.linearVelocity *= .5
187
+                
188
+        if o == g.players[2]:
189
+            poi = [0-6, -y, o.cont.worldPosition.z]
190
+            if g.puck.worldPosition.x > 4:
191
+                poi = [6-6, -y, o.cont.worldPosition.z]    
192
+            if g.puck.worldPosition.x < -4:
193
+                poi = [-4-6, y, o.cont.worldPosition.z]                    
194
+            #distance to point of interest
195
+            dto_poi = o.cont.getDistanceTo(poi)
196
+            if dto_poi > .5:
197
+                v = o.cont.getVectTo(poi)
198
+                o.cont.alignAxisToVect(v[1], 0, .1)
199
+                if o.cont.linearVelocity.x < 2:
200
+                    o.cont.applyForce([o.speed, 0, 0], True)
201
+            else:
202
+                v = o.cont.getVectTo(g.puck)
203
+                o.cont.alignAxisToVect(v[1], 0, .05)                
204
+                o.cont.linearVelocity = [0, 0, 0]
205
+                
206
+            o.align_to_base()
207
+            if abs(o.cont.linearVelocity.y) > .5:
208
+                o.cont.linearVelocity *= .5
209
+        
210
+        
211
+    def Exit(self):
212
+        pass         
213
+
214
+#====================================     
215
+        
216
+class Passing(State):
217
+    def __init__(self,FSM):
218
+        super(Passing, self).__init__(FSM)    
219
+        
220
+    def Enter(self):
221
+        print('Preparing to Passing.')
222
+        self.FSM.stateLife = 1
223
+        super(Passing, self).Enter()
224
+        
225
+    def Execute(self):
226
+        self.FSM.stateLife += 1
227
+        o = self.FSM.owner        
228
+        g = o.me['game']
229
+        o.state = 'passing'
230
+    
231
+        print('passing', self.FSM.stateLife, o.puck, o.user)
232
+        mates = o.mates.p_closest.copy()
233
+        mates.remove(o)    
234
+    
235
+        v = o.cont.getVectTo(o.teammates[o.pass_id].cont)
236
+        
237
+        stre = .1
238
+        o.stick.alignAxisToVect(v[1], 0, stre)        
239
+        o.cont.alignAxisToVect(v[1], 0, stre)                        
240
+        e1 = o.cont.worldOrientation.to_euler().z
241
+        e2 = o.stick.worldOrientation.to_euler().z
242
+        dif = e1 - e2
243
+        if dif > -1.5:
244
+            o.stick.applyRotation([0,0,.15], True) 
245
+
246
+        
247
+        if o.passing == 15:
248
+            g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
249
+            
250
+            
251
+        if o.passing > 15:   
252
+            g.puck.worldPosition = o.puck_empty.worldPosition
253
+            g.puck.linearVelocity = [0,0,0]            
254
+
255
+        if o.kb_la == 1 or o.kb_ra == 1:
256
+            o.passing = 25
257
+            #print('kb')   
258
+        else:
259
+            #print(o.passing)
260
+            if o.passing > 0:
261
+                #print('opassing')
262
+                dif = e1 - e2
263
+                o.passing -= 1
264
+                o.stick.applyRotation([0,0,-.23], True)   
265
+                #print(dif)      
266
+                #if dif > 1.8 and o.passing < 5:
267
+                if o.passing < 1:                
268
+                    o.state = 'chasing'
269
+                    self.FSM.ToTransition('toGetPuck')
270
+                    #print('exit')
271
+                o.puck = False
272
+            
273
+    def Exit(self):
274
+        print('Finished Passing')   
275
+        o = self.FSM.owner        
276
+        g = o.me['game']
277
+        o.puck = False 
278
+        o.passing = 0  
279
+        g.a_team.possession = False
280
+        g.b_team.possession = False                       
281
+        
282
+#====================================     
283
+        
284
+class Shooting(State):
285
+    
286
+    def __init__(self,FSM):
287
+        super(Shooting, self).__init__(FSM)  
288
+        
289
+    def Enter(self):
290
+        print('Starting to Shooting.')
291
+        super(Shooting, self).Enter()
292
+        self.FSM.stateLife = 1
293
+        
294
+    def Execute(self):
295
+        pass
296
+#        self.FSM.stateLife += 1
297
+#        o = self.FSM.owner        
298
+#        g = o.me['game']
299
+#        o.state = 'shooting'
300
+#        v = o.cont.getVectTo(o.goal_t)
301
+#        
302
+#        stre = .1
303
+#        o.stick.alignAxisToVect(v[1], 0, stre)        
304
+#        o.cont.alignAxisToVect(v[1], 0, stre)                        
305
+#        e1 = o.cont.worldOrientation.to_euler().z
306
+#        e2 = o.stick.worldOrientation.to_euler().z
307
+#        dif = e1 - e2
308
+#        if dif > -1.5:
309
+#            o.stick.applyRotation([0,0,.15], True) 
310
+#            
311
+#        if o.shooting > 15:   
312
+#            g.puck.worldPosition = o.puck_empty.worldPosition
313
+#            g.puck.linearVelocity = [0,0,0]            
314
+#        
315
+#        if o.shooting == 15:
316
+#            g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
317
+#            
318
+#        if o.kb_da == 1:
319
+#            o.shooting = 25
320
+#            #print('kb')   
321
+#        else:
322
+#            print(o.shooting)
323
+#            if o.shooting > 0:
324
+#                #print('oshooting')
325
+#                dif = e1 - e2
326
+#                o.shooting -= 1
327
+#                o.stick.applyRotation([0,0,-.22], True)   
328
+#                #print(dif)      
329
+#                #if dif > 1.8 and o.shooting < 5:
330
+#                if o.shooting < 1:                
331
+#                    o.state = 'chasing'
332
+#                    self.FSM.ToTransition('toGetPuck')
333
+#                    #print('exit')
334
+#                o.puck = False 
335
+            
336
+    def Exit(self):
337
+        print('Waking up from Shooting.')          
338
+        o = self.FSM.owner        
339
+        g = o.me['game']
340
+        o.puck = False  
341
+        o.shooting = 0      
342
+        g.a_team.possession = False
343
+        g.b_team.possession = False 
344
+        
345
+        
346
+#====================================             
347
+        
348
+class Dumping(State):
349
+    
350
+    def __init__(self,FSM):
351
+        super(Dumping, self).__init__(FSM)  
352
+        
353
+    def Enter(self):
354
+        print('Starting to dump.')
355
+        super(Dumping, self).Enter()
356
+        self.FSM.stateLife = 1
357
+        
358
+    def Execute(self):
359
+        self.FSM.stateLife += 1
360
+        o = self.FSM.owner        
361
+        g = o.me['game']
362
+        o.state = 'shooting'
363
+        #v = o.cont.getVectTo(o.goal_t)
364
+        
365
+        #stre = .1
366
+        #o.stick.alignAxisToVect(v[1], 0, stre)        
367
+        #o.cont.alignAxisToVect(v[1], 0, stre)                        
368
+        e1 = o.cont.worldOrientation.to_euler().z
369
+        e2 = o.stick.worldOrientation.to_euler().z
370
+        dif = e1 - e2
371
+        if dif > -1.5:
372
+            o.stick.applyRotation([0,0,.15], True) 
373
+            
374
+        if o.shooting > 15:   
375
+            g.puck.worldPosition = o.puck_empty.worldPosition
376
+            g.puck.linearVelocity = [0,0,0]            
377
+
378
+        if o.kb_ua == 1:
379
+            o.shooting = 25
380
+            #print('kb')   
381
+        else:
382
+            print(o.shooting)
383
+            if o.shooting > 0:
384
+                #print('oshooting')
385
+                dif = e1 - e2
386
+                o.shooting -= 1
387
+                o.stick.applyRotation([0,0,-.22], True)   
388
+                #print(dif)      
389
+                #if dif > 1.8 and o.shooting < 5:
390
+                if o.shooting < 1:                
391
+                    o.state = 'chasing'
392
+                    self.FSM.ToTransition('toGetPuck')
393
+                    #print('exit')
394
+                o.puck = False
395
+ 
396
+            
397
+    def Exit(self):
398
+        print('Waking up from Shooting.')          
399
+        o = self.FSM.owner        
400
+        g = o.me['game']
401
+        o.puck = False  
402
+        o.shooting = 0      
403
+        g.a_team.possession = False
404
+        g.b_team.possession = False 
405
+
406
+#====================================             
407
+        
408
+class MatchIntro(State):
409
+    def __init__(self,FSM):
410
+        super(MatchIntro, self).__init__(FSM)    
411
+        
412
+    def Enter(self):
413
+        self.FSM.stateLife = 1
414
+        super(MatchIntro, self).Enter()        
415
+        
416
+    def Execute(self):
417
+        self.FSM.stateLife += 1
418
+        o = self.FSM.owner
419
+        g = o.me['game']
420
+        utils.update_whiskers(o)        
421
+        #print(g.FSM.FSM.curState is not g.FSM.FSM.lastState)
422
+        if g.FSM.FSM.trans:
423
+            self.FSM.ToTransition('toFaceoffIntro')
424
+            print('exit intro')
425
+    
426
+    def Exit(self):
427
+        pass   
428
+    
429
+#====================================         
430
+    
431
+class FaceoffIntro(State):
432
+    def __init__(self,FSM):
433
+        super(FaceoffIntro, self).__init__(FSM)    
434
+        
435
+    def Enter(self):
436
+        self.FSM.stateLife = 1
437
+        super(FaceoffIntro, self).Enter()        
438
+        self.last_dist = 0
439
+        
440
+    def Execute(self):
441
+        self.FSM.stateLife += 1
442
+        o = self.FSM.owner
443
+        g = o.me['game']
444
+        utils.update_whiskers(o)  
445
+        target = [o.faceoff_pos[0], o.faceoff_pos[1], o.cont.worldPosition.z]
446
+        dist = o.cont.getDistanceTo(target)
447
+        #print(dist)
448
+        if dist > .5:
449
+            v = o.cont.getVectTo(target)
450
+            o.cont.alignAxisToVect(v[1], 0, .25)
451
+            if o.cont.linearVelocity.x < 2:
452
+                
453
+                o.cont.applyForce([10, 0,0], True)
454
+            #print('********-move')
455
+        else:
456
+            v = o.cont.getVectTo([0, 0.0001, .0001])
457
+            o.cont.alignAxisToVect(v[1], 0, .05)    
458
+        self.last_dist = dist
459
+        #print(g.FSM.FSM.curState is not g.FSM.FSM.lastState)
460
+        if g.FSM.FSM.trans:
461
+            self.FSM.ToTransition('toFaceoff')        
462
+    
463
+    def Exit(self):
464
+        pass   
465
+    
466
+#====================================     
467
+    
468
+class Faceoff(State):
469
+    def __init__(self,FSM):
470
+        super(Faceoff, self).__init__(FSM)    
471
+        
472
+    def Enter(self):
473
+        self.FSM.stateLife = 1
474
+        super(Faceoff, self).Enter()        
475
+        
476
+    def Execute(self):
477
+        self.FSM.stateLife += 1
478
+        o = self.FSM.owner
479
+        g = o.me['game']
480
+        #print(g.FSM.FSM.curState is not g.FSM.FSM.lastState)
481
+        o = self.FSM.owner
482
+        g = o.me['game']
483
+        
484
+        v = o.cont.getVectTo([0, 0.0001, .0001])
485
+        o.cont.alignAxisToVect(v[1], 0, .5)
486
+        
487
+        if g.FSM.FSM.trans:
488
+            self.FSM.ToTransition('toGetPuck')
489
+            print('exit intro')
490
+    
491
+    def Exit(self):
492
+        pass   
493
+                 
494
+#====================================                      
495
+
496
+class WindShot(State):
497
+    def __init__(self,FSM):
498
+        super(WindShot, self).__init__(FSM)    
499
+        
500
+    def Enter(self):
501
+        self.FSM.stateLife = 1
502
+        super(WindShot, self).Enter()        
503
+        
504
+    def Execute(self):
505
+        self.FSM.stateLife += 1
506
+        o = self.FSM.owner
507
+        g = o.me['game']
508
+        
509
+        
510
+        
511
+        v = o.cont.getVectTo(o.goal_t)
512
+        
513
+        stre = .1
514
+        o.stick.alignAxisToVect(v[1], 0, stre)        
515
+        o.cont.alignAxisToVect(v[1], 0, stre)                        
516
+        e1 = o.cont.worldOrientation.to_euler().z
517
+        e2 = o.stick.worldOrientation.to_euler().z
518
+        dif = e1 - e2
519
+        if dif > -1.5:
520
+            o.stick.applyRotation([0,0,.15], True) 
521
+            
522
+ 
523
+        g.puck.worldPosition = o.puck_empty.worldPosition
524
+        g.puck.linearVelocity = [0,0,0]            
525
+    
526
+        #if o.shooting == 15:
527
+        
528
+            
529
+        if o.kb_da == 1:
530
+            pass
531
+            #o.shooting = 25
532
+            #print('kb')   
533
+        else:
534
+            #print(o.shooting)
535
+            #if o.shooting > 0:
536
+                #print('oshooting')
537
+            #dif = e1 - e2
538
+            #o.shooting -= 1
539
+            g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
540
+            self.FSM.ToTransition('toShootShot')
541
+            o.stick.applyRotation([0,0,-.22], True)   
542
+            o.puck = False
543
+            o.mates.possession = False         
544
+        
545
+        
546
+        
547
+        
548
+        #print('wind shot')
549
+        #if self.FSM.stateLife > 20:
550
+            #self.FSM.ToTransition('toShootShot')
551
+    
552
+    def Exit(self):
553
+        pass
554
+
555
+#====================================  
556
+
557
+class ShootShot(State):
558
+    def __init__(self,FSM):
559
+        super(ShootShot, self).__init__(FSM)    
560
+        
561
+    def Enter(self):
562
+        self.FSM.stateLife = 1
563
+        super(ShootShot, self).Enter()  
564
+        o = self.FSM.owner
565
+        o.puck = False      
566
+        
567
+    def Execute(self):
568
+        self.FSM.stateLife += 1
569
+        o = self.FSM.owner
570
+        g = o.me
571
+        #print('shoot shot')
572
+        o.stick.applyRotation([0,0,-.22], True)   
573
+        o.puck = False         
574
+        
575
+        if self.FSM.stateLife > 20:
576
+            self.FSM.ToTransition('toGetPuck')
577
+    
578
+    def Exit(self):
579
+        pass
580
+
581
+#====================================  

+ 3
- 0
scripts/linkEmpty.blend View File

@@ -0,0 +1,3 @@
1
+version https://git-lfs.github.com/spec/v1
2
+oid sha256:d23a889cdc9c2ca661b49ccac257e3be73980f6c444f699db0149a3a5487ef60
3
+size 459492

+ 530
- 0
scripts/player.py View File

@@ -0,0 +1,530 @@
1
+import bge
2
+
3
+import math
4
+import mathutils
5
+import FSM
6
+import sound_man
7
+
8
+team_a_colors = [[.9,.9,.9,1], [.9,.1,.1,1], [.1, .1, .1, 1]]           
9
+team_b_colors = [[.1,.9,.1,1], [.1,.1,.1,1], [.3, .3, .3, 1]]
10
+
11
+#team_a_colors = [[.7,.7,.3,1], [.9,.1,.1,1], [.1, .1, .1, 1]]           
12
+#team_b_colors = [[.1,.3,.9,1], [.4,.1,.1,1], [.3, .3, .3, 1]]
13
+
14
+
15
+positions = [[3,0], [4,-3], [6, 3], [8, -4]]
16
+
17
+def run_camera(self):
18
+    
19
+    if self.camera == None:
20
+        scene = bge.logic.getCurrentScene()
21
+        self.camera = scene.objects['Camera']
22
+    else:    
23
+        target_dist = 8
24
+        opos = self.puck.worldPosition.x
25
+        cpos = self.camera.worldPosition.x
26
+        dist = cpos - opos
27
+        num = abs(dist - target_dist)
28
+        #print(opos + 10)
29
+        if opos > - 3 and opos < 6:
30
+            self.camera.worldPosition.x = opos + 10
31
+            
32
+class team:
33
+    def __init__(self, name, colors, user):
34
+        self.name = name
35
+        self.colors = colors
36
+        self.players = []
37
+        self.p_closest = []
38
+        self.possession = False
39
+        self.switch_player_frame = [0,0,0,0]
40
+        self.user = user
41
+        
42
+    def update(self, game):
43
+        
44
+        def sortClosestToPuck(e):
45
+            return e.cont.getDistanceTo(game.puck.worldPosition)
46
+        self.p_closest.sort(reverse=False, key=sortClosestToPuck)
47
+        
48
+        a_list = []
49
+        for x in self.players:
50
+            #a_list.append(str(x.FSM.FSM.curState.__class__.__name__))
51
+            a_list.append(x.user)
52
+        if self.name == 'a':
53
+            print(a_list)
54
+
55
+        
56
+class game:
57
+    def __init__(self, obj, cont):
58
+        self.scene = bge.logic.getCurrentScene()
59
+        self.frame = -1
60
+        self.team_a = []
61
+        self.team_b = []        
62
+        self.puck = None
63
+        self.score = [0, 0]
64
+        self.state = 'practice'
65
+        self.obj = obj
66
+        self.cont = cont    
67
+        self.players = [] 
68
+        self.team_possession = None
69
+        self.camera = None
70
+        self.puck_collision = True
71
+        self.puck_update = False
72
+        self.goal_a_e = self.scene.objects['goal_a_e']
73
+        self.goal_b_e = self.scene.objects['goal_b_e']
74
+        self.sound_man = sound_man.sound_manager()
75
+        self.num_p_a = 3
76
+        self.num_p_b = 3
77
+        self.team_a_user = 1
78
+        self.team_b_user = 0
79
+        
80
+        #team properties: name, colors, user
81
+        self.a_team = team('a', team_a_colors, 1)
82
+        self.b_team = team('b', team_b_colors, 0)
83
+        
84
+        self.FSM = FSM.GameFSM(self) 
85
+    
86
+    def load_players(self):
87
+        #do team a
88
+        if self.num_p_a > 0:
89
+            iter = self.num_p_a
90
+            while iter > 0:
91
+                
92
+                p1 = hockey_player(0, self.obj, self.cont)
93
+                p1.user = 0
94
+                pname = 'p' + str(iter)
95
+                aname = 'a' + str(iter)
96
+                p1.cont['name'] = aname
97
+                p1.stick['name'] = aname
98
+                p1.cont['pname'] = True
99
+                p1.stick['pname'] = True 
100
+                p1.cont['c_ref'] = p1       
101
+                self.team_a.append(p1)
102
+                self.players.append(p1)
103
+                self.a_team.players.insert(0, p1)
104
+
105
+                x = positions[iter -1][0] * -1
106
+                y = positions[iter -1][1] * -1 
107
+                p1.faceoff_pos = [x,y]               
108
+
109
+                p1.cont.worldPosition = [x, y, p1.cont.worldPosition.z]
110
+                
111
+                iter -= 1
112
+            self.a_team.p_closest = self.a_team.players.copy()    
113
+        #do team b
114
+        if self.num_p_b > 0:
115
+            iter = self.num_p_b
116
+            while iter > 0:
117
+                
118
+                p1 = hockey_player(1, self.obj, self.cont)
119
+                p1.user = 0
120
+                pname = 'p' + str(iter)
121
+                aname = 'b' + str(iter)
122
+                p1.cont['name'] = aname
123
+                p1.stick['name'] = aname                
124
+                p1.cont['pname'] = True
125
+                p1.stick['pname'] = True 
126
+                p1.cont['c_ref'] = p1       
127
+                self.team_b.append(p1)
128
+                self.players.append(p1)
129
+                self.b_team.players.insert(0, p1)                
130
+                x = positions[iter -1][0]
131
+                y = positions[iter -1][1]
132
+                p1.faceoff_pos = [x,y] 
133
+                p1.cont.worldPosition = [x, y, p1.cont.worldPosition.z]
134
+                iter -= 1                
135
+            self.b_team.p_closest = self.b_team.players.copy()  
136
+            
137
+                
138
+    def load_puck(self):
139
+        #scene = bge.logic.getCurrentScene()
140
+        o = self.scene.objectsInactive['puck']
141
+        self.puck = self.scene.addObject(o, self.obj, 0) 
142
+        self.puck['game'] = self
143
+        
144
+    def run(self):
145
+        #pass    
146
+        self.frame += 1
147
+        run_camera(self)
148
+        if self.team_a == []:
149
+            self.load_players()
150
+            self.load_puck()
151
+        
152
+        #update team
153
+        self.a_team.update(self)
154
+        self.b_team.update(self)
155
+        #update players
156
+        for t in self.team_a + self.team_b:
157
+            t.update()
158
+                 
159
+        p = []
160
+        for x in self.team_a:
161
+            p.append(x.state)
162
+        #print(p)
163
+                    
164
+        self.FSM.Execute() 
165
+        self.sound_man.update()   
166
+
167
+class hockey_player():
168
+    def __init__(self, team, other, contr):
169
+        scene = bge.logic.getCurrentScene()
170
+        self.me = other
171
+        g = self.me['game']
172
+        self.scene = scene
173
+        to = scene.objectsInactive['player_controller']
174
+        self.cont = scene.addObject(to, other, 0) 
175
+        to = scene.objectsInactive['base']
176
+        self.base = scene.addObject(to, other, 0)
177
+        to = scene.objectsInactive['body']
178
+        self.body = scene.addObject(to, other, 0) 
179
+        to = scene.objectsInactive['head']
180
+        self.head = scene.addObject(to, other, 0)         
181
+        to = scene.objectsInactive['stick']
182
+        self.stick = scene.addObject(to, other, 0) 
183
+        self.puck_empty = self.cont.children['sick_puck_empty'] 
184
+        self.puck_trigger = False
185
+        self.whisker_c_obj = self.cont.children['whisker_c'] 
186
+        self.whisker_r_obj = self.cont.children['whisker_r'] 
187
+        self.whisker_l_obj = self.cont.children['whisker_l']                 
188
+        self.whisker_c = None
189
+        self.whisker_r = None
190
+        self.whisker_l = None        
191
+        
192
+        self.stick_empty = self.stick.children['stick_empty']   
193
+        self.indicator_obj = self.cont.children['indicator']  
194
+        self.inicator = False
195
+        self.switch_player_frame = [0,0,0,0]
196
+        self.faceoff_pos = [0, 0, 0]           
197
+        self.team = team
198
+
199
+        self.teammates = []
200
+            
201
+        if self.team == 0:
202
+            self.mates = g.a_team
203
+            self.goal_t = g.goal_a_e
204
+            self.goal_d = g.goal_b_e
205
+            self.body.color = g.a_team.colors[0] 
206
+            self.body.children['stripe'].color = g.a_team.colors[1]         
207
+            self.head.color = g.a_team.colors[2]            
208
+        if self.team == 1:
209
+            self.mates = g.b_team
210
+            self.goal_t = g.goal_b_e
211
+            self.goal_d = g.goal_a_e   
212
+            self.body.color = g.b_team.colors[0]
213
+            self.body.children['stripe'].color = g.b_team.colors[1]
214
+            self.head.color = g.b_team.colors[2]
215
+                                   
216
+        self.contr = contr
217
+        self.state = 'chasing'
218
+        self.shooting = False
219
+        self.passing = 0
220
+        self.pass_id = 0
221
+        self.player_col = 'adfadf'
222
+        self.player_col_trig = False
223
+        self.controlled = False
224
+        self.contr2 = None
225
+        
226
+        self.puck = False
227
+        self.speed = 16
228
+        self.user = 0
229
+        
230
+        self.kb_ua = 0
231
+        self.kb_da = 0   
232
+        self.kb_la = 0
233
+        self.kb_ra = 0
234
+        self.kb_w = 0
235
+        self.kb_a = 0
236
+        self.kb_s = 0
237
+        self.kb_d = 0
238
+        self.kb_ls = 0
239
+        self.kb_sp = 0
240
+        self.turn_timer = 0
241
+        self.speed_tilt_timer = 0        
242
+        self.update_inputs()
243
+        
244
+        self.FSM = FSM.PlayerFSM(self)
245
+
246
+    def update_inputs(self):
247
+        keyboard = bge.logic.keyboard.inputs  
248
+        
249
+        self.last_kb_ua = self.kb_ua or 0
250
+        self.last_kb_da = self.kb_da
251
+        self.last_kb_la = self.kb_la
252
+        self.last_kb_ra = self.kb_ra
253
+        self.last_kb_w = self.kb_w
254
+        self.last_kb_a = self.kb_a
255
+        self.last_kb_s = self.kb_s
256
+        self.last_kb_d = self.kb_d
257
+        self.last_kb_ls = self.kb_ls
258
+        self.last_kb_sp = self.kb_sp
259
+
260
+        self.kb_ua = bge.logic.keyboard.inputs[bge.events.UPARROWKEY].values[-1]
261
+        self.kb_da = bge.logic.keyboard.inputs[bge.events.DOWNARROWKEY].values[-1]    
262
+        self.kb_la = bge.logic.keyboard.inputs[bge.events.LEFTARROWKEY].values[-1]
263
+        self.kb_ra = bge.logic.keyboard.inputs[bge.events.RIGHTARROWKEY].values[-1]
264
+        self.kb_w = bge.logic.keyboard.inputs[bge.events.WKEY].values[-1]
265
+        self.kb_a = bge.logic.keyboard.inputs[bge.events.AKEY].values[-1]    
266
+        self.kb_s = bge.logic.keyboard.inputs[bge.events.SKEY].values[-1]
267
+        self.kb_d = bge.logic.keyboard.inputs[bge.events.DKEY].values[-1]  
268
+        self.kb_ls = bge.logic.keyboard.inputs[bge.events.LEFTSHIFTKEY].values[-1]    
269
+        self.kb_sp = bge.logic.keyboard.inputs[bge.events.SPACEKEY].values[-1]    
270
+
271
+    def user_movement(self):
272
+        own = self.cont
273
+        if self.kb_w == 1:
274
+            self.speed_tilt_timer += 1
275
+            if own.linearVelocity.x < 2:
276
+                own.applyForce([13,0,0], True)
277
+            if self.kb_ls == 1:
278
+                if self.last_kb_ls == 0:
279
+                    self.speed_tilt_timer = 0
280
+                if own.linearVelocity.x < 4:
281
+                    own.applyForce([16,0,0], True)                    
282
+        else:
283
+            self.speed_tilt_timer = 0
284
+        if self.kb_s == 1:
285
+            if own.linearVelocity.x > -2:
286
+                own.applyForce([-13,0,0], True)
287
+        
288
+        tilt = .01#.005
289
+        tilt2 = .015#.01
290
+        time = 25  
291
+        time2 = 25 
292
+        aligned = False     
293
+        if self.kb_a == 1:
294
+            self.turn_timer += 1
295
+            own.applyRotation([0, 0, .04], True)
296
+            if self.turn_timer < time:
297
+                self.body.applyRotation([-tilt, 0, 0], True)
298
+                self.head.applyRotation([(tilt2 * -1.2), 0, 0], True)
299
+                #aligned = True                
300
+        elif self.kb_d == 1:
301
+            self.turn_timer += 1
302
+            own.applyRotation([0, 0, -.04], True)  
303
+            if self.turn_timer < time:
304
+                self.body.applyRotation([tilt, 0, 0], True)     
305
+                self.head.applyRotation([(tilt2 * 1.2), 0, 0], True)     
306
+                #aligned = True
307
+        else:
308
+            self.turn_timer = 0
309
+        
310
+        #print(self.turn_timer)
311
+        if self.speed_tilt_timer < time2 and self.speed_tilt_timer > 0:
312
+            self.body.applyRotation([0, tilt2, 0], True)     
313
+            self.head.applyRotation([0, (tilt2 * 1.2), 0], True) 
314
+                            
315
+
316
+        if not aligned:
317
+            
318
+            self.body.alignAxisToVect([0,0,1], 2, .02)
319
+            self.head.alignAxisToVect([0,0,1], 2, .02)            
320
+        #self.stick.alignAxisToVect([0,0,1], 2, .005)
321
+        
322
+        self.cont.linearVelocity.y *= .98   
323
+                 
324
+    def update_indicator(self):
325
+        #if self.state in ['possession', 'shooting']:
326
+        if self.puck or self.user:
327
+            self.indicator = True
328
+        else:
329
+            self.indicator = False
330
+        
331
+        if self.indicator:
332
+            if self.indicator_obj.color[3] < .5:
333
+               self.indicator_obj.color[3] += .05
334
+        else:
335
+            if self.indicator_obj.color[3] > 0:
336
+               self.indicator_obj.color[3] -= .05                        
337
+
338
+    def align_to_base(self):        
339
+        self.base.worldPosition = self.cont.worldPosition 
340
+        self.body.worldPosition = self.cont.worldPosition                
341
+        self.head.worldPosition = self.cont.worldPosition                
342
+        self.stick.worldPosition = self.cont.worldPosition                
343
+        self.cont.alignAxisToVect([0,0,1], 2, 1)
344
+        #base vector        
345
+        v = self.cont.getAxisVect([1,0,0])
346
+        #body vector
347
+        vb = self.body.getAxisVect([1,0,0])
348
+                                 
349
+        self.base.worldOrientation = self.cont.worldOrientation
350
+        self.body.alignAxisToVect(v, 0, .1)
351
+                        
352
+        #if self.state != 'possession':  
353
+        if self.FSM.FSM.curState.__class__.__name__ != 'PosesPuck':
354
+            self.stick.alignAxisToVect(vb, 0, .04)
355
+            #self.stick.alignAxisToVect(v, 0, .9)                
356
+        else:
357
+            self.stick.alignAxisToVect(v, 0, .9)    
358
+        self.stick.alignAxisToVect([0,0,1], 2, .9)    
359
+
360
+        self.head.alignAxisToVect(vb, 0, .15)   
361
+
362
+    def switch_player(self):
363
+        g = self.me['game']
364
+        self.mates.switch_player_frame.append(g.frame)
365
+        self.mates.switch_player_frame.pop(0)
366
+        
367
+        mates = self.mates.p_closest.copy()
368
+        mates.remove(self)
369
+        since_switch_a = g.frame - self.mates.switch_player_frame[2]
370
+        print(mates, since_switch_a)
371
+        for m in mates:
372
+            m.user = 0
373
+        if since_switch_a > 30:
374
+            
375
+            mates[0].user = 1
376
+            print('p1')
377
+        else:
378
+            mates[1].user = 1            
379
+            print('p2', since_switch_a)
380
+            
381
+        self.user = 0  
382
+        print('switch player')  
383
+            
384
+    def check_puck(self):
385
+        if self.FSM.FSM.stateLife > 120:
386
+            if self.puck_trigger:
387
+                print('pick up puck')
388
+                self.puck_trigger = False
389
+                for x in self.mates.players:
390
+                    x.puck = False
391
+                    x.user = 0
392
+                self.puck = True
393
+                if self.mates.user > 0:
394
+                    self.user = 1 
395
+                    print('check_puck function switching user') 
396
+                self.FSM.FSM.ToTransition('toPosesPuck')
397
+                self.state = 'possession' 
398
+              
399
+    def update(self):
400
+        if self.teammates == []:
401
+            self.puck = False
402
+            print(self.me['game'].team_a, self.me['game'].players)
403
+            if self.me['game'].team_a_user == 1:
404
+                if self.me['game'].team_a[2] == self:
405
+                    print('this is number 1')
406
+                    self.user = 1
407
+                else:
408
+                    self.user = 0                
409
+            if self.me['game'].team_b_user == 1:
410
+                if self.me['game'].team_b[0] == self:
411
+                    print('this is number 1')
412
+                    self.user = 1
413
+                else:
414
+                    self.user = 0                                    
415
+            for x in self.me['game'].players:
416
+                if x.cont.worldPosition != self.cont.worldPosition and self.team == x.team:
417
+                    self.teammates.append(x)
418
+        
419
+        self.update_indicator()
420
+        self.align_to_base()
421
+        self.FSM.Execute()
422
+        #self.check_puck()
423
+        state = str(self.FSM.FSM.curState.__class__.__name__)
424
+        
425
+        if self.puck == True and self.user == 0:
426
+            self.puck = False
427
+        u = []
428
+        for x in self.mates.players:
429
+            if x.puck == True:
430
+                if u != []:
431
+                    x.puck = False
432
+                u.append(x)
433
+        u2 = []
434
+        for x in self.mates.players:
435
+            if x.user == 1:
436
+                u2.append(x)                
437
+        
438
+        if self.user == 1:
439
+            self.update_inputs()             
440
+
441
+            e1 = self.cont.worldOrientation.to_euler().z
442
+            e2 = self.stick.worldOrientation.to_euler().z
443
+            dif = e1 - e2
444
+            
445
+            if self.kb_la == 1 and self.puck:
446
+                self.pass_id = 0
447
+                a = str(self.FSM.FSM.curState.__class__.__name__)
448
+                if state != 'Passing':
449
+                    self.FSM.FSM.ToTransition('toPassing')
450
+
451
+            if self.kb_ra == 1 and self.puck:
452
+                self.pass_id = 1
453
+                a = str(self.FSM.FSM.curState.__class__.__name__)
454
+                if state != 'Passing':
455
+                    self.FSM.FSM.ToTransition('toPassing')
456
+                                        
457
+            if self.kb_ua == 1 and self.puck == False:
458
+                self.stick.applyRotation([0, -.35, 0], True)                    
459
+                self.stick.applyMovement([.4, 0, 0], True)
460
+                if self.last_kb_ua == False:
461
+                    self.me['game'].sound_man.queue_sound(['check', self.cont, self.me['game'].camera])
462
+                    print('hit sound')
463
+            if self.kb_ua == 1 and self.puck == True:
464
+                a = str(self.FSM.FSM.curState.__class__.__name__)
465
+                if state != 'Dumping':
466
+                    self.FSM.FSM.ToTransition('toDumping')   
467
+
468
+            self.user_movement()                
469
+                
470
+def main(cont):
471
+    own = cont.owner
472
+    scene = bge.logic.getCurrentScene()      
473
+    me = scene.objects['main_empty']    
474
+    if 'inited' not in own:
475
+        own['inited'] = True
476
+        me['game'].team_a[0].contr2 = cont
477
+
478
+    own.worldPosition.z = .1
479
+    own.applyForce([0,0,1.8], False)       
480
+
481
+    own['c_ref'].player_col = cont.sensors['player_col'].hitObject
482
+
483
+def game_main(cont):
484
+    own = cont.owner
485
+    if 'inited' not in own:
486
+        own['inited'] = True
487
+        own['game'] = game(own, cont)
488
+        
489
+    own['game'].run()    
490
+    
491
+def puck(cont):
492
+    own = cont.owner
493
+    g = own['game']
494
+
495
+    if g.puck_update:  
496
+        if own.worldPosition.z < 0: 
497
+           own.worldPosition.z = 0 
498
+        if own.worldPosition.z > .5: 
499
+           own.worldPosition.z = .5           
500
+        if own.worldPosition.x > 12:
501
+            own.worldPosition.x = 11.5
502
+        if own.worldPosition.x < -12:
503
+            own.worldPosition.x = -11.5
504
+        if own.worldPosition.y > 7:
505
+            own.worldPosition.y = 6.5
506
+        if own.worldPosition.y < -7:
507
+            own.worldPosition.y = -6.5  
508
+            
509
+        if cont.sensors['puck-player'].hitObject is not None:
510
+            ho = cont.sensors['puck-player'].hitObject
511
+            if 'post' in ho:
512
+                print('POST!!!!')
513
+                g.sound_man.queue_sound(['post', g.puck, g.camera])                                
514
+          
515
+        if not g.a_team.possession and not g.b_team.possession:                  
516
+            if cont.sensors['puck-player'].hitObject is not None:
517
+                ho = cont.sensors['puck-player'].hitObject
518
+                for p in g.a_team.players + g.b_team.players:
519
+                    if ho == p.cont or ho == p.stick:
520
+                        p.puck_trigger = True
521
+                    else:
522
+                        p.puck_trigger = False
523
+                
524
+                o = cont.sensors['puck-player'].hitObject
525
+                if 'goal' in o:
526
+                    print('GOOOAAAALLL!!', o['team'])
527
+                    g.FSM.FSM.ToTransition('toGoalScored')
528
+
529
+                    if 'a2' in cont.sensors['puck-player'].hitObject['name']:
530
+                        pass

+ 137
- 0
scripts/sound_man.py View File

@@ -0,0 +1,137 @@
1
+#sound_man.py
2
+#shuvit sound effects manager
3
+
4
+import bge
5
+import aud
6
+
7
+def init_sounds(self):
8
+	#pop
9
+
10
+	self.check = sounds('check')
11
+	self.shoot = sounds('shoot')
12
+	self.post = sounds('post')		
13
+
14
+
15
+class sound_manager:
16
+	def __init__(self):
17
+		self.queue = []
18
+		self.history = []
19
+		self.h_queue = []
20
+		self.gd = bge.logic.globalDict
21
+		init_sounds(self)
22
+
23
+	def queue_sound(self, sound):
24
+		self.queue.append(sound)
25
+
26
+	def remove_sound(self, sound):
27
+		self.queue.remove(sound)
28
+
29
+	def play_queue(self):
30
+		if self.queue is not []:
31
+			self.h_queue = self.queue.copy()
32
+			for ev in self.queue:
33
+				#get function from string at position 0 of event
34
+				result = getattr(self, ev[0])
35
+				if result.loop:
36
+					result.loop_play(ev[1], ev[2], ev[3], ev[4])
37
+				else:
38
+					result.play(ev[1], ev[2])
39
+
40
+				self.queue.remove(ev)
41
+			self.queue = []	
42
+
43
+	def play_hist(self):
44
+		if self.h_queue is not []:
45
+			for ev in self.h_queue:
46
+				#get function from string at position 0 of event
47
+				result = getattr(self, ev[0])
48
+				#print(result)
49
+				#print(result.name)
50
+				if result.loop:
51
+					result.loop_play(ev[1], ev[2], ev[3], ev[4])
52
+				else:
53
+					result.play(ev[1], ev[2])
54
+
55
+				#self.queue.remove(ev)				
56
+
57
+	def update(self):
58
+		self.play_queue()
59
+		#print('queued sounds', self.queue)
60
+
61
+	def stop_sound(self, sound):
62
+		c = getattr(self, sound[0])
63
+		if c.handle_buffered:
64
+			c.handle_buffered.stop()
65
+
66
+	def h_Playback(self, frame):
67
+		
68
+		try:	
69
+			self.h_queue = self.history[frame]
70
+			#print(self.history[frame], self.queue, frame, 'replay queue')
71
+		except:
72
+			print('replay audio not playing', frame, len(self.history))
73
+		print('h_queue', self.h_queue, frame)
74
+		if self.h_queue is not []:
75
+			for ev in self.h_queue:
76
+				result = getattr(self, ev[0])
77
+				if result.loop:
78
+					result.loop_play(ev[1], ev[2], ev[3], ev[4])
79
+				else:
80
+					result.play(ev[1], ev[2])
81
+
82
+
83
+class sounds(sound_manager):
84
+	def __init__(self, name):
85
+		self.name = name
86
+		self.obj = None
87
+		self.loop = False
88
+		self.pingpong = False
89
+		self.listener_obj = None
90
+		self.pitch = 1.0	
91
+		self.volume = 0.9
92
+		self.device = aud.device()
93
+		self.path = bge.logic.expandPath('//sounds')
94
+		self.factory = aud.Factory(self.path + '/' + self.name + '.wav')
95
+		self.factory_buffered = aud.Factory.buffer(self.factory)
96
+		self.handle_buffered = None
97
+
98
+	def play(self, obj, listener):
99
+		
100
+		scene = bge.logic.getCurrentScene()
101
+		self.device.distance_model = aud.AUD_DISTANCE_MODEL_LINEAR
102
+		self.device.listener_location = obj.worldPosition
103
+		self.device.listener_velocity = obj.getLinearVelocity()
104
+		self.device.volume = self.volume
105
+
106
+		handle_buffered = self.device.play(self.factory_buffered)
107
+		handle_buffered.relative = False
108
+		handle_buffered.location = listener.worldPosition
109
+		handle_buffered.velocity = listener.getLinearVelocity()
110
+		handle_buffered.distance_maximum = 25
111
+		handle_buffered.distance_reference = 1
112
+
113
+        
114
+	def loop_play(self, obj, listener, v, p):
115
+		
116
+		scene = bge.logic.getCurrentScene()
117
+
118
+		self.device.distance_model = aud.AUD_DISTANCE_MODEL_LINEAR
119
+		self.device.listener_location = obj.worldPosition
120
+		self.device.listener_velocity = obj.getLinearVelocity()
121
+		
122
+		if not self.handle_buffered or not self.handle_buffered.status:
123
+			self.handle_buffered = self.device.play(self.factory_buffered)
124
+		self.factory_buffered.loop(-1)
125
+		
126
+		if self.pingpong:
127
+			self.factory_buffered.pingpong()
128
+		
129
+		self.handle_buffered.volume = v
130
+		self.handle_buffered.pitch = p
131
+		self.handle_buffered.relative = False
132
+		self.handle_buffered.location = listener.worldPosition
133
+		self.handle_buffered.velocity = listener.getLinearVelocity()
134
+		self.handle_buffered.distance_maximum = 50
135
+		self.handle_buffered.distance_reference = .1	
136
+		
137
+

+ 64
- 0
scripts/utils.py View File

@@ -0,0 +1,64 @@
1
+import bge
2
+
3
+def update_whiskers(self):
4
+    o = self
5
+    wco = o.whisker_c_obj
6
+    wro = o.whisker_r_obj
7
+    wlo = o.whisker_l_obj
8
+    wc = o.whisker_c
9
+    wr = o.whisker_r
10
+    wl = o.whisker_l        
11
+    
12
+    cc = [0,0,1]
13
+    rc = [0,1,0]
14
+    lc = [0,1,0]
15
+    
16
+    
17
+    wc = o.cont.rayCast(wco.worldPosition, 
18
+                        o.cont.worldPosition, 
19
+                        dist = 0, 
20
+                        prop = 'collisionadf', 
21
+                        face = 0, 
22
+                        xray = 1,
23
+                        poly = 0,
24
+                        mask = 1)
25
+                        
26
+
27
+    wr = o.cont.rayCast(wro.worldPosition, 
28
+                        o.cont.worldPosition, 
29
+                        dist = 0, 
30
+                        prop = 'collision', 
31
+                        face = 0, 
32
+                        xray = 1,
33
+                        poly = 0,
34
+                        mask = 1)
35
+                        
36
+
37
+    wl = o.cont.rayCast(wlo.worldPosition, 
38
+                        o.cont.worldPosition, 
39
+                        dist = 0, 
40
+                        prop = 'collision', 
41
+                        face = 0, 
42
+                        xray = 1,
43
+                        poly = 0,
44
+                        mask = 1)
45
+                                                
46
+                                                
47
+    if wc[0]:
48
+        cc = [1,0,0]
49
+        if 'puck' in wc[0]:
50
+            cc = [1,1,0]
51
+    if wr[0]:
52
+        rc = [1,0,0]
53
+        if 'puck' in wr[0]:
54
+            cc = [1,1,0]        
55
+    if wl[0]:
56
+        lc = [1,0,0]   
57
+        if 'puck' in wl[0]:
58
+            cc = [1,1,0]        
59
+            #print(wl[0])             
60
+    
61
+    bge.render.drawLine(o.cont.worldPosition, wco.worldPosition, cc)
62
+    bge.render.drawLine(o.cont.worldPosition, wlo.worldPosition, lc)
63
+    bge.render.drawLine(o.cont.worldPosition, wro.worldPosition, rc)        
64
+            

+ 3
- 0
sounds/check.wav View File

@@ -0,0 +1,3 @@
1
+version https://git-lfs.github.com/spec/v1
2
+oid sha256:37c72948d61bfc11063a063ca80b18ac1a3efcd4bcc821a88b2cb6710620c1fa
3
+size 20264

+ 3
- 0
sounds/post.wav View File

@@ -0,0 +1,3 @@
1
+version https://git-lfs.github.com/spec/v1
2
+oid sha256:c17761b4acc7944b3bbdd00cb80fc9ebdf5cb1f1d8bf1831d058154fd03fdc1b
3
+size 86678

+ 3
- 0
sounds/shoot.wav View File

@@ -0,0 +1,3 @@
1
+version https://git-lfs.github.com/spec/v1
2
+oid sha256:897e475426ced96d9b3dfc46d67d8e099b1fb26d3b54e2621e6f3e0cf29ba80c
3
+size 49158

Loading…
Cancel
Save