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

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

+ 2
- 2
game.blend View File

1
 version https://git-lfs.github.com/spec/v1
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
 
2
 
3
 import StatesGame
3
 import StatesGame
4
 import StatesPlayer
4
 import StatesPlayer
5
+import StatesTeam
5
    
6
    
6
 #====================================
7
 #====================================
7
 class Transition(object):
8
 class Transition(object):
54
 Char = type("Char",(object,),{})
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
 class PlayerFSM(Char):
111
 class PlayerFSM(Char):
59
     def __init__(self, owner):
112
     def __init__(self, owner):
63
         state_list = [
116
         state_list = [
64
         'Shooting',
117
         'Shooting',
65
         'GetPuck',
118
         'GetPuck',
119
+        'GetPuckUser',
66
         'Passing',
120
         'Passing',
67
         'DefendPuck',
121
         'DefendPuck',
68
         'PosesPuck',
122
         'PosesPuck',
79
         'WindDump',
133
         'WindDump',
80
         'ShootDump',
134
         'ShootDump',
81
         'WindPass',
135
         'WindPass',
82
-        'ShootPass']
136
+        'ShootPass',
137
+        'ReceivePass', 
138
+        'DefendNet',
139
+        'DefendPursuePuck',
140
+        'DefendThirdMan',
141
+        'OffencePuck']
83
         
142
         
84
         for s in state_list:
143
         for s in state_list:
85
             self.FSM.AddState(s, getattr(StatesPlayer, s)(self.FSM))
144
             self.FSM.AddState(s, getattr(StatesPlayer, s)(self.FSM))
92
     def Execute(self):
151
     def Execute(self):
93
         self.FSM.Execute(self.owner)    
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
     def __init__(self, owner):
178
     def __init__(self, owner):
99
         self.FSM = FSM(self, owner)
179
         self.FSM = FSM(self, owner)
100
         self.owner = owner
180
         self.owner = owner
101
         
181
         
102
         state_list = [
182
         state_list = [
103
-        'MatchIntro',
104
-        'FaceOff',
105
-        'FaceoffIntro',
106
-        'InPlay',
107
-        'GoalScored']
183
+        'Example']
108
         
184
         
109
         for s in state_list:
185
         for s in state_list:
110
             self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
186
             self.FSM.AddState(s, getattr(StatesGame, s)(self.FSM))
112
             self.FSM.AddTransition(t, Transition(s))
188
             self.FSM.AddTransition(t, Transition(s))
113
         
189
         
114
         if self.FSM.curState == None:
190
         if self.FSM.curState == None:
115
-            self.FSM.SetState('MatchIntro')
191
+            self.FSM.SetState('Example')
116
     
192
     
117
     def Execute(self):
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

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
         super(FaceOff, self).Enter() 
40
         super(FaceOff, self).Enter() 
41
         g = self.FSM.owner
41
         g = self.FSM.owner
42
         g.sound_man.queue_sound(['whistle', g.center_ice, g.camera])
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
     def Execute(self):
48
     def Execute(self):
46
         self.FSM.stateLife += 1
49
         self.FSM.stateLife += 1
57
             #g.puck.worldPosition = [0,0,40]
60
             #g.puck.worldPosition = [0,0,40]
58
             g.puck_update = True
61
             g.puck_update = True
59
             self.FSM.ToTransition('toInPlay')
62
             self.FSM.ToTransition('toInPlay')
63
+            g.a_team.FSM.FSM.ToTransition('toChase')
64
+            g.b_team.FSM.FSM.ToTransition('toChase')
60
             g.sound_man.queue_sound(['puck_drop', g.center_ice, g.camera])
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
     def Exit(self):
70
     def Exit(self):
66
         pass   
71
         pass   
67
     
72
     
80
         
85
         
81
     def Execute(self):
86
     def Execute(self):
82
         self.FSM.stateLife += 1
87
         self.FSM.stateLife += 1
83
-        print('faceoff intro')
88
+        #print('faceoff intro')
84
         if self.FSM.stateLife > 240:
89
         if self.FSM.stateLife > 240:
85
 
90
 
86
             self.FSM.ToTransition('toFaceOff')
91
             self.FSM.ToTransition('toFaceOff')
87
                 
92
                 
88
             
93
             
89
-        print('faceoff')
94
+        #print('faceoff')
90
     def Exit(self):
95
     def Exit(self):
91
         pass        
96
         pass        
92
     
97
     
104
         
109
         
105
     def Execute(self):
110
     def Execute(self):
106
         self.FSM.stateLife += 1
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
         if self.FSM.stateLife > 340:
127
         if self.FSM.stateLife > 340:
110
             self.FSM.ToTransition('toFaceoffIntro')
128
             self.FSM.ToTransition('toFaceoffIntro')
