shuvit 4 years ago
parent
commit
e20987fedb
10 changed files with 1143 additions and 220 deletions
  1. 3
    0
      assets/zamboni.blend
  2. 2
    2
      game.blend
  3. 87
    12
      scripts/FSM.py
  4. 33
    0
      scripts/StatesCamera.py
  5. 64
    7
      scripts/StatesGame.py
  6. 462
    105
      scripts/StatesPlayer.py
  7. 33
    0
      scripts/StatesPuck.py
  8. 183
    0
      scripts/StatesTeam.py
  9. 203
    89
      scripts/player.py
  10. 73
    5
      scripts/utils.py

+ 3
- 0
assets/zamboni.blend View File

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

+ 2
- 2
game.blend View File

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

+ 87
- 12
scripts/FSM.py View File

@@ -2,6 +2,7 @@ import bge
2 2
 
3 3
 import StatesGame
4 4
 import StatesPlayer
5
+import StatesTeam
5 6
    
6 7
 #====================================
7 8
 class Transition(object):
@@ -54,6 +55,58 @@ class FSM(object):
54 55
 Char = type("Char",(object,),{})
55 56
 
56 57
 #===================================
58
+        
59
+class GameFSM(Char):
60
+    def __init__(self, owner):
61
+        self.FSM = FSM(self, owner)
62
+        self.owner = owner
63
+        
64
+        state_list = [
65
+        'MatchIntro',
66
+        'FaceOff',
67
+        'FaceoffIntro',
68
+        'InPlay',
69
+        'GoalScored']
70
+        
71
+        for s in state_list:
72
+            self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
73
+            t = 'to' + s
74
+            self.FSM.AddTransition(t, Transition(s))
75
+        
76
+        if self.FSM.curState == None:
77
+            self.FSM.SetState('MatchIntro')
78
+    
79
+    def Execute(self):
80
+        self.FSM.Execute(self.owner)    
81
+
82
+#===================================
83
+
84
+class TeamFSM(Char):
85
+    def __init__(self, owner):
86
+        self.FSM = FSM(self, owner)
87
+        self.owner = owner
88
+        
89
+        state_list = [
90
+        'Chase',
91
+        'Defense',
92
+        'Offence',
93
+        'Pout',
94
+        'Celebrate',
95
+        'Faceoff',
96
+        'MatchIntro']
97
+        
98
+        for s in state_list:
99
+            self.FSM.AddState(s, getattr(StatesTeam, s)(self.FSM))
100
+            t = 'to' + s
101
+            self.FSM.AddTransition(t, Transition(s))
102
+        
103
+        if self.FSM.curState == None:
104
+            self.FSM.SetState('MatchIntro')
105
+    
106
+    def Execute(self):
107
+        self.FSM.Execute(self.owner)               
108
+             
109
+#====================================    
57 110
 
58 111
 class PlayerFSM(Char):
59 112
     def __init__(self, owner):
@@ -63,6 +116,7 @@ class PlayerFSM(Char):
63 116
         state_list = [
64 117
         'Shooting',
65 118
         'GetPuck',
119
+        'GetPuckUser',
66 120
         'Passing',
67 121
         'DefendPuck',
68 122
         'PosesPuck',
@@ -79,7 +133,12 @@ class PlayerFSM(Char):
79 133
         'WindDump',
80 134
         'ShootDump',
81 135
         'WindPass',
82
-        'ShootPass']
136
+        'ShootPass',
137
+        'ReceivePass', 
138
+        'DefendNet',
139
+        'DefendPursuePuck',
140
+        'DefendThirdMan',
141
+        'OffencePuck']
83 142
         
84 143
         for s in state_list:
85 144
             self.FSM.AddState(s, getattr(StatesPlayer, s)(self.FSM))
@@ -92,19 +151,36 @@ class PlayerFSM(Char):
92 151
     def Execute(self):
93 152
         self.FSM.Execute(self.owner)    
94 153
         
95
-#===================================
154
+#=================================== 
155
+
156
+class CameraFSM(Char):
157
+    def __init__(self, owner):
158
+        self.FSM = FSM(self, owner)
159
+        self.owner = owner
96 160
         
97
-class GameFSM(Char):
161
+        state_list = [
162
+        'Example']
163
+        
164
+        for s in state_list:
165
+            self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
166
+            t = 'to' + s
167
+            self.FSM.AddTransition(t, Transition(s))
168
+        
169
+        if self.FSM.curState == None:
170
+            self.FSM.SetState('Example')
171
+    
172
+    def Execute(self):
173
+        self.FSM.Execute(self.owner)    
174
+
175
+#===================================
176
+
177
+class PuckFSM(Char):
98 178
     def __init__(self, owner):
99 179
         self.FSM = FSM(self, owner)
100 180
         self.owner = owner
101 181
         
102 182
         state_list = [
103
-        'MatchIntro',
104
-        'FaceOff',
105
-        'FaceoffIntro',
106
-        'InPlay',
107
-        'GoalScored']
183
+        'Example']
108 184
         
109 185
         for s in state_list:
110 186
             self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
@@ -112,10 +188,9 @@ class GameFSM(Char):
112 188
             self.FSM.AddTransition(t, Transition(s))
113 189
         
114 190
         if self.FSM.curState == None:
115
-            self.FSM.SetState('MatchIntro')
191
+            self.FSM.SetState('Example')
116 192
     
117 193
     def Execute(self):
118
-        self.FSM.Execute(self.owner)       
119
-             
120
-#====================================     
194
+        self.FSM.Execute(self.owner)    
121 195
 
196
+#===================================

+ 33
- 0
scripts/StatesCamera.py View File

@@ -0,0 +1,33 @@
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['game']
30
+        #self.FSM.ToTransition('toNewState')
31
+    
32
+    def Exit(self):
33
+        pass

+ 64
- 7
scripts/StatesGame.py View File

@@ -40,7 +40,10 @@ class FaceOff(State):
40 40
         super(FaceOff, self).Enter() 
41 41
         g = self.FSM.owner
42 42
         g.sound_man.queue_sound(['whistle', g.center_ice, g.camera])
43
-        print('whistling')       
43
+        #print('whistling')       
44
+
45
+        g.a_team.FSM.FSM.ToTransition('toFaceoff')
46
+        g.b_team.FSM.FSM.ToTransition('toFaceoff')
44 47
         
45 48
     def Execute(self):
46 49
         self.FSM.stateLife += 1
@@ -57,11 +60,13 @@ class FaceOff(State):
57 60
             #g.puck.worldPosition = [0,0,40]
58 61
             g.puck_update = True
59 62
             self.FSM.ToTransition('toInPlay')
63
+            g.a_team.FSM.FSM.ToTransition('toChase')
64
+            g.b_team.FSM.FSM.ToTransition('toChase')
60 65
             g.sound_man.queue_sound(['puck_drop', g.center_ice, g.camera])
61 66
 
62 67
                 
63 68
             
64
-        print('faceoff')
69
+        #print('faceoff')
65 70
     def Exit(self):
66 71
         pass   
67 72
     
@@ -80,13 +85,13 @@ class FaceoffIntro(State):
80 85
         
81 86
     def Execute(self):
82 87
         self.FSM.stateLife += 1
83
-        print('faceoff intro')
88
+        #print('faceoff intro')
84 89
         if self.FSM.stateLife > 240:
85 90
 
86 91
             self.FSM.ToTransition('toFaceOff')
87 92
                 
88 93
             
89
-        print('faceoff')
94
+        #print('faceoff')
90 95
     def Exit(self):
91 96
         pass        
92 97
     
@@ -104,8 +109,21 @@ class GoalScored(State):
104 109
         
105 110
     def Execute(self):
106 111
         self.FSM.stateLife += 1
107
-        o = self.FSM.owner
108
-        print('GOOOOOAAAALLL')
112
+        g = self.FSM.owner
113
+
114
+        if g.a_team.scored == True:
115
+            g.a_team.scored = False
116
+            self.FSM.ToTransition('toFaceoffIntro')
117
+            g.a_team.FSM.FSM.ToTransition('toCelebrate')
118
+            g.b_team.FSM.FSM.ToTransition('toPout')
119
+
120
+        if g.b_team.scored == True:
121
+            g.b_team.scored = False
122
+            self.FSM.ToTransition('toFaceoffIntro')
123
+            g.b_team.FSM.FSM.ToTransition('toCelebrate')
124
+            g.a_team.FSM.FSM.ToTransition('toPout')    
125
+
126
+        #print('GOOOOOAAAALLL')
109 127
         if self.FSM.stateLife > 340:
110 128
             self.FSM.ToTransition('toFaceoffIntro')
111 129
         #print('goal')
@@ -122,11 +140,50 @@ class InPlay(State):
122 140
         
123 141
     def Execute(self):
124 142
         self.FSM.stateLife += 1
125
-        o = self.FSM.owner
143
+        g = self.FSM.owner
144
+        g.clock_time += 1
145
+        #print('clock_time', self.FSM.owner.clock_time)
126 146
 
127 147
         #if self.FSM.stateLife > 20:
128 148
             #self.FSM.ToTransition('toGoalScored')
129 149
         #print('inplay')