111
         #print('goal')
129
         #print('goal')
122
         
140
         
123
     def Execute(self):
141
     def Execute(self):
124
         self.FSM.stateLife += 1
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
         #if self.FSM.stateLife > 20:
147
         #if self.FSM.stateLife > 20:
128
             #self.FSM.ToTransition('toGoalScored')
148
             #self.FSM.ToTransition('toGoalScored')
129
         #print('inplay')
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
     def Exit(self):
187
     def Exit(self):
131
         pass      
188
         pass      
132
     
189
     

+ 462
- 105
scripts/StatesPlayer.py View File

1
 import utils
1
 import utils
2
+from mathutils import Vector
2
 
3
 
3
 State = type("State", (object,), {})
4
 State = type("State", (object,), {})
4
 #====================================     
5
 #====================================     
50
         o = self.FSM.owner
51
         o = self.FSM.owner
51
         g = o.me['game']
52
         g = o.me['game']
52
         utils.update_whiskers(o)
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
         if o.user == 1:
56
         if o.user == 1:
62
             o.update_inputs() 
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
                     o.switch_player()
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
                 o.check_check()
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
         if o.team == 1:
71
         if o.team == 1:
73
             self.FSM.ToTransition('toDefendPuck')
72
             self.FSM.ToTransition('toDefendPuck')
75
     def Exit(self):
74
     def Exit(self):
76
         pass
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
 class PosesPuck(State):
123
 class PosesPuck(State):
87
         self.FSM.stateLife = 1
130
         self.FSM.stateLife = 1
88
         o = self.FSM.owner
131
         o = self.FSM.owner
89
         g = o.me['game'] 
132
         g = o.me['game'] 
90
-        o.puck_trigger = False       
133
+        o.puck_trigger = False 
134
+        o.orders = None      
91
         if o.team == 0:
135
         if o.team == 0:
92
             g.team_possession = 1
136
             g.team_possession = 1
93
         if o.team == 1:
137
         if o.team == 1:
97
         o = self.FSM.owner
141
         o = self.FSM.owner
98
         g = o.me['game']
142
         g = o.me['game']
99
         self.FSM.stateLife += 1
143
         self.FSM.stateLife += 1
100
-        #print('possessing')
101
-        #print(o.kb_da, o.state)
144
+
102
         #ai        
145
         #ai        
103
         if o.mates.user == 0:
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
                 g.puck.worldPosition = o.stick_empty.worldPosition
149
                 g.puck.worldPosition = o.stick_empty.worldPosition
106
                 g.puck.linearVelocity = [0,0,0]  
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
                 g.puck.applyForce([1,0,0], True)
153
                 g.puck.applyForce([1,0,0], True)
111
                 o.puck = False
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
                 self.FSM.ToTransition('toDefendPuck') 
166
                 self.FSM.ToTransition('toDefendPuck') 
114
                 o.mates.possession = False              
167
                 o.mates.possession = False              
115
                 o.puck = False
168
                 o.puck = False
116
         #user  
169
         #user  
117
-#        elif o.state != 'chasing':
118
-#            g.puck.worldPosition = o.stick_empty.worldPosition
119
-#            g.puck.linearVelocity = [0,0,0]  
170
+
120
         else:
171
         else:
121
             #check inputs
172
             #check inputs
122
             o.update_inputs()    
173
             o.update_inputs()    
125
             #print(o.kb_da)             
176
             #print(o.kb_da)             
126
             #if o.kb_da == 1 and o.last_kb_da == 0:
177
             #if o.kb_da == 1 and o.last_kb_da == 0:
127
             if o.mates.user_input.i_da == 1 and o.mates.user_input.i_last_da == 0: 
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
                 self.FSM.ToTransition('toWindShot')    
180
                 self.FSM.ToTransition('toWindShot')    
130
             #if o.kb_ua == 1 and o.last_kb_ua == 0:
181
             #if o.kb_ua == 1 and o.last_kb_ua == 0:
131
             if o.mates.user_input.i_ua == 1 and o.mates.user_input.i_last_ua == 0:                 
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
             o.user_movement()
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
     def Exit(self):
197
     def Exit(self):
138
         o = self.FSM.owner
198
         o = self.FSM.owner
148
         super(DefendPuck, self).__init__(FSM)    
208
         super(DefendPuck, self).__init__(FSM)    
149
         
209
         
150
     def Enter(self):
210
     def Enter(self):
151
-        print('Preparing to defend.')
211
+        #print('Preparing to defend.')
152
         self.FSM.stateLife = 1
212
         self.FSM.stateLife = 1
153
         super(DefendPuck, self).Enter()
213
         super(DefendPuck, self).Enter()
154
         
214
         
166
 
226
 
167
         o.simple_align(.04)    
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
     def Exit(self):
238
     def Exit(self):
225
         pass         
239
         pass         
231
         super(Passing, self).__init__(FSM)    
245
         super(Passing, self).__init__(FSM)    
232
         
246
         
233
     def Enter(self):
247
     def Enter(self):
234
-        print('Preparing to Passing.')
248
+        #print('Preparing to Passing.')
235
         self.FSM.stateLife = 1
249
         self.FSM.stateLife = 1
236
         super(Passing, self).Enter()
250
         super(Passing, self).Enter()
237
         o = self.FSM.owner        
251
         o = self.FSM.owner        
243
 
257
 
244
         players.sort(reverse=False, key=sortClosestToPlayer)        
258
         players.sort(reverse=False, key=sortClosestToPlayer)        
245
         players.remove(o)
259
         players.remove(o)
246
-        print(players)
260
+        #print(players)
247
         self.closest = players
261
         self.closest = players
248
 
262
 
249
     def Execute(self):
263
     def Execute(self):
294
                     o.state = 'chasing'
308
                     o.state = 'chasing'
295
                     self.FSM.ToTransition('toGetPuck')
309
                     self.FSM.ToTransition('toGetPuck')
296
                     #print('exit')
310
                     #print('exit')
297
-                o.puck = False
311
+                #o.puck = False
298
             
312
             
299
     def Exit(self):
313
     def Exit(self):
300
-        print('Finished Passing')   
314
+        #print('Finished Passing')   
301
         o = self.FSM.owner        
315
         o = self.FSM.owner        
302
         g = o.me['game']
316
         g = o.me['game']
303
         o.puck = False 
317
         o.puck = False 
313
         super(Shooting, self).__init__(FSM)  
327
         super(Shooting, self).__init__(FSM)  
314
         
328
         
315
     def Enter(self):
329
     def Enter(self):
316
-        print('Starting to Shooting.')
330
+        #print('Starting to Shooting.')
317
         super(Shooting, self).Enter()
331
         super(Shooting, self).Enter()
318
         self.FSM.stateLife = 1
332
         self.FSM.stateLife = 1
319
         
333
         
322
 
336
 
323
             
337
             
324
     def Exit(self):
338
     def Exit(self):
325
-        print('Waking up from Shooting.')          
339
+        #print('Waking up from Shooting.')          
326
         o = self.FSM.owner        
340
         o = self.FSM.owner        
327
         g = o.me['game']
341
         g = o.me['game']
328
         o.puck = False  
342
         o.puck = False  
488
         
502
         
489
     def Enter(self):
503
     def Enter(self):
490
         self.FSM.stateLife = 1
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
     def Execute(self):
511
     def Execute(self):
494
         self.FSM.stateLife += 1
512
         self.FSM.stateLife += 1
495
         o = self.FSM.owner
513
         o = self.FSM.owner
515
             g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
533
             g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
516
             self.FSM.ToTransition('toShootShot')
534
             self.FSM.ToTransition('toShootShot')
517
             o.stick.applyRotation([0,0,-.22], True)   
535
             o.stick.applyRotation([0,0,-.22], True)   
518
-            o.puck = False
536
+            #o.puck = False
519
             o.mates.possession = False         
537
             o.mates.possession = False         
520
         
538
         
521
     def Exit(self):
539
     def Exit(self):
532
         super(ShootDumpm, self).Enter()  
550
         super(ShootDumpm, self).Enter()  
533
         o = self.FSM.owner
551
         o = self.FSM.owner
534
         g = o.me['game']
552
         g = o.me['game']
535
-        o.puck = False      
553
+        #o.puck = False      
536
         g.puck.worldOrientation = o.base.worldOrientation
554
         g.puck.worldOrientation = o.base.worldOrientation
537
         g.puck.applyForce([200,0,0], True)
555
         g.puck.applyForce([200,0,0], True)
538
     def Execute(self):
556
     def Execute(self):
540
         o = self.FSM.owner
558
         o = self.FSM.owner
541
         g = o.me['game']
559
         g = o.me['game']
542
         o.stick.applyRotation([0,0,-.22], True)   
560
         o.stick.applyRotation([0,0,-.22], True)   
543
-        o.puck = False         
561
+        #o.puck = False         
544
         
562
         
545
         if self.FSM.stateLife > 20:
563
         if self.FSM.stateLife > 20:
546
             self.FSM.ToTransition('toGetPuck')
564
             self.FSM.ToTransition('toGetPuck')
547
     
565
     
548
     def Exit(self):
566
     def Exit(self):
549
-        pass
567
+        o = self.FSM.owner
568
+        o.puck = False
550
 
569
 
551
 
570
 
552
 class WindPass(State):
571
 class WindPass(State):
559
 
578
 
560
         o = self.FSM.owner        