150
+
151
+        #update possession
152
+        ta = False
153
+        tb = False
154
+        
155
+        #print(g.a_team.possession)
156
+
157
+        for p in g.a_team.players:
158
+            if p.puck:
159
+                #print('this guy has the puck', p)
160
+                ta = True
161
+                break
162
+        for p in g.b_team.players:
163
+            if p.puck:
164
+                #print('this guy has the puck', p)
165
+                tb = True
166
+                break
167
+
168
+        if not ta and not tb:
169
+            if g.a_team.FSM.FSM.curState.__class__.__name__ != 'Chase':
170
+                g.a_team.FSM.FSM.ToTransition('toChase')
171
+            if g.b_team.FSM.FSM.curState.__class__.__name__ != 'Chase':
172
+                g.b_team.FSM.FSM.ToTransition('toChase')                 
173
+
174
+        if ta:
175
+            if g.a_team.FSM.FSM.curState.__class__.__name__ != 'Offence':
176
+                g.a_team.FSM.FSM.ToTransition('toOffence')   
177
+                g.b_team.FSM.FSM.ToTransition('toDefense')    
178
+        if tb:
179
+            if g.a_team.FSM.FSM.curState.__class__.__name__ != 'Offence':
180
+                g.b_team.FSM.FSM.ToTransition('toOffence')   
181
+                g.a_team.FSM.FSM.ToTransition('toDefense')    
182
+
183
+
184
+                #g.b_team.FSM.FSM.ToTransition('tooOffence')
185
+
186
+
130 187
     def Exit(self):
131 188
         pass      
132 189
     

+ 462
- 105
scripts/StatesPlayer.py View File

@@ -1,4 +1,5 @@
1 1
 import utils
2
+from mathutils import Vector
2 3
 
3 4
 State = type("State", (object,), {})
4 5
 #====================================     
@@ -50,24 +51,22 @@ class GetPuck(State):
50 51
         o = self.FSM.owner
51 52
         g = o.me['game']
52 53
         utils.update_whiskers(o)
53
-        if self.FSM.stateLife > 30:
54
-            if o.puck_trigger:
55
-                o.puck_trigger = False
56
-                o.puck = True
57
-                for x in o.mates.players:
58
-                    x.user = 0
59
-                o.user = 1
60
-                self.FSM.ToTransition('toPosesPuck')
54
+        utils.check_puck_collision(self, o)
55
+
61 56
         if o.user == 1:
62 57
             o.update_inputs() 
63
-            if self.FSM.stateLife > 10:
64
-                #if o.kb_da == 0 and o.last_kb_da == 1:
65
-                if o.mates.user_input.i_da == 0 and o.mates.user_input.i_last_da == 1:     
58
+            if self.FSM.stateLife > 2:
59
+                if o.mates.user_input.i_da == 1 and o.mates.user_input.i_last_da == 0:     
66 60
                     o.switch_player()
67
-                    #print('fsm switch')
61
+                    o.puck = False
62
+                    #o.user = 0
63
+                    self.FSM.stateLife = 0
64
+                    #print('fsm switch', o.user)
68 65
                 o.check_check()
69
-                # if o.kb_ua == 1:
70
-                #     self.FSM.ToTransition('toCheckMissOn')
66
+
67
+        utils.getPlayerOrders(o, g)        
68
+        if o.orders != None:
69
+            self.FSM.ToTransition(o.orders)
71 70
 
72 71
         if o.team == 1:
73 72
             self.FSM.ToTransition('toDefendPuck')
@@ -75,6 +74,50 @@ class GetPuck(State):
75 74
     def Exit(self):
76 75
         pass
77 76
 
77
+
78
+class GetPuckUser(State):
79
+    def __init__(self,FSM):
80
+        super(GetPuckUser, self).__init__(FSM)    
81
+        
82
+    def Enter(self):
83
+        self.FSM.stateLife = 1
84
+        super(GetPuckUser, self).Enter()  
85
+        o = self.FSM.owner      
86
+        o.puck_trigger = False
87
+        #o.last_kb_da = 0
88
+        
89
+    def Execute(self):
90
+        self.FSM.stateLife += 1
91
+        o = self.FSM.owner
92
+        g = o.me['game']
93
+        utils.update_whiskers(o)
94
+        utils.check_puck_collision(self, o)
95
+
96
+        if o.user == 1:
97
+            o.update_inputs() 
98
+            if self.FSM.stateLife > 2:
99
+                if o.mates.user_input.i_da == 1 and o.mates.user_input.i_last_da == 0:     
100
+                    o.switch_player()
101
+                    o.puck = False
102
+                    #o.user = 0
103
+                    self.FSM.stateLife = 0
104
+                    #print('fsm switchb')
105
+                o.check_check()
106
+
107
+        utils.check_puck_collision(self, o)
108
+
109
+        utils.getPlayerOrders(o, g)        
110
+        if o.orders != None:
111
+            self.FSM.ToTransition(o.orders)
112
+
113
+
114
+        if o.team == 1:
115
+            self.FSM.ToTransition('toDefendPuck')
116
+    
117
+    def Exit(self):
118
+        pass
119
+
120
+
78 121
 #====================================     
79 122
     
80 123
 class PosesPuck(State):
@@ -87,7 +130,8 @@ class PosesPuck(State):
87 130
         self.FSM.stateLife = 1
88 131
         o = self.FSM.owner
89 132
         g = o.me['game'] 
90
-        o.puck_trigger = False       
133
+        o.puck_trigger = False 
134
+        o.orders = None      
91 135
         if o.team == 0:
92 136
             g.team_possession = 1
93 137
         if o.team == 1:
@@ -97,26 +141,33 @@ class PosesPuck(State):
97 141
         o = self.FSM.owner
98 142
         g = o.me['game']
99 143
         self.FSM.stateLife += 1
100
-        #print('possessing')
101
-        #print(o.kb_da, o.state)
144
+
102 145
         #ai        
103 146
         if o.mates.user == 0:
104
-            if self.FSM.stateLife < 260:
147
+            #print('why are we controlling this')
148
+            if self.FSM.stateLife < 26000:
105 149
                 g.puck.worldPosition = o.stick_empty.worldPosition
106 150
                 g.puck.linearVelocity = [0,0,0]  
107 151
               
108
-            #print('doing puck ai', self.FSM.stateLife)
109
-            if self.FSM.stateLife > 260:
152
+            if self.FSM.stateLife > 26000:
110 153
                 g.puck.applyForce([1,0,0], True)
111 154
                 o.puck = False
112
-            if self.FSM.stateLife > 300:
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')
162
+
163
+
164
+    
165
+            if self.FSM.stateLife > 3000:
113 166
                 self.FSM.ToTransition('toDefendPuck') 
114 167
                 o.mates.possession = False              
115 168
                 o.puck = False
116 169
         #user  
117
-#        elif o.state != 'chasing':
118
-#            g.puck.worldPosition = o.stick_empty.worldPosition
119
-#            g.puck.linearVelocity = [0,0,0]  
170
+
120 171
         else:
121 172
             #check inputs
122 173
             o.update_inputs()    
@@ -125,14 +176,23 @@ class PosesPuck(State):
125 176
             #print(o.kb_da)             
126 177
             #if o.kb_da == 1 and o.last_kb_da == 0:
127 178
             if o.mates.user_input.i_da == 1 and o.mates.user_input.i_last_da == 0: 
128
-                print('--- wind shot')
179
+                #print('--- wind shot')
129 180
                 self.FSM.ToTransition('toWindShot')    
130 181
             #if o.kb_ua == 1 and o.last_kb_ua == 0:
131 182
             if o.mates.user_input.i_ua == 1 and o.mates.user_input.i_last_ua == 0:                 
132
-                print('--- wind dump')
133
-                self.FSM.ToTransition('toWindDump')             
134
-                
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
+
135 189
             o.user_movement()
190
+
191
+        if o.mates.user_input.type == 0:
192
+            utils.getPlayerOrders(o, g)        
193
+            if o.orders != None:
194
+                self.FSM.ToTransition(o.orders)
195
+
136 196
                 
137 197
     def Exit(self):
138 198
         o = self.FSM.owner
@@ -148,7 +208,7 @@ class DefendPuck(State):
148 208
         super(DefendPuck, self).__init__(FSM)    
149 209
         
150 210
     def Enter(self):
151
-        print('Preparing to defend.')
211
+        #print('Preparing to defend.')
152 212
         self.FSM.stateLife = 1
153 213
         super(DefendPuck, self).Enter()
154 214
         
@@ -166,60 +226,14 @@ class DefendPuck(State):
166 226
 
167 227
         o.simple_align(.04)    
168 228
 
169
-        # if g.puck.worldPosition.y > 0:
170
-        #     y = -4
171
-        # else:
172
-        #     y = 4
173
-        # if o.player_col:
174
-        #     #print('hitting', o.player_col) 
175
-        #     pass   
229
+        
176 230
 
177
-    
231
+        utils.check_puck_collision(self, o)
178 232
 