579
         o = self.FSM.owner        
561
         g = o.me['game']
580
         g = o.me['game']
581
+        self.target = None
562
         players = o.mates.players.copy()
582
         players = o.mates.players.copy()
563
 
583
 
564
         def sortClosestToPlayer(e):
584
         def sortClosestToPlayer(e):
566
             
586
             
567
         players.sort(reverse=False, key=sortClosestToPlayer)        
587
         players.sort(reverse=False, key=sortClosestToPlayer)        
568
         players.remove(o)
588
         players.remove(o)
569
-        print(players)
589
+        #print(players)
570
         self.closest = players
590
         self.closest = players
571
-
591
+        o.puck = True
572
         #set o.pass_id       
592
         #set o.pass_id       
573
         
593
         
574
     def Execute(self):
594
     def Execute(self):
578
         
598
         
579
 
599
 
580
 
600
 
581
-                  
601
+        #o.puck = True          
582
     
602
     
583
         #if o.kb_la == 1 or o.kb_ra == 1:
603
         #if o.kb_la == 1 or o.kb_ra == 1:
584
         if o.mates.user_input.i_la == 1 or o.mates.user_input.i_ra == 1:                         
604
         if o.mates.user_input.i_la == 1 or o.mates.user_input.i_ra == 1:                         
585
             #if o.kb_la == 1:
605
             #if o.kb_la == 1:
606
+            
586
             if o.mates.user_input.i_la == 1:                 
607
             if o.mates.user_input.i_la == 1:                 
587
                 v = o.cont.getVectTo(self.closest[0].puck_empty)
608
                 v = o.cont.getVectTo(self.closest[0].puck_empty)
609
+                self.target = self.closest[0]
588
             #elif o.kb_ra == 1:  
610
             #elif o.kb_ra == 1:  
589
             elif o.mates.user_input.i_ra == 1:             
611
             elif o.mates.user_input.i_ra == 1:             
590
                 v = o.cont.getVectTo(self.closest[1].puck_empty)
612
                 v = o.cont.getVectTo(self.closest[1].puck_empty)
613
+                self.target = self.closest[1]
591
             stre = .1
614
             stre = .1
592
             o.stick.alignAxisToVect(v[1], 0, stre)        
615
             o.stick.alignAxisToVect(v[1], 0, stre)        
593
             o.cont.alignAxisToVect(v[1], 0, stre)                        
616
             o.cont.alignAxisToVect(v[1], 0, stre)                        
603
             g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
626
             g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
604
             self.FSM.ToTransition('toShootShot')
627
             self.FSM.ToTransition('toShootShot')
605
             o.stick.applyRotation([0,0,-.22], True)   
628
             o.stick.applyRotation([0,0,-.22], True)   
606
-            o.puck = False
629
+            #o.puck = False
607
             o.mates.possession = False         
630
             o.mates.possession = False         
608
         
631
         
609
     def Exit(self):
632
     def Exit(self):
633
+        if self.target != None:
634
+            self.target.FSM.FSM.ToTransition('toReceivePass')
635
+            print('receive')
610
         pass
636
         pass
611
 
637
 
612
 #====================================  
638
 #====================================  
620
         super(ShootPass, self).Enter()  
646
         super(ShootPass, self).Enter()  
621
         o = self.FSM.owner
647
         o = self.FSM.owner
622
         g = o.me['game']
648
         g = o.me['game']
623
-        o.puck = False      
649
+        #o.puck = False      
624
         g.puck.worldOrientation = o.base.worldOrientation
650
         g.puck.worldOrientation = o.base.worldOrientation
625
         g.puck.applyForce([200,0,0], True)
651
         g.puck.applyForce([200,0,0], True)
626
     def Execute(self):
652
     def Execute(self):
628
         o = self.FSM.owner
654
         o = self.FSM.owner
629
         g = o.me['game']
655
         g = o.me['game']
630
         o.stick.applyRotation([0,0,-1.72], True)   
656
         o.stick.applyRotation([0,0,-1.72], True)   
631
-        o.puck = False         
657
+        #o.puck = False         
632
         
658
         
633
         if self.FSM.stateLife > 20:
659
         if self.FSM.stateLife > 20:
634
             self.FSM.ToTransition('toGetPuck')
660
             self.FSM.ToTransition('toGetPuck')
635
     
661
     
636
     def Exit(self):
662
     def Exit(self):
637
-        pass
663
+        o = self.FSM.owner
664
+        o.puck = False         
638
 
665
 
639
                  
666
                  
640
 #====================================                      
667
 #====================================                      
645
         
672
         
646
     def Enter(self):
673
     def Enter(self):
647
         self.FSM.stateLife = 1
674
         self.FSM.stateLife = 1
675
+        o = self.FSM.owner
676
+        o.puck = True     
677
+
648
         super(WindShot, self).Enter()        
678
         super(WindShot, self).Enter()        
649
         
679
         
650
     def Execute(self):
680
     def Execute(self):
672
             g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
702
             g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
673
             self.FSM.ToTransition('toShootShot')
703
             self.FSM.ToTransition('toShootShot')
674
             o.stick.applyRotation([0,0,-.22], True)   
704
             o.stick.applyRotation([0,0,-.22], True)   
675
-            o.puck = False
705
+            #o.puck = False
676
             o.mates.possession = False         
706
             o.mates.possession = False         
677
         
707
         
678
     def Exit(self):
708
     def Exit(self):
689
         super(ShootShot, self).Enter()  
719
         super(ShootShot, self).Enter()  
690
         o = self.FSM.owner
720
         o = self.FSM.owner
691
         g = o.me['game']
721
         g = o.me['game']
692
-        o.puck = False      
722
+        #o.puck = False      
693
         g.puck.worldOrientation = o.base.worldOrientation
723
         g.puck.worldOrientation = o.base.worldOrientation
694
         g.puck.applyRotation([0,0,-.1], True)
724
         g.puck.applyRotation([0,0,-.1], True)
695
         g.puck.applyForce([200,0,0], True)
725
         g.puck.applyForce([200,0,0], True)
698
         o = self.FSM.owner
728
         o = self.FSM.owner
699
         g = o.me['game']
729
         g = o.me['game']
700
         o.stick.applyRotation([0,0,-.22], True)   
730
         o.stick.applyRotation([0,0,-.22], True)   
701
-        o.puck = False         
731
+        #o.puck = False         
702
         
732
         
703
         if self.FSM.stateLife > 20:
733
         if self.FSM.stateLife > 20:
704
             self.FSM.ToTransition('toGetPuck')
734
             self.FSM.ToTransition('toGetPuck')
705
     
735
     
706
     def Exit(self):
736
     def Exit(self):
707
-        pass
737
+        o = self.FSM.owner
738
+        o.puck = False
708
 
739
 
709
 #====================================  
740
 #====================================  
710
 
741
 
831
         o = self.FSM.owner
862
         o = self.FSM.owner
832
         self.checker = o.checked 
863
         self.checker = o.checked 
833
         o.checked = None      
864
         o.checked = None      
865
+        o.puck = False
866
+        o.controlled = False
867
+        o.puck_trigger = False
868
+        o.user = False
834
         
869
         
835
     def Execute(self):
870
     def Execute(self):
836
         self.FSM.stateLife += 1
871
         self.FSM.stateLife += 1
838
         g = o.me['game']
873
         g = o.me['game']
839
 
874
 
840
         tilt = -.01
875
         tilt = -.01
876
+        o.puck_trigger = False
841
         
877
         
842
         local = o.cont.worldOrientation.inverted() * (self.checker.cont.worldPosition - o.cont.worldPosition) 
878
         local = o.cont.worldOrientation.inverted() * (self.checker.cont.worldPosition - o.cont.worldPosition) 
843
-        print(local)
879
+        #print(local)
844
         if local.x > 0:
880
         if local.x > 0:
845
             #target is in front
881
             #target is in front
846
             print('in front')
882
             print('in front')
866
 
902
 
867
         o.body.applyRotation([0, tilt2, 0], True)     
903
         o.body.applyRotation([0, tilt2, 0], True)     
868
         o.head.applyRotation([0, (tilt2 * 1.2), 0], True) 
904
         o.head.applyRotation([0, (tilt2 * 1.2), 0], True) 
869
-        if self.FSM.stateLife > 20:
905
+        if self.FSM.stateLife > 60:
870
             self.FSM.ToTransition('toDefendPuck')
906
             self.FSM.ToTransition('toDefendPuck')
871
     
907
     
872
     def Exit(self):
908
     def Exit(self):
873
         pass
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

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

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
 
10
 
11
 #team_a_colors = [[.7,.7,.3,1], [.9,.1,.1,1], [.1, .1, .1, 1]]           
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]]
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
 positions = [[3,0], [4,-3], [6, 3], [8, -4]]
19
 positions = [[3,0], [4,-3], [6, 3], [8, -4]]
29
         if opos > - 3 and opos < 6:
33
         if opos > - 3 and opos < 6:
30
             self.camera.worldPosition.x = opos + 10
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
 class user_input:
72
 class user_input:
33
     def __init__(self, type):
73
     def __init__(self, type):
34
         self.type = type
74
         self.type = type
81
 class cpu_input(user_input):
121
 class cpu_input(user_input):
82
     def __init__(self, type):
122
     def __init__(self, type):
83
         self.type = type
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
     def update(self):
145
     def update(self):