179
-        # if o == g.players[1]:
180
-        #     poi = [0, y, o.cont.worldPosition.z]
181
-        #     if g.puck.worldPosition.x > 4:
182
-        #         poi = [-6, y, o.cont.worldPosition.z]    
183
-        #     if g.puck.worldPosition.x < -4:
184
-        #         poi = [4, y, o.cont.worldPosition.z]                    
185
-        #     #distance to point of interest
186
-        #     dto_poi = o.cont.getDistanceTo(poi)
187
-        #     if dto_poi > .5:
188
-        #         v = o.cont.getVectTo(poi)
189
-        #         o.cont.alignAxisToVect(v[1], 0, .1)
190
-        #         if o.cont.linearVelocity.x < 2:
191
-        #             o.cont.applyForce([o.speed, 0, 0], True)
192
-        #     else:
193
-        #         v = o.cont.getVectTo(g.puck)
194
-        #         o.cont.alignAxisToVect(v[1], 0, .05)                
195
-        #         o.cont.linearVelocity = [0, 0, 0]
196
-                
197
-        #     o.align_to_base()
198
-        #     if abs(o.cont.linearVelocity.y) > .5:
199
-        #         o.cont.linearVelocity *= .5
200
-                
201
-        # if o == g.players[2]:
202
-        #     poi = [0-6, -y, o.cont.worldPosition.z]
203
-        #     if g.puck.worldPosition.x > 4:
204
-        #         poi = [6-6, -y, o.cont.worldPosition.z]    
205
-        #     if g.puck.worldPosition.x < -4:
206
-        #         poi = [-4-6, y, o.cont.worldPosition.z]                    
207
-        #     #distance to point of interest
208
-        #     dto_poi = o.cont.getDistanceTo(poi)
209
-        #     if dto_poi > .5:
210
-        #         v = o.cont.getVectTo(poi)
211
-        #         o.cont.alignAxisToVect(v[1], 0, .1)
212
-        #         if o.cont.linearVelocity.x < 2:
213
-        #             o.cont.applyForce([o.speed, 0, 0], True)
214
-        #     else:
215
-        #         v = o.cont.getVectTo(g.puck)
216
-        #         o.cont.alignAxisToVect(v[1], 0, .05)                
217
-        #         o.cont.linearVelocity = [0, 0, 0]
218
-                
219
-        #     o.align_to_base()
220
-        #     if abs(o.cont.linearVelocity.y) > .5:
221
-        #         o.cont.linearVelocity *= .5
222
-        
233
+        utils.getPlayerOrders(o, g)        
234
+        if o.orders != None:
235
+            #print(o.orders)
236
+            self.FSM.ToTransition(o.orders)
223 237
         
224 238
     def Exit(self):
225 239
         pass         
@@ -231,7 +245,7 @@ class Passing(State):
231 245
         super(Passing, self).__init__(FSM)    
232 246
         
233 247
     def Enter(self):
234
-        print('Preparing to Passing.')
248
+        #print('Preparing to Passing.')
235 249
         self.FSM.stateLife = 1
236 250
         super(Passing, self).Enter()
237 251
         o = self.FSM.owner        
@@ -243,7 +257,7 @@ class Passing(State):
243 257
 
244 258
         players.sort(reverse=False, key=sortClosestToPlayer)        
245 259
         players.remove(o)
246
-        print(players)
260
+        #print(players)
247 261
         self.closest = players
248 262
 
249 263
     def Execute(self):
@@ -294,10 +308,10 @@ class Passing(State):
294 308
                     o.state = 'chasing'
295 309
                     self.FSM.ToTransition('toGetPuck')
296 310
                     #print('exit')
297
-                o.puck = False
311
+                #o.puck = False
298 312
             
299 313
     def Exit(self):
300
-        print('Finished Passing')   
314
+        #print('Finished Passing')   
301 315
         o = self.FSM.owner        
302 316
         g = o.me['game']
303 317
         o.puck = False 
@@ -313,7 +327,7 @@ class Shooting(State):
313 327
         super(Shooting, self).__init__(FSM)  
314 328
         
315 329
     def Enter(self):
316
-        print('Starting to Shooting.')
330
+        #print('Starting to Shooting.')
317 331
         super(Shooting, self).Enter()
318 332
         self.FSM.stateLife = 1
319 333
         
@@ -322,7 +336,7 @@ class Shooting(State):
322 336
 
323 337
             
324 338
     def Exit(self):
325
-        print('Waking up from Shooting.')          
339
+        #print('Waking up from Shooting.')          
326 340
         o = self.FSM.owner        
327 341
         g = o.me['game']
328 342
         o.puck = False  
@@ -488,8 +502,12 @@ class WindDump(State):
488 502
         
489 503
     def Enter(self):
490 504
         self.FSM.stateLife = 1
491
-        super(WindDump, self).Enter()        
492 505
         
506
+        o = self.FSM.owner
507
+        o.puck = True        
508
+        
509
+        super(WindDump, self).Enter()
510
+
493 511
     def Execute(self):
494 512
         self.FSM.stateLife += 1
495 513
         o = self.FSM.owner
@@ -515,7 +533,7 @@ class WindDump(State):
515 533
             g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
516 534
             self.FSM.ToTransition('toShootShot')
517 535
             o.stick.applyRotation([0,0,-.22], True)   
518
-            o.puck = False
536
+            #o.puck = False
519 537
             o.mates.possession = False         
520 538
         
521 539
     def Exit(self):
@@ -532,7 +550,7 @@ class ShootDump(State):
532 550
         super(ShootDumpm, self).Enter()  
533 551
         o = self.FSM.owner
534 552
         g = o.me['game']
535
-        o.puck = False      
553
+        #o.puck = False      
536 554
         g.puck.worldOrientation = o.base.worldOrientation
537 555
         g.puck.applyForce([200,0,0], True)
538 556
     def Execute(self):
@@ -540,13 +558,14 @@ class ShootDump(State):
540 558
         o = self.FSM.owner
541 559
         g = o.me['game']
542 560
         o.stick.applyRotation([0,0,-.22], True)   
543
-        o.puck = False         
561
+        #o.puck = False         
544 562
         
545 563
         if self.FSM.stateLife > 20:
546 564
             self.FSM.ToTransition('toGetPuck')
547 565
     
548 566
     def Exit(self):
549
-        pass
567
+        o = self.FSM.owner
568
+        o.puck = False
550 569
 
551 570
 
552 571
 class WindPass(State):
@@ -559,6 +578,7 @@ class WindPass(State):
559 578
 
560 579
         o = self.FSM.owner        
561 580
         g = o.me['game']
581
+        self.target = None
562 582
         players = o.mates.players.copy()
563 583
 
564 584
         def sortClosestToPlayer(e):
@@ -566,9 +586,9 @@ class WindPass(State):
566 586
             
567 587
         players.sort(reverse=False, key=sortClosestToPlayer)        
568 588
         players.remove(o)
569
-        print(players)
589
+        #print(players)
570 590
         self.closest = players
571
-
591
+        o.puck = True
572 592
         #set o.pass_id       
573 593
         
574 594
     def Execute(self):
@@ -578,16 +598,19 @@ class WindPass(State):
578 598
         
579 599
 
580 600
 
581
-                  
601
+        #o.puck = True          
582 602
     
583 603
         #if o.kb_la == 1 or o.kb_ra == 1:
584 604
         if o.mates.user_input.i_la == 1 or o.mates.user_input.i_ra == 1:                         
585 605
             #if o.kb_la == 1:
606
+            
586 607
             if o.mates.user_input.i_la == 1:                 
587 608
                 v = o.cont.getVectTo(self.closest[0].puck_empty)
609
+                self.target = self.closest[0]
588 610
             #elif o.kb_ra == 1:  
589 611
             elif o.mates.user_input.i_ra == 1:             
590 612
                 v = o.cont.getVectTo(self.closest[1].puck_empty)
613
+                self.target = self.closest[1]
591 614
             stre = .1
592 615
             o.stick.alignAxisToVect(v[1], 0, stre)        
593 616
             o.cont.alignAxisToVect(v[1], 0, stre)                        
@@ -603,10 +626,13 @@ class WindPass(State):
603 626
             g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
604 627
             self.FSM.ToTransition('toShootShot')
605 628
             o.stick.applyRotation([0,0,-.22], True)   
606
-            o.puck = False
629
+            #o.puck = False
607 630
             o.mates.possession = False         
608 631
         
609 632
     def Exit(self):
633
+        if self.target != None:
634
+            self.target.FSM.FSM.ToTransition('toReceivePass')
635
+            print('receive')
610 636
         pass
611 637
 
612 638
 #====================================  
@@ -620,7 +646,7 @@ class ShootPass(State):
620 646
         super(ShootPass, self).Enter()  
621 647
         o = self.FSM.owner
622 648
         g = o.me['game']
623
-        o.puck = False      
649
+        #o.puck = False      
624 650
         g.puck.worldOrientation = o.base.worldOrientation
625 651
         g.puck.applyForce([200,0,0], True)
626 652
     def Execute(self):
@@ -628,13 +654,14 @@ class ShootPass(State):
628 654
         o = self.FSM.owner
629 655
         g = o.me['game']
630 656
         o.stick.applyRotation([0,0,-1.72], True)   
631
-        o.puck = False         
657
+        #o.puck = False         
632 658
         
633 659
         if self.FSM.stateLife > 20:
634 660
             self.FSM.ToTransition('toGetPuck')
635 661
     
636 662
     def Exit(self):
637
-        pass
663
+        o = self.FSM.owner
664
+        o.puck = False         
638 665
 
639 666
                  
640 667
 #====================================                      
@@ -645,6 +672,9 @@ class WindShot(State):
645 672
         
646 673
     def Enter(self):
647 674
         self.FSM.stateLife = 1
675
+        o = self.FSM.owner
676
+        o.puck = True     
677
+
648 678
         super(WindShot, self).Enter()        
649 679
         
650 680
     def Execute(self):
@@ -672,7 +702,7 @@ class WindShot(State):
672 702
             g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
673 703
             self.FSM.ToTransition('toShootShot')
674 704
             o.stick.applyRotation([0,0,-.22], True)   
675
-            o.puck = False
705
+            #o.puck = False
676 706
             o.mates.possession = False         
677 707
         
678 708
     def Exit(self):
@@ -689,7 +719,7 @@ class ShootShot(State):
689 719
         super(ShootShot, self).Enter()  
690 720
         o = self.FSM.owner
691 721
         g = o.me['game']
692
-        o.puck = False      
722
+        #o.puck = False      
693 723
         g.puck.worldOrientation = o.base.worldOrientation
694 724
         g.puck.applyRotation([0,0,-.1], True)
695 725
         g.puck.applyForce([200,0,0], True)
@@ -698,13 +728,14 @@ class ShootShot(State):
698 728
         o = self.FSM.owner
699 729
         g = o.me['game']
700 730
         o.stick.applyRotation([0,0,-.22], True)   
701
-        o.puck = False         
731
+        #o.puck = False         
702 732
         
703 733
         if self.FSM.stateLife > 20:
704 734
             self.FSM.ToTransition('toGetPuck')
705 735
     
706 736
     def Exit(self):
707
-        pass
737
+        o = self.FSM.owner
738
+        o.puck = False
708 739
 
709 740
 #====================================  
710 741
 
@@ -831,6 +862,10 @@ class Checked(State):
831 862
         o = self.FSM.owner
832 863
         self.checker = o.checked 
833 864
         o.checked = None      
865
+        o.puck = False
866
+        o.controlled = False
867
+        o.puck_trigger = False
868
+        o.user = False
834 869
         
835 870
     def Execute(self):
836 871
         self.FSM.stateLife += 1
@@ -838,9 +873,10 @@ class Checked(State):
838 873
         g = o.me['game']
839 874
 
840 875
         tilt = -.01
876
+        o.puck_trigger = False
841 877
         
842 878
         local = o.cont.worldOrientation.inverted() * (self.checker.cont.worldPosition - o.cont.worldPosition) 
843
-        print(local)
879
+        #print(local)
844 880
         if local.x > 0:
845 881
             #target is in front
846 882
             print('in front')
@@ -866,10 +902,331 @@ class Checked(State):
866 902
 
867 903
         o.body.applyRotation([0, tilt2, 0], True)     
868 904
         o.head.applyRotation([0, (tilt2 * 1.2), 0], True) 
869
-        if self.FSM.stateLife > 20:
905
+        if self.FSM.stateLife > 60:
870 906
             self.FSM.ToTransition('toDefendPuck')
871 907
     
872 908
     def Exit(self):
873 909
         pass
874 910
 
875 911
 #====================================  