85
         pass
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
 class keyboard_input(user_input):
170
 class keyboard_input(user_input):
89
     def __init__(self, type):
171
     def __init__(self, type):
153
 
235
 
154
     def update(self):    
236
     def update(self):    
155
         if bge.logic.joysticks[self.stick]:
237
         if bge.logic.joysticks[self.stick]:
156
-            print(bge.logic.joysticks[self.stick].activeButtons)
238
+            #print(bge.logic.joysticks[self.stick].activeButtons)
157
             sens = .4
239
             sens = .4
240
+            sens2 = .6
158
             if 0 in bge.logic.joysticks[self.stick].activeButtons:
241
             if 0 in bge.logic.joysticks[self.stick].activeButtons:
159
                 self.i_da = 1
242
                 self.i_da = 1
160
-            if 1 in bge.logic.joysticks[self.stick].activeButtons:
161
-                self.i_la = 1
162
             if 2 in bge.logic.joysticks[self.stick].activeButtons:
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
                 self.i_ra = 1
246
                 self.i_ra = 1
164
             if 3 in bge.logic.joysticks[self.stick].activeButtons:
247
             if 3 in bge.logic.joysticks[self.stick].activeButtons:
165
                 self.i_ua = 1
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
                 self.i_ls = 1
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
                 self.i_a = 1
254
                 self.i_a = 1
172
             if bge.logic.joysticks[self.stick].axisValues[1] < -sens:
255
             if bge.logic.joysticks[self.stick].axisValues[1] < -sens:
173
                 self.i_w = 1            
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
                 self.i_d = 1
258
                 self.i_d = 1
176
             if bge.logic.joysticks[self.stick].axisValues[1] > sens:
259
             if bge.logic.joysticks[self.stick].axisValues[1] > sens:
177
                 self.i_s = 1                        
260
                 self.i_s = 1                        
189
 
272
 
190
             #inputs.JoystickButton(joystickIndex, buttonIndex)            
273
             #inputs.JoystickButton(joystickIndex, buttonIndex)            
191
 class team:
274
 class team:
192
-    def __init__(self, name, colors, user):
275
+    def __init__(self, name, colors, user, game):
193
         self.name = name
276
         self.name = name
277
+        self.game = game
194
         self.colors = colors
278
         self.colors = colors
195
         self.players = []
279
         self.players = []
196
         self.puck_closest = []
280
         self.puck_closest = []
281
+        self.net_closest = []
197
         self.possession = False
282
         self.possession = False
283
+        self.scored = False
198
         self.switch_player_frame = [0,0,0,0]
284
         self.switch_player_frame = [0,0,0,0]
199
         self.user = user
285
         self.user = user
200
         self.user_input = None
286
         self.user_input = None
287
+        self.FSM = FSM.TeamFSM(self)
288
+        self.own_net = None
201
         
289
         
202
     def update(self, game):
290
     def update(self, game):
203
         
291
         
205
             return e.cont.getDistanceTo(game.puck.worldPosition)
293
             return e.cont.getDistanceTo(game.puck.worldPosition)
206
         self.puck_closest.sort(reverse=False, key=sortClosestToPuck)
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
 class game:
314
 class game:
214
     def __init__(self, obj, cont):
315
     def __init__(self, obj, cont):
235
         self.team_b_user = 0
336
         self.team_b_user = 0
236
         self.center_ice = self.scene.objects['center_ice']
337
         self.center_ice = self.scene.objects['center_ice']
237
         self.score = [0,0]
338
         self.score = [0,0]
339
+        self.score_overlay = ScoreOverlay(self)
340
+        self.clock_time = 0
238
         #team properties: name, colors, user
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
         #self.a_team.user_input = keyboard_input(1)
344
         #self.a_team.user_input = keyboard_input(1)
242
         self.a_team.user_input = joystick_input(2, 0)
345
         self.a_team.user_input = joystick_input(2, 0)
243
         #self.b_team.user_input = joystick_input(3, 1)
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
         self.FSM = FSM.GameFSM(self) 
352
         self.FSM = FSM.GameFSM(self) 
247
     
353
     
331
                     
437
                     
332
         self.FSM.Execute() 
438
         self.FSM.Execute() 
333
         self.sound_man.update() 
439
         self.sound_man.update() 
334
-        
440
+        self.score_overlay.update()
335
         #print(self.team_a_user_input.i_w)
441
         #print(self.team_a_user_input.i_w)
336
         #print(self.team_b_user_input.i_da)
442
         #print(self.team_b_user_input.i_da)
337
         
443
         
338
         
444
         
339
         #print(self.score)  
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
 class hockey_player():
453
 class hockey_player():
342
     def __init__(self, team, other, contr):
454
     def __init__(self, team, other, contr):