912
+
913
+class ReceivePass(State):
914
+    def __init__(self,FSM):
915
+        super(ReceivePass, self).__init__(FSM)    
916
+        
917
+    def Enter(self):
918
+        self.FSM.stateLife = 1
919
+        super(ReceivePass, self).Enter()        
920
+        
921
+    def Execute(self):
922
+        self.FSM.stateLife += 1
923
+        o = self.FSM.owner
924
+        g = o.me['game']
925
+        v = o.base.getVectTo(g.puck.worldPosition)
926
+        o.stick.alignAxisToVect(v[1], 0, .1)
927
+
928
+        utils.check_puck_collision(self, o)        
929
+        
930
+        if self.FSM.stateLife > 180:
931
+            self.FSM.ToTransition('toGetPuck')
932
+
933
+    def Exit(self):
934
+        pass
935
+
936
+#====================================             
937
+
938
+class DefendNet(State):
939
+    def __init__(self,FSM):
940
+        super(DefendNet, self).__init__(FSM)    
941
+        
942
+    def Enter(self):
943
+        self.FSM.stateLife = 1
944
+        super(DefendNet, self).Enter()   
945
+        o = self.FSM.owner
946
+        if o.mates.name == 'a':
947
+            self.base_pos = Vector([-7, 0, 0])
948
+            self.posy = -4
949
+            self.zone_add = -8
950
+            self.inzone = -2
951
+        else:
952
+            self.base_pos = Vector([7, 0, 0])
953
+            self.posy = 4
954
+            self.zone_add = 8
955
+            self.inzone = 2
956
+        
957
+    def Execute(self):
958
+        self.FSM.stateLife += 1
959
+        o = self.FSM.owner
960
+        g = o.me['game']
961
+        utils.update_whiskers(o)
962
+        utils.getPlayerOrders(o, g)        
963
+        v = o.cont.getVectTo(self.base_pos)
964
+        #posy = 4
965
+        #inzone = 2
966
+        target = self.base_pos.copy()
967
+
968
+        if g.puck.worldPosition.y > self.posy:
969
+            target.y += 2
970
+        if g.puck.worldPosition.y < -self.posy:
971
+            target.y -= 2          
972
+        if (self.inzone > 1 and g.puck.worldPosition.x > self.inzone) or (self.inzone < -1 and g.puck.worldPosition.x < self.inzone):
973
+            #print(o.mates.name, 'inzone')
974
+            pass
975
+        # elif g.puck.worldPosition < inzone and g.puck.worldPosition > - inzone:
976
+        #     target.x = g.puck.worldPosition.x + (self.zone_add / 2) 
977
+
978
+        else:
979
+            #print(o.mates.name, 'outzone')
980
+            target.x = g.puck.worldPosition.x + self.zone_add    
981
+        local = o.cont.worldOrientation.inverted() * (o.cont.worldPosition - target) 
982
+        dist = o.cont.getDistanceTo(target)
983
+        if dist > 1:
984
+            if local.x > 0:                
985
+                o.kb_s = 1
986
+            else:
987
+                o.kb_w = 1
988
+            if local.y > 0:
989
+                rot = 'right'
990
+                o.kb_d = 1
991
+            else:
992
+                rot = 'left'  
993
+                o.kb_a = 1
994
+        else:
995
+            v = o.cont.getVectTo(g.puck.worldPosition)
996
+            o.cont.alignAxisToVect(v[1], 0, .05)   
997
+
998
+        utils.check_puck_collision(self, o)
999
+
1000
+        #if o.whisker_objs[0] or o.whisker_objs[1]:
1001
+            #print('whiskers d')
1002
+        #print(o.whiskers[0])
1003
+        utils.whisker_turns_goal(o)
1004
+            
1005
+
1006
+        if o.orders != 'toDefendNet':
1007
+            self.FSM.ToTransition('toDefendPuck')
1008
+            #print('exiting defend')
1009
+    
1010
+    def Exit(self):
1011
+        pass
1012
+
1013
+class DefendPursuePuck(State):
1014
+    def __init__(self,FSM):
1015
+        super(DefendPursuePuck, self).__init__(FSM)    
1016
+        
1017
+    def Enter(self):
1018
+        self.FSM.stateLife = 1
1019
+        super(DefendPursuePuck, self).Enter()   
1020
+        o = self.FSM.owner
1021
+        if o.mates.name == 'a':
1022
+            self.base_pos = Vector([-7, 0, 0])
1023
+        else:
1024
+            self.base_pos = Vector([7, 0, 0])
1025
+        
1026
+    def Execute(self):
1027
+        self.FSM.stateLife += 1
1028
+        o = self.FSM.owner
1029
+        g = o.me['game']
1030
+        utils.getPlayerOrders(o, g)        
1031
+        v = o.cont.getVectTo(self.base_pos)
1032
+        posy = 4
1033
+        inzone = 2
1034
+        target = g.puck.worldPosition.copy()
1035
+
1036
+        # if g.puck.worldPosition.y > posy:
1037
+        #     target.y += 2
1038
+        # if g.puck.worldPosition.y < -posy:
1039
+        #     target.y -= 2          
1040
+        # if g.puck.worldPosition.x > inzone:
1041
+        #     pass
1042
+        #else:
1043
+            #target.x = g.puck.worldPosition.x + 8    
1044
+        local = o.cont.worldOrientation.inverted() * (o.cont.worldPosition - target) 
1045
+        dist = o.cont.getDistanceTo(target)
1046
+        if dist > 2:
1047
+            if local.x > 0:                
1048
+                o.kb_s = 1
1049
+            else:
1050
+                o.kb_w = 1
1051
+            if local.y > 0:
1052
+                rot = 'right'
1053
+                o.kb_d = 1
1054
+            else:
1055
+                rot = 'left'  
1056
+                o.kb_a = 1
1057
+        else:
1058
+            v = o.cont.getVectTo(g.puck.worldPosition)
1059
+            o.cont.alignAxisToVect(v[1], 0, .05)   
1060
+
1061
+        utils.check_puck_collision(self, o)
1062
+        utils.whisker_turns_goal(o)
1063
+
1064
+        if o.orders != 'toDefendPursuePuck':
1065
+            self.FSM.ToTransition('toDefendPuck')
1066
+            print('exiting pursue')
1067
+    
1068
+    def Exit(self):
1069
+        pass        
1070
+
1071
+
1072
+
1073
+class DefendThirdMan(State):
1074
+    def __init__(self,FSM):
1075
+        super(DefendThirdMan, self).__init__(FSM)    
1076
+        
1077
+    def Enter(self):
1078
+        self.FSM.stateLife = 1
1079
+        super(DefendThirdMan, self).Enter()   
1080
+        o = self.FSM.owner
1081
+        if o.mates.name == 'a':
1082
+            self.base_pos = Vector([2, 0, 0])
1083
+            self.posy = -4
1084
+            self.zone_add = -2
1085
+            self.inzone = -2
1086
+        else:
1087
+            self.base_pos = Vector([-2, 0, 0])
1088
+            self.posy = 4
1089
+            self.zone_add = 2
1090
+            self.inzone = 2
1091
+        
1092
+    def Execute(self):
1093
+        self.FSM.stateLife += 1
1094
+        o = self.FSM.owner
1095
+        g = o.me['game']
1096
+        utils.update_whiskers(o)
1097
+        utils.getPlayerOrders(o, g)        
1098
+        v = o.cont.getVectTo(self.base_pos)
1099
+        #posy = 4
1100
+        #inzone = 2
1101
+        target = self.base_pos.copy()
1102
+
1103
+        if g.puck.worldPosition.y > self.posy:
1104
+            target.y -= 2
1105
+        if g.puck.worldPosition.y < -self.posy:
1106
+            target.y += 2          
1107
+        if (self.inzone > 1 and g.puck.worldPosition.x > self.inzone) or (self.inzone < -1 and g.puck.worldPosition.x < self.inzone):
1108
+            #print(o.mates.name, 'inzone')
1109
+            pass
1110
+        # elif g.puck.worldPosition < inzone and g.puck.worldPosition > - inzone:
1111
+        #     target.x = g.puck.worldPosition.x + (self.zone_add / 2) 
1112
+
1113
+        else:
1114
+            #print(o.mates.name, 'outzone')
1115
+            target.x = g.puck.worldPosition.x + self.zone_add    
1116
+        local = o.cont.worldOrientation.inverted() * (o.cont.worldPosition - target) 
1117
+        dist = o.cont.getDistanceTo(target)
1118
+        if dist > 1:
1119
+            if local.x > 0:                
1120
+                o.kb_s = 1
1121
+            else:
1122
+                o.kb_w = 1
1123
+            if local.y > 0:
1124
+                rot = 'right'
1125
+                o.kb_d = 1
1126
+            else:
1127
+                rot = 'left'  
1128
+                o.kb_a = 1
1129
+        else:
1130
+            v = o.cont.getVectTo(g.puck.worldPosition)
1131
+            o.cont.alignAxisToVect(v[1], 0, .05)   
1132
+
1133
+        utils.check_puck_collision(self, o)
1134
+
1135
+        #if o.whisker_objs[0] or o.whisker_objs[1]:
1136
+            #print('whiskers d')
1137
+        #print(o.whiskers[0])
1138
+        utils.whisker_turns_goal(o)
1139
+            
1140
+
1141
+        if o.orders != 'toDefendThirdMan':
1142
+            self.FSM.ToTransition('toDefendPuck')
1143
+            #print('exiting defend')
1144
+    
1145
+    def Exit(self):
1146
+        pass        
1147
+
1148
+
1149
+
1150
+class OffencePuck(State):
1151
+    def __init__(self,FSM):
1152
+        super(OffencePuck, self).__init__(FSM)    
1153
+        
1154
+    def Enter(self):
1155
+        self.FSM.stateLife = 1
1156
+        super(OffencePuck, self).Enter()   
1157
+        o = self.FSM.owner
1158
+        
1159
+    def Execute(self):
1160
+        self.FSM.stateLife += 1
1161
+        o = self.FSM.owner
1162
+        g = o.me['game']
1163
+        utils.getPlayerOrders(o, g)        
1164
+        #v = o.cont.getVectTo(self.base_pos)
1165
+
1166
+        g.puck.worldPosition = o.stick_empty.worldPosition
1167
+        g.puck.linearVelocity = [0,0,0]  
1168
+
1169
+
1170
+        if o.checked != None:
1171
+            #self.FSM.ToTransition('toDefendPuck') 
1172
+            o.mates.possession = False              
1173
+            g.puck.worldOrientation = o.puck_empty.worldOrientation
1174
+            g.puck.applyForce([50, 0, .5])
1175
+            o.puck = False
1176
+            self.FSM.ToTransition('toChecked')        
1177
+
1178
+        posy = 4
1179
+        inzone = 2
1180
+        target = g.puck.worldPosition.copy()
1181
+        #print('check for pass')
1182
+        teammates = o.mates.players.copy()
1183
+        teammates.remove(o)
1184
+
1185
+        rc = o.cont.rayCast(teammates[0].cont.worldPosition,
1186
+                            o.cont.worldPosition,
1187
+                            dist = 0,
1188
+                            prop = 'player',
1189
+                            face = 0,
1190
+                            xray = 1,
1191
+                            poly = 0,
1192
+                            mask = 1)
1193
+        if rc[0]:
1194
+            if teammates[0].cont == rc[0]:
1195
+                v = o.cont.getVectTo(teammates[0].cont)
1196
+                o.cont.alignAxisToVect(v[1], 0, .05)
1197
+                print('can pass to this dude')
1198
+
1199
+        # if g.puck.worldPosition.y > posy:
1200
+        #     target.y += 2
1201
+        # if g.puck.worldPosition.y < -posy:
1202
+        #     target.y -= 2          
1203
+        # if g.puck.worldPosition.x > inzone:
1204
+        #     pass
1205
+        #else:
1206
+            #target.x = g.puck.worldPosition.x + 8    
1207
+        # local = o.cont.worldOrientation.inverted() * (o.cont.worldPosition - target) 
1208
+        # dist = o.cont.getDistanceTo(target)
1209
+        # if dist > 2:
1210
+        #     if local.x > 0:                
1211
+        #         o.kb_s = 1
1212
+        #     else:
1213
+        #         o.kb_w = 1
1214
+        #     if local.y > 0:
1215
+        #         rot = 'right'
1216
+        #         o.kb_d = 1
1217
+        #     else:
1218
+        #         rot = 'left'  
1219
+        #         o.kb_a = 1
1220
+        # else:
1221
+        #     v = o.cont.getVectTo(g.puck.worldPosition)
1222
+        #     o.cont.alignAxisToVect(v[1], 0, .05)   
1223
+
1224
+        utils.check_puck_collision(self, o)
1225
+        utils.whisker_turns_goal(o)
1226
+
1227
+        if o.orders != 'toOffencePuck':
1228
+            self.FSM.ToTransition('toDefendPuck')
1229
+            #print('exiting pursue')
1230
+    
1231
+    def Exit(self):
1232
+        pass        

+ 33
- 0
scripts/StatesPuck.py View File

@@ -0,0 +1,33 @@
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['game']
30
+        #self.FSM.ToTransition('toNewState')
31
+    
32
+    def Exit(self):
33
+        pass

+ 183
- 0
scripts/StatesTeam.py View File

@@ -0,0 +1,183 @@
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['game']
30
+        self.FSM.ToTransition('toNewState')
31
+    
32
+    def Exit(self):
33
+        pass
34
+
35
+#====================================             
36
+
37
+class MatchIntro(State):
38
+    def __init__(self,FSM):
39
+        super(MatchIntro, self).__init__(FSM)    
40
+        
41
+    def Enter(self):
42
+        self.FSM.stateLife = 1
43
+        super(MatchIntro, self).Enter()        
44
+        
45
+    def Execute(self):
46
+        self.FSM.stateLife += 1
47
+        o = self.FSM.owner
48
+        #g = o.me['game']
49
+        #self.FSM.ToTransition('toNewState')
50
+    
51
+    def Exit(self):
52
+        pass
53
+
54
+
55
+#====================================   
56
+
57
+class Pout(State):
58
+    def __init__(self,FSM):
59
+        super(Pout, self).__init__(FSM)    
60
+        
61
+    def Enter(self):
62
+        self.FSM.stateLife = 1
63
+        super(Pout, self).Enter()        
64
+        
65
+    def Execute(self):
66
+        self.FSM.stateLife += 1
67
+        o = self.FSM.owner
68
+        #g = o.me['game']
69
+        #self.FSM.ToTransition('toNewState')
70
+    def Exit(self):
71
+        pass
72
+
73
+#====================================             
74
+
75
+class Celebrate(State):
76
+    def __init__(self,FSM):
77
+        super(Celebrate, self).__init__(FSM)    
78
+        
79
+    def Enter(self):
80
+        self.FSM.stateLife = 1
81
+        super(Celebrate, self).Enter()        
82
+        
83
+    def Execute(self):
84
+        self.FSM.stateLife += 1
85
+        o = self.FSM.owner
86
+        #g = o.me['game']
87
+        #self.FSM.ToTransition('toNewState')
88
+        print('PARTY __')
89
+    def Exit(self):
90
+        pass
91
+
92
+
93
+#====================================   
94
+
95
+#====================================             
96
+
97
+class Faceoff(State):
98
+    def __init__(self,FSM):
99
+        super(Faceoff, self).__init__(FSM)    
100
+        
101
+    def Enter(self):
102
+        self.FSM.stateLife = 1
103
+        super(Faceoff, self).Enter()        
104
+        
105
+    def Execute(self):
106
+        self.FSM.stateLife += 1
107
+        o = self.FSM.owner
108
+        #g = o.me['game']
109
+        #self.FSM.ToTransition('toNewState')
110
+    
111
+    def Exit(self):
112
+        pass
113
+
114
+
115
+#====================================             
116
+class Chase(State):
117
+    def __init__(self,FSM):
118
+        super(Chase, self).__init__(FSM)    
119
+        
120
+    def Enter(self):
121
+        self.FSM.stateLife = 1
122
+        super(Chase, self).Enter() 
123
+        #self.FSM.posession == 0       
124
+        
125
+    def Execute(self):
126
+        self.FSM.stateLife += 1
127
+        g = self.FSM.owner.game
128
+        t = self.FSM.owner
129
+        #if this team gains possesion
130
+        self.possession = 0
131
+        if g.a_team == t:
132
+            if t.possession == 1:
133
+                self.possession = 1
134
+            #print('this is the a_team', self.FSM.owner)
135
+        if g.b_team == t:
136
+            if t.possession == 1:
137
+                self.possession = 2
138
+            #print('this is the b_team', self.FSM.owner)  
139
+        #print('posession', g.team_possession)          
140
+
141
+        #if the opposite team gains possesion
142
+
143
+
144
+        #self.FSM.ToTransition('tooOffence')
145
+    
146
+    def Exit(self):
147
+        pass
148
+
149
+#====================================             
150
+class Defense(State):
151
+    def __init__(self,FSM):
152
+        super(Defense, self).__init__(FSM)    
153
+        
154
+    def Enter(self):
155
+        self.FSM.stateLife = 1
156
+        super(Defense, self).Enter()        
157
+        
158
+    def Execute(self):
159
+        self.FSM.stateLife += 1
160
+        #o = self.FSM.owner
161
+        #g = o.me['game']
162
+        #self.FSM.ToTransition('tooOffence')
163
+    
164
+    def Exit(self):
165
+        pass
166
+
167
+#====================================             
168
+class Offence(State):
169
+    def __init__(self,FSM):
170
+        super(Offence, self).__init__(FSM)    
171
+        
172
+    def Enter(self):
173
+        self.FSM.stateLife = 1
174
+        super(Offence, self).Enter()        
175
+        
176
+    def Execute(self):
177
+        self.FSM.stateLife += 1
178
+        #o = self.FSM.owner
179
+        #g = o.me['game']
180
+        #self.FSM.ToTransition('toDefense')
181
+    
182
+    def Exit(self):
183
+        pass                

+ 203
- 89
scripts/player.py View File

@@ -10,6 +10,10 @@ team_b_colors = [[.1,.9,.1,1], [.1,.1,.1,1], [.3, .3, .3, 1]]
10 10
 
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
+import datetime
14
+#from datetime import datetime, timedelta
15
+#sec = timedelta(seconds=(input('Enter the number of seconds: ')))
16
+#time = str(sec)
13 17
 
14 18
 
15 19
 positions = [[3,0], [4,-3], [6, 3], [8, -4]]
@@ -29,6 +33,42 @@ def run_camera(self):
29 33
         if opos > - 3 and opos < 6:
30 34
             self.camera.worldPosition.x = opos + 10
31 35
 
36
+class ScoreOverlay:
37
+    def __init__(self, game):
38
+        self.game = game
39
+        self.life = 0
40
+        self.scene = bge.logic.addScene('ScoreOverlay')
41
+        
42
+
43
+    def update(self):
44
+        if self.life == 1:
45
+            self.scene = bge.logic.getSceneList()['ScoreOverlay']
46
+            txt_objs = ['score_a', 'score_b', 'home_title', 'away_title', 'time']
47
+            for x in txt_objs:
48
+                self.scene.objects[x].resolution = 24
49
+        elif self.life > 1:
50
+        #if self.game.score is not None:str(number).zfill(2)
51
+            self.scene.objects['score_a'].text = str(self.game.score[0]).zfill(2)
52
+            self.scene.objects['score_b'].text = str(self.game.score[1]).zfill(2)
53
+        
54
+            sec = datetime.timedelta(seconds=self.game.clock_time)
55
+            sec = '0' + str(sec)[:-3]
56
+            if len(sec) > 5:
57
+                sec = sec[1:]
58
+            self.scene.objects['time'].text = sec
59
+        #print(self.game.score)
60
+        self.life += 1
61
+        
62
+
63
+        #avg = sum(datetimes, datetime.timedelta(0)) / len(datetimes)
64
+        #avg = avg - datetime.timedelta(microseconds=avg.microseconds)
65
+
66
+        #sec = sec.replace(microsecond=0)
67
+        #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
68
+
69
+        #print(sec)
70
+#time = str(sec)
71
+
32 72
 class user_input:
33 73
     def __init__(self, type):
34 74
         self.type = type
@@ -81,9 +121,51 @@ class user_input:
81 121
 class cpu_input(user_input):
82 122
     def __init__(self, type):
83 123
         self.type = type
124
+        self.i_ua = 0
125
+        self.i_da = 0
126
+        self.i_ra = 0
127
+        self.i_la = 0
128
+        self.i_w = 0
129
+        self.i_a = 0
130
+        self.i_s = 0
131
+        self.i_d = 0
132
+        self.i_ls = 0
133
+        self.i_sp = 0
134
+        self.i_last_ua = 0
135
+        self.i_last_da = 0
136
+        self.i_last_ra = 0
137
+        self.i_last_la = 0
138
+        self.i_last_w = 0
139
+        self.i_last_a = 0
140
+        self.i_last_s = 0
141
+        self.i_last_d = 0
142
+        self.i_last_ls = 0
143
+        self.i_lastsp = 0
144
+
84 145
     def update(self):
85 146
         pass
86 147
 
148
+    def clear(self):
149
+        self.i_last_ua = self.i_ua
150
+        self.i_last_da = self.i_da
151
+        self.i_last_ra = self.i_ra
152
+        self.i_last_la = self.i_la
153
+        self.i_last_w = self.i_w
154
+        self.i_last_a = self.i_a
155
+        self.i_last_s = self.i_s
156
+        self.i_last_d = self.i_d
157
+        self.i_last_ls = self.i_ls
158
+        self.i_lastsp = self.i_sp
159
+        self.i_ua = 0
160
+        self.i_da = 0
161
+        self.i_ra = 0
162
+        self.i_la = 0
163
+        self.i_w = 0
164
+        self.i_a = 0
165
+        self.i_s = 0
166
+        self.i_d = 0
167
+        self.i_ls = 0
168
+        self.i_sp = 0
87 169
 
88 170
 class keyboard_input(user_input):
89 171
     def __init__(self, type):
@@ -153,25 +235,26 @@ class joystick_input(user_input):
153 235
 
154 236
     def update(self):    
155 237
         if bge.logic.joysticks[self.stick]:
156
-            print(bge.logic.joysticks[self.stick].activeButtons)
238
+            #print(bge.logic.joysticks[self.stick].activeButtons)
157 239
             sens = .4
240
+            sens2 = .6
158 241
             if 0 in bge.logic.joysticks[self.stick].activeButtons:
159 242
                 self.i_da = 1
160
-            if 1 in bge.logic.joysticks[self.stick].activeButtons:
161
-                self.i_la = 1
162 243
             if 2 in bge.logic.joysticks[self.stick].activeButtons:
244
+                self.i_la = 1
245
+            if 1 in bge.logic.joysticks[self.stick].activeButtons:
163 246
                 self.i_ra = 1
164 247
             if 3 in bge.logic.joysticks[self.stick].activeButtons:
165 248
                 self.i_ua = 1
166
-            if 9 in bge.logic.joysticks[self.stick].activeButtons:
249
+            if 10 in bge.logic.joysticks[self.stick].activeButtons:
167 250
                 self.i_ls = 1
168 251
 
169 252
 
170
-            if bge.logic.joysticks[self.stick].axisValues[0] < -sens:
253
+            if bge.logic.joysticks[self.stick].axisValues[0] < -sens2:
171 254
                 self.i_a = 1
172 255
             if bge.logic.joysticks[self.stick].axisValues[1] < -sens:
173 256
                 self.i_w = 1            
174
-            if bge.logic.joysticks[self.stick].axisValues[0] > sens:
257
+            if bge.logic.joysticks[self.stick].axisValues[0] > sens2:
175 258
                 self.i_d = 1
176 259
             if bge.logic.joysticks[self.stick].axisValues[1] > sens:
177 260
                 self.i_s = 1                        
@@ -189,15 +272,20 @@ class joystick_input(user_input):
189 272
 
190 273
             #inputs.JoystickButton(joystickIndex, buttonIndex)            
191 274
 class team:
192
-    def __init__(self, name, colors, user):
275
+    def __init__(self, name, colors, user, game):
193 276
         self.name = name
277
+        self.game = game
194 278
         self.colors = colors
195 279
         self.players = []
196 280
         self.puck_closest = []
281
+        self.net_closest = []
197 282
         self.possession = False
283
+        self.scored = False
198 284
         self.switch_player_frame = [0,0,0,0]
199 285
         self.user = user
200 286
         self.user_input = None
287
+        self.FSM = FSM.TeamFSM(self)
288
+        self.own_net = None
201 289
         
202 290
     def update(self, game):
203 291
         
@@ -205,10 +293,23 @@ class team:
205 293
             return e.cont.getDistanceTo(game.puck.worldPosition)