343
         scene = bge.logic.getCurrentScene()
455
         scene = bge.logic.getCurrentScene()
375
         self.switch_player_frame = [0,0,0,0]
487
         self.switch_player_frame = [0,0,0,0]
376
         self.faceoff_pos = [0, 0, 0]           
488
         self.faceoff_pos = [0, 0, 0]           
377
         self.team = team
489
         self.team = team
490
+        self.role = None
491
+        self.orders = None
378
 
492
 
379
         self.teammates = []
493
         self.teammates = []
380
             
494
             
438
         self.last_kb_ls = self.kb_ls
552
         self.last_kb_ls = self.kb_ls
439
         self.last_kb_sp = self.kb_sp
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
     def user_movement(self):
581
     def user_movement(self):
582
+        #print(self.kb_a)
453
         own = self.cont
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
             self.speed_tilt_timer += 1
586
             self.speed_tilt_timer += 1
457
             if own.linearVelocity.x < 2:
587
             if own.linearVelocity.x < 2:
458
                 own.applyForce([13,0,0], True)
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
                 #if self.last_kb_ls == 0:
591
                 #if self.last_kb_ls == 0:
462
                 if self.mates.user_input.i_last_ls == 0:      
592
                 if self.mates.user_input.i_last_ls == 0:      
463
                     self.speed_tilt_timer = 0
593
                     self.speed_tilt_timer = 0
465
                     own.applyForce([16,0,0], True)                    
595
                     own.applyForce([16,0,0], True)                    
466
         else:
596
         else:
467
             self.speed_tilt_timer = 0
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
             if own.linearVelocity.x > -2:
600
             if own.linearVelocity.x > -2:
471
                 own.applyForce([-13,0,0], True)
601
                 own.applyForce([-13,0,0], True)
472
         
602
         
475
         time = 25  
605
         time = 25  
476
         time2 = 25 
606
         time2 = 25 
477
         aligned = False     
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
             self.turn_timer += 1
610
             self.turn_timer += 1
481
             own.applyRotation([0, 0, .04], True)
611
             own.applyRotation([0, 0, .04], True)
482
             if self.turn_timer < time:
612
             if self.turn_timer < time:
483
                 self.body.applyRotation([-tilt, 0, 0], True)
613
                 self.body.applyRotation([-tilt, 0, 0], True)
484
                 self.head.applyRotation([(tilt2 * -1.2), 0, 0], True)
614
                 self.head.applyRotation([(tilt2 * -1.2), 0, 0], True)
485
                 #aligned = True                
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
             self.turn_timer += 1
618
             self.turn_timer += 1
489
             own.applyRotation([0, 0, -.04], True)  
619
             own.applyRotation([0, 0, -.04], True)  
490
             if self.turn_timer < time:
620
             if self.turn_timer < time:
557
         #print(mates, since_switch_a)
687
         #print(mates, since_switch_a)
558
         for m in mates:
688
         for m in mates:
559
             m.user = 0
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
     def check_puck(self):
708
     def check_puck(self):
572
         if self.FSM.FSM.stateLife > 120:
709
         if self.FSM.FSM.stateLife > 120:
579
                 self.puck = True
716
                 self.puck = True
580
                 if self.mates.user > 0:
717
                 if self.mates.user > 0:
581
                     self.user = 1 
718
                     self.user = 1 
582
-                    #print('check_puck function switching user') 
583
                 self.FSM.FSM.ToTransition('toPosesPuck')
719
                 self.FSM.FSM.ToTransition('toPosesPuck')
584
                 self.state = 'possession' 
720
                 self.state = 'possession' 
585
 
721
 
600
             if distances != []:
736
             if distances != []:
601
                 #sort list of whiskers
737
                 #sort list of whiskers
602
                 nd = sorted(distances, key=lambda x: x[1])
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
                 #sort list of whiskers
740
                 #sort list of whiskers
607
                 if nd[0][1] < 1.1:
741
                 if nd[0][1] < 1.1:
608
                     self.FSM.FSM.ToTransition('toCheckOn') 
742
                     self.FSM.FSM.ToTransition('toCheckOn') 
609
-                    print(nd[0][0][0]['c_ref'])
743
+                    #print(nd[0][0][0]['c_ref'])
610
                     nd[0][0][0]['c_ref'].checked = self                          
744
                     nd[0][0][0]['c_ref'].checked = self                          
611
                 else:    
745
                 else:    
612
                     self.FSM.FSM.ToTransition('toCheckMissOn')        
746
                     self.FSM.FSM.ToTransition('toCheckMissOn')        
616
     def check_checked(self):
750
     def check_checked(self):
617
         if self.checked == True:
751
         if self.checked == True:
618
             #self.checked = False
752
             #self.checked = False