206 294
         self.puck_closest.sort(reverse=False, key=sortClosestToPuck)
207 295
         
208
-        a_list = []
209
-        for x in self.players:
210
-            a_list.append(x.user)
211 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
+
304
+        self.FSM.Execute()
305
+        #print(self.FSM.FSM.curState.__class__.__name__, self.name)
306
+#self.FSM.FSM.curState.__class__.__name__ != 'PosesPuck':
307
+        if self.name == 'b':
308
+            a_list = []
309
+            for x in self.players:
310
+                #a_list.append(x.puck)
311
+                a_list.append(x.FSM.FSM.curState.__class__)
312
+            #print(a_list)
212 313
         
213 314
 class game:
214 315
     def __init__(self, obj, cont):
@@ -235,13 +336,18 @@ class game:
235 336
         self.team_b_user = 0
236 337
         self.center_ice = self.scene.objects['center_ice']
237 338
         self.score = [0,0]
339
+        self.score_overlay = ScoreOverlay(self)
340
+        self.clock_time = 0
238 341
         #team properties: name, colors, user
239
-        self.a_team = team('a', team_a_colors, 1)
240
-        self.b_team = team('b', team_b_colors, 0)
342
+        self.a_team = team('a', team_a_colors, 1, self)
343
+        self.b_team = team('b', team_b_colors, 0, self)
241 344
         #self.a_team.user_input = keyboard_input(1)
242 345
         self.a_team.user_input = joystick_input(2, 0)
243 346
         #self.b_team.user_input = joystick_input(3, 1)
244
-        self.b_team.user_input = keyboard_input(1)
347
+        self.b_team.user_input = cpu_input(0)
348
+
349
+        self.a_team.own_net = self.goal_b_e
350
+        self.b_team.own_net = self.goal_a_e
245 351
         
246 352
         self.FSM = FSM.GameFSM(self) 
247 353
     
@@ -331,13 +437,19 @@ class game:
331 437
                     
332 438
         self.FSM.Execute() 
333 439
         self.sound_man.update() 
334
-        
440
+        self.score_overlay.update()
335 441
         #print(self.team_a_user_input.i_w)
336 442
         #print(self.team_b_user_input.i_da)
337 443
         
338 444
         
339 445
         #print(self.score)  
340 446
 
447
+        # l = []
448
+        # for x in self.a_team.players:
449
+        #     l.append(x.orders)
450
+        #     #l.append(x.FSM.FSM.curState)
451
+        # print(l, 'orders')
452
+
341 453
 class hockey_player():
342 454
     def __init__(self, team, other, contr):
343 455
         scene = bge.logic.getCurrentScene()
@@ -375,6 +487,8 @@ class hockey_player():
375 487
         self.switch_player_frame = [0,0,0,0]
376 488
         self.faceoff_pos = [0, 0, 0]           
377 489
         self.team = team
490
+        self.role = None
491
+        self.orders = None
378 492
 
379 493
         self.teammates = []
380 494
             
@@ -438,26 +552,42 @@ class hockey_player():
438 552
         self.last_kb_ls = self.kb_ls
439 553
         self.last_kb_sp = self.kb_sp
440 554
 
441
-        self.kb_ua = bge.logic.keyboard.inputs[bge.events.UPARROWKEY].values[-1]
442
-        self.kb_da = bge.logic.keyboard.inputs[bge.events.DOWNARROWKEY].values[-1]    
443
-        self.kb_la = bge.logic.keyboard.inputs[bge.events.LEFTARROWKEY].values[-1]
444
-        self.kb_ra = bge.logic.keyboard.inputs[bge.events.RIGHTARROWKEY].values[-1]
445
-        self.kb_w = bge.logic.keyboard.inputs[bge.events.WKEY].values[-1]
446
-        self.kb_a = bge.logic.keyboard.inputs[bge.events.AKEY].values[-1]    
447
-        self.kb_s = bge.logic.keyboard.inputs[bge.events.SKEY].values[-1]
448
-        self.kb_d = bge.logic.keyboard.inputs[bge.events.DKEY].values[-1]  
449
-        self.kb_ls = bge.logic.keyboard.inputs[bge.events.LEFTSHIFTKEY].values[-1]    
450
-        self.kb_sp = bge.logic.keyboard.inputs[bge.events.SPACEKEY].values[-1]    
555
+
556
+        if self.user:
557
+            g = self.mates
558
+            self.kb_ua = g.user_input.i_ua
559
+            self.kb_da = g.user_input.i_da
560
+            self.kb_la = g.user_input.i_la
561
+            self.kb_ra = g.user_input.i_ra
562
+            self.kb_w = g.user_input.i_w
563
+            self.kb_a = g.user_input.i_a
564
+            self.kb_s = g.user_input.i_s
565
+            self.kb_d = g.user_input.i_d
566
+            self.kb_ls = g.user_input.i_ls
567
+            self.kb_sp = g.user_input.i_sp
568
+
569
+        else:    
570
+            self.kb_ua = 0
571
+            self.kb_da = 0   
572
+            self.kb_la = 0
573
+            self.kb_ra = 0
574
+            self.kb_w = 0
575
+            self.kb_a = 0 
576
+            self.kb_s = 0
577
+            self.kb_d = 0 
578
+            self.kb_ls = 0   
579
+            self.kb_sp = 0   
451 580
 
452 581
     def user_movement(self):
582
+        #print(self.kb_a)
453 583
         own = self.cont
454
-        #if self.kb_w == 1:
455
-        if self.mates.user_input.i_w == 1:    
584
+        if self.kb_w == 1:
585
+        #if self.mates.user_input.i_w == 1:    
456 586
             self.speed_tilt_timer += 1
457 587
             if own.linearVelocity.x < 2:
458 588
                 own.applyForce([13,0,0], True)
459
-            #if self.kb_ls == 1:
460
-            if self.mates.user_input.i_ls == 1:      
589
+            if self.kb_ls == 1:
590
+            #if self.mates.user_input.i_ls == 1:      
461 591
                 #if self.last_kb_ls == 0:
462 592
                 if self.mates.user_input.i_last_ls == 0:      
463 593
                     self.speed_tilt_timer = 0
@@ -465,8 +595,8 @@ class hockey_player():
465 595
                     own.applyForce([16,0,0], True)                    
466 596
         else:
467 597
             self.speed_tilt_timer = 0
468
-        #if self.kb_s == 1:
469
-        if self.mates.user_input.i_s == 1:     
598
+        if self.kb_s == 1:
599
+        #if self.mates.user_input.i_s == 1:     
470 600
             if own.linearVelocity.x > -2:
471 601
                 own.applyForce([-13,0,0], True)
472 602
         
@@ -475,16 +605,16 @@ class hockey_player():
475 605
         time = 25  
476 606
         time2 = 25 
477 607
         aligned = False     
478
-        #if self.kb_a == 1:
479
-        if self.mates.user_input.i_a == 1: 
608
+        if self.kb_a == 1:
609
+        #if self.mates.user_input.i_a == 1: 
480 610
             self.turn_timer += 1
481 611
             own.applyRotation([0, 0, .04], True)
482 612
             if self.turn_timer < time:
483 613
                 self.body.applyRotation([-tilt, 0, 0], True)
484 614
                 self.head.applyRotation([(tilt2 * -1.2), 0, 0], True)
485 615
                 #aligned = True                
486
-        #elif self.kb_d == 1:
487
-        elif self.mates.user_input.i_d == 1: 
616
+        elif self.kb_d == 1:
617
+        #elif self.mates.user_input.i_d == 1: 
488 618
             self.turn_timer += 1
489 619
             own.applyRotation([0, 0, -.04], True)  
490 620
             if self.turn_timer < time:
@@ -557,16 +687,23 @@ class hockey_player():
557 687
         #print(mates, since_switch_a)
558 688
         for m in mates:
559 689
             m.user = 0
560
-        if since_switch_a > 30:
561
-            
562
-            mates[0].user = 1
563
-            print('p1')
564
-        else:
565
-            mates[1].user = 1            
566
-            print('p2', since_switch_a)
567
-            
568
-        self.user = 0  
569
-        print('switch player')  
690
+        if since_switch_a is not 0:
691
+            if since_switch_a > 40:
692
+                
693
+                mates[0].user = 1
694
+                mates[0].orders = None
695
+                #self.user = 0
696
+                #print('p1')
697
+                mates[0].FSM.FSM.ToTransition('toGetPuckUser')
698
+            else:
699
+                mates[1].user = 1            
700
+                mates[1].orders = None
701
+                #print('p2', since_switch_a)
702
+                mates[0].FSM.FSM.ToTransition('toGetPuckUser')
703
+            self.orders = None    
704
+            self.FSM.FSM.ToTransition('toGetPuck')
705
+            self.user = 0  
706
+            #print('switch player', round(since_switch_a), self.user, self)  
570 707
             
571 708
     def check_puck(self):
572 709
         if self.FSM.FSM.stateLife > 120:
@@ -579,7 +716,6 @@ class hockey_player():
579 716
                 self.puck = True
580 717
                 if self.mates.user > 0:
581 718
                     self.user = 1 
582
-                    #print('check_puck function switching user') 
583 719
                 self.FSM.FSM.ToTransition('toPosesPuck')
584 720
                 self.state = 'possession' 
585 721
 
@@ -600,13 +736,11 @@ class hockey_player():
600 736
             if distances != []:
601 737
                 #sort list of whiskers
602 738
                 nd = sorted(distances, key=lambda x: x[1])
603
-                for a in nd:
604
-                    print(a[0][0]['name'], a[1])
605
-                print('----')
739
+                
606 740
                 #sort list of whiskers
607 741
                 if nd[0][1] < 1.1:
608 742
                     self.FSM.FSM.ToTransition('toCheckOn') 
609
-                    print(nd[0][0][0]['c_ref'])
743
+                    #print(nd[0][0][0]['c_ref'])
610 744
                     nd[0][0][0]['c_ref'].checked = self                          
611 745
                 else:    
612 746
                     self.FSM.FSM.ToTransition('toCheckMissOn')        
@@ -616,7 +750,7 @@ class hockey_player():
616 750
     def check_checked(self):
617 751
         if self.checked == True:
618 752
             #self.checked = False
619
-            print('--------checked')
753
+            #print('--------checked')
620 754
             return True    
621 755
         else:
622 756
             return False  
@@ -650,15 +784,15 @@ class hockey_player():
650 784
             for x in self.me['game'].players:
651 785
                 if x.cont.worldPosition != self.cont.worldPosition and self.team == x.team:
652 786
                     self.teammates.append(x)
653
-        
787
+        self.update_inputs()    
654 788
         self.update_indicator()
655 789
         self.align_to_base()
656 790
         self.FSM.Execute()
657 791
         #self.check_puck()
658 792
         state = str(self.FSM.FSM.curState.__class__.__name__)
659 793
         
660
-        if self.puck == True and self.user == 0:
661
-            self.puck = False
794
+        #if self.puck == True and self.user == 0:
795
+            #self.puck = False
662 796
         u = []
663 797
         for x in self.mates.players:
664 798
             if x.puck == True:
@@ -670,39 +804,15 @@ class hockey_player():
670 804
             if x.user == 1:
671 805
                 u2.append(x)                
672 806
         
673
-        if self.user == 1:
674
-            self.update_inputs()             
807
+        # if self.user == 1:
808
+        #     self.update_inputs()             
809
+        # else:
810
+        #     pass
811
+                
812
+        #self.update_inputs()    
675 813
 
676
-            e1 = self.cont.worldOrientation.to_euler().z
677
-            e2 = self.stick.worldOrientation.to_euler().z
678
-            dif = e1 - e2
679
-            
680
-            #if self.kb_la == 1 and self.puck:
681
-            if self.mates.user_input.i_la == 1 and self.puck:                 
682
-                self.pass_id = 0
683
-                a = str(self.FSM.FSM.curState.__class__.__name__)
684
-                if state != 'Passing':
685
-                    self.FSM.FSM.ToTransition('toWindPass')
686
-
687
-            #if self.kb_ra == 1 and self.puck:
688
-            if self.mates.user_input.i_ra == 1 and self.puck:     
689
-                self.pass_id = 1
690
-                a = str(self.FSM.FSM.curState.__class__.__name__)
691
-                if state != 'Passing':
692
-                    self.FSM.FSM.ToTransition('toWindPass')
693
-                                        
694
-            # if self.kb_ua == 1 and self.puck == False:
695
-            #     self.stick.applyRotation([0, -.35, 0], True)                    
696
-            #     self.stick.applyMovement([.4, 0, 0], True)
697
-            #     if self.last_kb_ua == False:
698
-            #         self.me['game'].sound_man.queue_sound(['check', self.cont, self.me['game'].camera])
699
-            #         print('hit sound')
700
-            # if self.kb_ua == 1 and self.puck == True:
701
-            #     a = str(self.FSM.FSM.curState.__class__.__name__)
702
-            #     if state != 'Dumping':
703
-            #         self.FSM.FSM.ToTransition('toDumping')   
704
-
705
-            self.user_movement()                
814
+
815
+        self.user_movement()                
706 816
                 
707 817
 def main(cont):
708 818
     own = cont.owner
@@ -741,11 +851,11 @@ def puck(cont):
741 851
         if own.worldPosition.x < -12:
742 852
             own.worldPosition.x = -11.5
743 853
             print('puck out of bounds -x')
744
-        if own.worldPosition.y > 8.25:
854
+        if own.worldPosition.y > 8.15:
745 855
             own.worldPosition.y = 7.0
746 856
             #own.linearVelocity.x *= -1
747 857
             print('puck out of bounds +y')
748
-        if own.worldPosition.y < -8.25:
858
+        if own.worldPosition.y < -8.15:
749 859
             own.worldPosition.y = -7.0
750 860
             print('puck out of bounds -y')
751 861
             #own.linearVelocity.x *= -1  
@@ -760,7 +870,9 @@ def puck(cont):
760 870
                 if g.frame - g.sound_man.board_played > 30:
761 871
                     g.sound_man.queue_sound(['board', g.puck, g.camera])                                                
762 872
                     g.sound_man.board_played = g.frame 
763
-        if not g.a_team.possession and not g.b_team.possession:                  
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': 
764 876
             if cont.sensors['puck-player'].hitObject is not None:
765 877
                 ho = cont.sensors['puck-player'].hitObject
766 878
                 for p in g.a_team.players + g.b_team.players:
@@ -775,8 +887,10 @@ def puck(cont):
775 887
                     print('GOOOAAAALLL!!', o['team'])
776 888
                     if o['team'] == 'a':
777 889
                         g.score[0] += 1
890
+                        g.a_team.scored = True
778 891
                     if o['team'] == 'b':
779
-                        g.score[1] += 1    
892
+                        g.score[1] += 1 
893
+                        g.b_team.scored = True   
780 894
                     g.FSM.FSM.ToTransition('toGoalScored')
781 895
 
782 896
                     #if 'a2' in cont.sensors['puck-player'].hitObject['name']:

+ 73
- 5
scripts/utils.py View File

@@ -5,11 +5,8 @@ def update_whiskers(self):
5 5
 
6 6
     color = [0,1,0]
7 7
     iter = 0
8
-
9
-    #cast all whisker rays
10 8
     l = len(self.whisker_objs)
11
-    #print(l)
12
-    #for w in self.whisker_objs:
9
+
13 10
     while iter < l:
14 11
         rc = o.cont.rayCast(self.whisker_objs[iter].worldPosition,
15 12
                             o.cont.worldPosition,
@@ -34,4 +31,75 @@ def update_whiskers(self):
34 31
     #             #print(w[0])
35 32
     #     #print(self.whiskers)
36 33
     #     bge.render.drawLine(o.cont.worldPosition, self.whisker_objs[iter].worldPosition, color)
37
-    #     iter += 1
34
+    #     iter += 1
35
+
36
+
37
+def getPlayerOrders(o, g):
38
+    o.orders = None
39
+    o.mates.net_closest = o.mates.players
40
+    #check if team is controlled by cpu
41
+    #if o.mates.user_input.type == 0:
42
+    if 0 == 0:    
43
+        #get closest player to puck
44
+        o.mates.net_closest = o.mates.players.copy()
45
+        def sortClosestToNet(e):
46
+            return e.cont.getDistanceTo(o.mates.own_net.worldPosition)
47
+        o.mates.net_closest.sort(reverse=False, key=sortClosestToNet)        
48
+        
49
+        if o.mates.net_closest != []:
50
+            if o.mates.net_closest[0] == o:
51
+                o.orders = 'toDefendNet'
52
+
53
+            else:
54
+                goalie = None
55
+                for x in o.mates.players:
56
+                    if x.orders == 'toDefendNet':
57
+                        goalie = x
58
+                closest = o.mates.puck_closest.copy()
59
+                if goalie in closest:
60
+                    closest.remove(goalie)
61
+                if closest[0] == o:
62
+                    o.orders = 'toDefendPursuePuck'
63
+                else:    
64
+                    o.orders = None
65
+                if o.orders == None:
66
+                    o.orders = 'toDefendThirdMan'
67
+
68
+        else:
69
+            print('list is none')
70
+    if o.user == 1 or o.puck == 1:
71
+        o.orders = None
72
+
73
+    if o.puck == 1:
74
+        if o.mates.user_input.type == 0:
75
+            print('utils offence order')
76
+            o.orders = 'toOffencePuck'    
77
+    #return orders
78
+
79
+def check_puck_collision(self, o):
80
+    if self.FSM.stateLife > 5:
81
+        if o.puck_trigger:
82
+            switch = True
83
+            for x in o.mates.players:
84
+                if x.puck == 1:
85
+                    switch = False
86
+            if switch:
87
+                o.puck_trigger = False
88
+                o.puck = True
89
+                for x in o.mates.players:
90
+                    x.user = 0
91
+                o.user = 1
92
+                self.FSM.ToTransition('toPosesPuck')
93
+
94
+def whisker_turns_goal(o):
95
+    if o.whiskers[0][0] and not o.whiskers[4][0]:
96
+        if 'goal' in o.whiskers[0][0]:
97
+            o.kb_d = 1
98
+            o.kb_a = 0
99
+            print('whisker turn d')
100
+
101
+    if o.whiskers[4][0] and not o.whiskers[0][0]:
102
+        if 'goal' in o.whiskers[4][0]:
103
+            o.kb_a = 1
104
+            o.kb_d = 0                
105
+            print('whisker turn a')

Loading…
Cancel
Save