619
-            print('--------checked')
753
+            #print('--------checked')
620
             return True    
754
             return True    
621
         else:
755
         else:
622
             return False  
756
             return False  
650
             for x in self.me['game'].players:
784
             for x in self.me['game'].players:
651
                 if x.cont.worldPosition != self.cont.worldPosition and self.team == x.team:
785
                 if x.cont.worldPosition != self.cont.worldPosition and self.team == x.team:
652
                     self.teammates.append(x)
786
                     self.teammates.append(x)
653
-        
787
+        self.update_inputs()    
654
         self.update_indicator()
788
         self.update_indicator()
655
         self.align_to_base()
789
         self.align_to_base()
656
         self.FSM.Execute()
790
         self.FSM.Execute()
657
         #self.check_puck()
791
         #self.check_puck()
658
         state = str(self.FSM.FSM.curState.__class__.__name__)
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
         u = []
796
         u = []
663
         for x in self.mates.players:
797
         for x in self.mates.players:
664
             if x.puck == True:
798
             if x.puck == True:
670
             if x.user == 1:
804
             if x.user == 1:
671
                 u2.append(x)                
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
 def main(cont):
817
 def main(cont):
708
     own = cont.owner
818
     own = cont.owner
741
         if own.worldPosition.x < -12:
851
         if own.worldPosition.x < -12:
742
             own.worldPosition.x = -11.5
852
             own.worldPosition.x = -11.5
743
             print('puck out of bounds -x')
853
             print('puck out of bounds -x')
744
-        if own.worldPosition.y > 8.25:
854
+        if own.worldPosition.y > 8.15:
745
             own.worldPosition.y = 7.0
855
             own.worldPosition.y = 7.0
746
             #own.linearVelocity.x *= -1
856
             #own.linearVelocity.x *= -1
747
             print('puck out of bounds +y')
857
             print('puck out of bounds +y')
748
-        if own.worldPosition.y < -8.25:
858
+        if own.worldPosition.y < -8.15:
749
             own.worldPosition.y = -7.0
859
             own.worldPosition.y = -7.0
750
             print('puck out of bounds -y')
860
             print('puck out of bounds -y')
751
             #own.linearVelocity.x *= -1  
861
             #own.linearVelocity.x *= -1  
760
                 if g.frame - g.sound_man.board_played > 30:
870
                 if g.frame - g.sound_man.board_played > 30:
761
                     g.sound_man.queue_sound(['board', g.puck, g.camera])                                                
871
                     g.sound_man.queue_sound(['board', g.puck, g.camera])                                                
762
                     g.sound_man.board_played = g.frame 
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
             if cont.sensors['puck-player'].hitObject is not None:
876
             if cont.sensors['puck-player'].hitObject is not None:
765
                 ho = cont.sensors['puck-player'].hitObject
877
                 ho = cont.sensors['puck-player'].hitObject
766
                 for p in g.a_team.players + g.b_team.players:
878
                 for p in g.a_team.players + g.b_team.players:
775
                     print('GOOOAAAALLL!!', o['team'])
887
                     print('GOOOAAAALLL!!', o['team'])
776
                     if o['team'] == 'a':
888
                     if o['team'] == 'a':
777
                         g.score[0] += 1
889
                         g.score[0] += 1
890
+                        g.a_team.scored = True
778
                     if o['team'] == 'b':
891
                     if o['team'] == 'b':
779
-                        g.score[1] += 1    
892
+                        g.score[1] += 1 
893
+                        g.b_team.scored = True   
780
                     g.FSM.FSM.ToTransition('toGoalScored')
894
                     g.FSM.FSM.ToTransition('toGoalScored')
781
 
895
 
782
                     #if 'a2' in cont.sensors['puck-player'].hitObject['name']:
896
                     #if 'a2' in cont.sensors['puck-player'].hitObject['name']:

+ 73
- 5
scripts/utils.py View File

5
 
5
 
6
     color = [0,1,0]
6
     color = [0,1,0]
7
     iter = 0
7
     iter = 0
8
-
9
-    #cast all whisker rays
10
     l = len(self.whisker_objs)
8
     l = len(self.whisker_objs)
11
-    #print(l)
12
-    #for w in self.whisker_objs:
9
+
13
     while iter < l:
10
     while iter < l:
14
         rc = o.cont.rayCast(self.whisker_objs[iter].worldPosition,
11
         rc = o.cont.rayCast(self.whisker_objs[iter].worldPosition,
15
                             o.cont.worldPosition,
12
                             o.cont.worldPosition,
34
     #             #print(w[0])
31
     #             #print(w[0])
35
     #     #print(self.whiskers)
32
     #     #print(self.whiskers)
36
     #     bge.render.drawLine(o.cont.worldPosition, self.whisker_objs[iter].worldPosition, color)
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