shuvit 4 years ago
parent
commit
81b2495cfc
11 changed files with 463 additions and 84 deletions
  1. 1
    1
      assets/base_rink.blend
  2. 2
    2
      game.blend
  3. 5
    1
      scripts/FSM.py
  4. 9
    2
      scripts/StatesGame.py
  5. 199
    42
      scripts/StatesPlayer.py
  6. 226
    27
      scripts/player.py
  7. 3
    0
      scripts/sound_man.py
  8. 9
    9
      scripts/utils.py
  9. 3
    0
      sounds/goal.wav
  10. 3
    0
      sounds/puck_drop.wav
  11. 3
    0
      sounds/whistle.wav

+ 1
- 1
assets/base_rink.blend View File

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

+ 2
- 2
game.blend View File

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

+ 5
- 1
scripts/FSM.py View File

@@ -75,7 +75,11 @@ class PlayerFSM(Char):
75 75
         'CheckMissOff',
76 76
         'CheckOn',
77 77
         'CheckOff',
78
-        'Checked']
78
+        'Checked',
79
+        'WindDump',
80
+        'ShootDump',
81
+        'WindPass',
82
+        'ShootPass']
79 83
         
80 84
         for s in state_list:
81 85
             self.FSM.AddState(s, getattr(StatesPlayer, s)(self.FSM))

+ 9
- 2
scripts/StatesGame.py View File

@@ -37,7 +37,10 @@ class FaceOff(State):
37 37
         
38 38
     def Enter(self):
39 39
         self.FSM.stateLife = 1
40
-        super(FaceOff, self).Enter()        
40
+        super(FaceOff, self).Enter() 
41
+        g = self.FSM.owner
42
+        g.sound_man.queue_sound(['whistle', g.center_ice, g.camera])
43
+        print('whistling')       
41 44
         
42 45
     def Execute(self):
43 46
         self.FSM.stateLife += 1
@@ -54,6 +57,7 @@ class FaceOff(State):
54 57
             #g.puck.worldPosition = [0,0,40]
55 58
             g.puck_update = True
56 59
             self.FSM.ToTransition('toInPlay')
60
+            g.sound_man.queue_sound(['puck_drop', g.center_ice, g.camera])
57 61
 
58 62
                 
59 63
             
@@ -93,7 +97,10 @@ class GoalScored(State):
93 97
     def Enter(self):
94 98
         self.FSM.stateLife = 1
95 99
         super(GoalScored, self).Enter()        
96
-        self.FSM.owner.puck_update = False
100
+        g = self.FSM.owner
101
+        g.puck_update = False
102
+        
103
+        g.sound_man.queue_sound(['goal', g.center_ice, g.camera])
97 104
         
98 105
     def Execute(self):
99 106
         self.FSM.stateLife += 1

+ 199
- 42
scripts/StatesPlayer.py View File

@@ -61,9 +61,10 @@ class GetPuck(State):
61 61
         if o.user == 1:
62 62
             o.update_inputs() 
63 63
             if self.FSM.stateLife > 10:
64
-                if o.kb_da == 0 and o.last_kb_da == 1:
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:     
65 66
                     o.switch_player()
66
-                    print('fsm switch')
67
+                    #print('fsm switch')
67 68
                 o.check_check()
68 69
                 # if o.kb_ua == 1:
69 70
                 #     self.FSM.ToTransition('toCheckMissOn')
@@ -122,9 +123,14 @@ class PosesPuck(State):
122 123
             g.puck.worldPosition = o.stick_empty.worldPosition
123 124
             g.puck.linearVelocity = [0,0,0]             
124 125
             #print(o.kb_da)             
125
-            if o.kb_da == 1 and o.last_kb_da == 0:
126
+            #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: 
126 128
                 print('--- wind shot')
127
-                self.FSM.ToTransition('toWindShot')         
129
+                self.FSM.ToTransition('toWindShot')    
130
+            #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:                 
132
+                print('--- wind dump')
133
+                self.FSM.ToTransition('toWindDump')             
128 134
                 
129 135
             o.user_movement()
130 136
                 
@@ -228,18 +234,30 @@ class Passing(State):
228 234
         print('Preparing to Passing.')
229 235
         self.FSM.stateLife = 1
230 236
         super(Passing, self).Enter()
231
-        
237
+        o = self.FSM.owner        
238
+        g = o.me['game']
239
+        players = o.mates.players.copy()
240
+
241
+        def sortClosestToPlayer(e):
242
+            return e.cont.getDistanceTo(o.cont.worldPosition)
243
+
244
+        players.sort(reverse=False, key=sortClosestToPlayer)        
245
+        players.remove(o)
246
+        print(players)
247
+        self.closest = players
248
+
232 249
     def Execute(self):
233 250
         self.FSM.stateLife += 1
234 251
         o = self.FSM.owner        
235 252
         g = o.me['game']
236 253
         o.state = 'passing'
237 254
     
238
-        print('passing', self.FSM.stateLife, o.puck, o.user)
239
-        mates = o.mates.p_closest.copy()
240
-        mates.remove(o)    
241
-    
255
+        #print('passing', self.FSM.stateLife, o.puck, o.user)
256
+        #mates = o.mates.puck_closest.copy()
257
+        #mates.remove(o)    
258
+        
242 259
         v = o.cont.getVectTo(o.teammates[o.pass_id].cont)
260
+        v = o.cont.getVectTo(self.closest[0].cont)
243 261
         
244 262
         stre = .1
245 263
         o.stick.alignAxisToVect(v[1], 0, stre)        
@@ -259,7 +277,8 @@ class Passing(State):
259 277
             g.puck.worldPosition = o.puck_empty.worldPosition
260 278
             g.puck.linearVelocity = [0,0,0]            
261 279
 
262
-        if o.kb_la == 1 or o.kb_ra == 1:
280
+        #if o.kb_la == 1 or o.kb_ra == 1:
281
+        if o.mates.user_input.i_la == 1 or o.mates.user_input.i_ra == 1:             
263 282
             o.passing = 25
264 283
             #print('kb')   
265 284
         else:
@@ -344,7 +363,8 @@ class Dumping(State):
344 363
             g.puck.worldPosition = o.puck_empty.worldPosition
345 364
             g.puck.linearVelocity = [0,0,0]            
346 365
 
347
-        if o.kb_ua == 1:
366
+        #if o.kb_ua == 1:
367
+        if o.mates.user_input.i_ua == 1:             
348 368
             o.shooting = 25
349 369
             #print('kb')   
350 370
         else:
@@ -459,6 +479,163 @@ class Faceoff(State):
459 479
     
460 480
     def Exit(self):
461 481
         pass   
482
+
483
+
484
+
485
+class WindDump(State):
486
+    def __init__(self,FSM):
487
+        super(WindDump, self).__init__(FSM)    
488
+        
489
+    def Enter(self):
490
+        self.FSM.stateLife = 1
491
+        super(WindDump, self).Enter()        
492
+        
493
+    def Execute(self):
494
+        self.FSM.stateLife += 1
495
+        o = self.FSM.owner
496
+        g = o.me['game']
497
+        
498
+        # v = o.cont.getVectTo(o.goal_t)
499
+        # stre = .1
500
+        # o.stick.alignAxisToVect(v[1], 0, stre)        
501
+        # o.cont.alignAxisToVect(v[1], 0, stre)                        
502
+        e1 = o.cont.worldOrientation.to_euler().z
503
+        e2 = o.stick.worldOrientation.to_euler().z
504
+        dif = e1 - e2
505
+        if dif > -1.5:
506
+            o.stick.applyRotation([0,0,.15], True) 
507
+            
508
+        g.puck.worldPosition = o.puck_empty.worldPosition
509
+        g.puck.linearVelocity = [0,0,0]            
510
+    
511
+        #if o.kb_ua == 1:
512
+        if o.mates.user_input.i_ua == 1:                         
513
+            pass
514
+        else:
515
+            g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
516
+            self.FSM.ToTransition('toShootShot')
517
+            o.stick.applyRotation([0,0,-.22], True)   
518
+            o.puck = False
519
+            o.mates.possession = False         
520
+        
521
+    def Exit(self):
522
+        pass
523
+
524
+#====================================  
525
+
526
+class ShootDump(State):
527
+    def __init__(self,FSM):
528
+        super(ShootDump, self).__init__(FSM)    
529
+        
530
+    def Enter(self):
531
+        self.FSM.stateLife = 1
532
+        super(ShootDumpm, self).Enter()  
533
+        o = self.FSM.owner
534
+        g = o.me['game']
535
+        o.puck = False      
536
+        g.puck.worldOrientation = o.base.worldOrientation
537
+        g.puck.applyForce([200,0,0], True)
538
+    def Execute(self):
539
+        self.FSM.stateLife += 1
540
+        o = self.FSM.owner
541
+        g = o.me['game']
542
+        o.stick.applyRotation([0,0,-.22], True)   
543
+        o.puck = False         
544
+        
545
+        if self.FSM.stateLife > 20:
546
+            self.FSM.ToTransition('toGetPuck')
547
+    
548
+    def Exit(self):
549
+        pass
550
+
551
+
552
+class WindPass(State):
553
+    def __init__(self,FSM):
554
+        super(WindPass, self).__init__(FSM)    
555
+        
556
+    def Enter(self):
557
+        self.FSM.stateLife = 1
558
+        super(WindPass, self).Enter() 
559
+
560
+        o = self.FSM.owner        
561
+        g = o.me['game']
562
+        players = o.mates.players.copy()
563
+
564
+        def sortClosestToPlayer(e):
565
+            return e.cont.getDistanceTo(o.cont.worldPosition)
566
+            
567
+        players.sort(reverse=False, key=sortClosestToPlayer)        
568
+        players.remove(o)
569
+        print(players)
570
+        self.closest = players
571
+
572
+        #set o.pass_id       
573
+        
574
+    def Execute(self):
575
+        self.FSM.stateLife += 1
576
+        o = self.FSM.owner
577
+        g = o.me['game']
578
+        
579
+
580
+
581
+                  
582
+    
583
+        #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:                         
585
+            #if o.kb_la == 1:
586
+            if o.mates.user_input.i_la == 1:                 
587
+                v = o.cont.getVectTo(self.closest[0].puck_empty)
588
+            #elif o.kb_ra == 1:  
589
+            elif o.mates.user_input.i_ra == 1:             
590
+                v = o.cont.getVectTo(self.closest[1].puck_empty)
591
+            stre = .1
592
+            o.stick.alignAxisToVect(v[1], 0, stre)        
593
+            o.cont.alignAxisToVect(v[1], 0, stre)                        
594
+            e1 = o.cont.worldOrientation.to_euler().z
595
+            e2 = o.stick.worldOrientation.to_euler().z
596
+            dif = e1 - e2
597
+            if dif > -1.5:
598
+                o.stick.applyRotation([0,0,.15], True) 
599
+                
600
+            g.puck.worldPosition = o.puck_empty.worldPosition
601
+            g.puck.linearVelocity = [0,0,0]  
602
+        else:
603
+            g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
604
+            self.FSM.ToTransition('toShootShot')
605
+            o.stick.applyRotation([0,0,-.22], True)   
606
+            o.puck = False
607
+            o.mates.possession = False         
608
+        
609
+    def Exit(self):
610
+        pass
611
+
612
+#====================================  
613
+
614
+class ShootPass(State):
615
+    def __init__(self,FSM):
616
+        super(ShootPass, self).__init__(FSM)    
617
+        
618
+    def Enter(self):
619
+        self.FSM.stateLife = 1
620
+        super(ShootPass, self).Enter()  
621
+        o = self.FSM.owner
622
+        g = o.me['game']
623
+        o.puck = False      
624
+        g.puck.worldOrientation = o.base.worldOrientation
625
+        g.puck.applyForce([200,0,0], True)
626
+    def Execute(self):
627
+        self.FSM.stateLife += 1
628
+        o = self.FSM.owner
629
+        g = o.me['game']
630
+        o.stick.applyRotation([0,0,-1.72], True)   
631
+        o.puck = False         
632
+        
633
+        if self.FSM.stateLife > 20:
634
+            self.FSM.ToTransition('toGetPuck')
635
+    
636
+    def Exit(self):
637
+        pass
638
+
462 639
                  
463 640
 #====================================                      
464 641
 
@@ -475,10 +652,7 @@ class WindShot(State):
475 652
         o = self.FSM.owner
476 653
         g = o.me['game']
477 654
         
478
-        
479
-        
480 655
         v = o.cont.getVectTo(o.goal_t)
481
-        
482 656
         stre = .1
483 657
         o.stick.alignAxisToVect(v[1], 0, stre)        
484 658
         o.cont.alignAxisToVect(v[1], 0, stre)                        
@@ -488,36 +662,19 @@ class WindShot(State):
488 662
         if dif > -1.5:
489 663
             o.stick.applyRotation([0,0,.15], True) 
490 664
             
491
- 
492 665
         g.puck.worldPosition = o.puck_empty.worldPosition
493 666
         g.puck.linearVelocity = [0,0,0]            
494 667
     
495
-        #if o.shooting == 15:
496
-        
497
-            
498
-        if o.kb_da == 1:
668
+        #if o.kb_da == 1:
669
+        if o.mates.user_input.i_da == 1:                         
499 670
             pass
500
-            #o.shooting = 25
501
-            #print('kb')   
502 671
         else:
503
-            #print(o.shooting)
504
-            #if o.shooting > 0:
505
-                #print('oshooting')
506
-            #dif = e1 - e2
507
-            #o.shooting -= 1
508 672
             g.sound_man.queue_sound(['shoot', o.cont, g.camera]) 
509 673
             self.FSM.ToTransition('toShootShot')
510 674
             o.stick.applyRotation([0,0,-.22], True)   
511 675
             o.puck = False
512 676
             o.mates.possession = False         
513 677
         
514
-        
515
-        
516
-        
517
-        #print('wind shot')
518
-        #if self.FSM.stateLife > 20:
519
-            #self.FSM.ToTransition('toShootShot')
520
-    
521 678
     def Exit(self):
522 679
         pass
523 680
 
@@ -531,13 +688,15 @@ class ShootShot(State):
531 688
         self.FSM.stateLife = 1
532 689
         super(ShootShot, self).Enter()  
533 690
         o = self.FSM.owner
691
+        g = o.me['game']
534 692
         o.puck = False      
535
-        
693
+        g.puck.worldOrientation = o.base.worldOrientation
694
+        g.puck.applyRotation([0,0,-.1], True)
695
+        g.puck.applyForce([200,0,0], True)
536 696
     def Execute(self):
537 697
         self.FSM.stateLife += 1
538 698
         o = self.FSM.owner
539
-        g = o.me
540
-        #print('shoot shot')
699
+        g = o.me['game']
541 700
         o.stick.applyRotation([0,0,-.22], True)   
542 701
         o.puck = False         
543 702
         
@@ -577,7 +736,8 @@ class CheckMissOn(State):
577 736
         o.stick.applyRotation([0, sr, 0], True)                    
578 737
         o.stick.applyMovement([sm, 0, 0], True)
579 738
 
580
-        if o.kb_ua != 1:
739
+        #if o.kb_ua != 1:
740
+        if o.mates.user_input.i_ua != 1:                         
581 741
             self.FSM.ToTransition('toCheckMissOff')
582 742
     
583 743
     def Exit(self):
@@ -604,7 +764,6 @@ class CheckMissOff(State):
604 764
 
605 765
 #====================================  
606 766
 
607
-
608 767
 class CheckOn(State):
609 768
     def __init__(self,FSM):
610 769
         super(CheckOn, self).__init__(FSM)    
@@ -634,7 +793,8 @@ class CheckOn(State):
634 793
         o.stick.applyRotation([0, sr, 0], True)                    
635 794
         o.stick.applyMovement([sm, 0, 0], True)
636 795
 
637
-        if o.kb_ua != 1:
796
+        #if o.kb_ua != 1:
797
+        if o.mates.user_input.i_ua != 1: 
638 798
             self.FSM.ToTransition('toCheckOff')
639 799
     
640 800
     def Exit(self):
@@ -702,8 +862,6 @@ class Checked(State):
702 862
             o.body.applyRotation([tilt, 0, 0], True)        
703 863
             o.head.applyRotation([(tilt * 1.2), 0, 0], True)     
704 864
 
705
-
706
-
707 865
         tilt2 = -.02
708 866
 
709 867
         o.body.applyRotation([0, tilt2, 0], True)     
@@ -715,4 +873,3 @@ class Checked(State):
715 873
         pass
716 874
 
717 875
 #====================================  
718
-

+ 226
- 27
scripts/player.py View File

@@ -28,29 +28,186 @@ def run_camera(self):
28 28
         #print(opos + 10)
29 29
         if opos > - 3 and opos < 6:
30 30
             self.camera.worldPosition.x = opos + 10
31
-            
31
+
32
+class user_input:
33
+    def __init__(self, type):
34
+        self.type = type
35
+        self.i_ua = 0
36
+        self.i_da = 0
37
+        self.i_ra = 0
38
+        self.i_la = 0
39
+        self.i_w = 0
40
+        self.i_a = 0
41
+        self.i_s = 0
42
+        self.i_d = 0
43
+        self.i_ls = 0
44
+        self.i_sp = 0
45
+        self.i_last_ua = 0
46
+        self.i_last_da = 0
47
+        self.i_last_ra = 0
48
+        self.i_last_la = 0
49
+        self.i_last_w = 0
50
+        self.i_last_a = 0
51
+        self.i_last_s = 0
52
+        self.i_last_d = 0
53
+        self.i_last_ls = 0
54
+        self.i_lastsp = 0
55
+
56
+    def update(self):
57
+        pass
58
+
59
+    def clear(self):
60
+        self.i_last_ua = self.i_ua
61
+        self.i_last_da = self.i_da
62
+        self.i_last_ra = self.i_ra
63
+        self.i_last_la = self.i_la
64
+        self.i_last_w = self.i_w
65
+        self.i_last_a = self.i_a
66
+        self.i_last_s = self.i_s
67
+        self.i_last_d = self.i_d
68
+        self.i_last_ls = self.i_ls
69
+        self.i_lastsp = self.i_sp
70
+        self.i_ua = 0
71
+        self.i_da = 0
72
+        self.i_ra = 0
73
+        self.i_la = 0
74
+        self.i_w = 0
75
+        self.i_a = 0
76
+        self.i_s = 0
77
+        self.i_d = 0
78
+        self.i_ls = 0
79
+        self.i_sp = 0
80
+
81
+class cpu_input(user_input):
82
+    def __init__(self, type):
83
+        self.type = type
84
+    def update(self):
85
+        pass
86
+
87
+
88
+class keyboard_input(user_input):
89
+    def __init__(self, type):
90
+        self.type = type
91
+
92
+        self.i_ua = 0
93
+        self.i_da = 0
94
+        self.i_ra = 0
95
+        self.i_la = 0
96
+        self.i_w = 0
97
+        self.i_a = 0
98
+        self.i_s = 0
99
+        self.i_d = 0
100
+        self.i_ls = 0
101
+        self.i_sp = 0
102
+        self.i_last_ua = 0
103
+        self.i_last_da = 0
104
+        self.i_last_ra = 0
105
+        self.i_last_la = 0
106
+        self.i_last_w = 0
107
+        self.i_last_a = 0
108
+        self.i_last_s = 0
109
+        self.i_last_d = 0
110
+        self.i_last_ls = 0
111
+        self.i_lastsp = 0    
112
+
113
+    def update(self):    
114
+
115
+        keyboard = bge.logic.keyboard.inputs  
116
+        
117
+
118
+        self.i_ua = bge.logic.keyboard.inputs[bge.events.UPARROWKEY].values[-1]
119
+        self.i_da = bge.logic.keyboard.inputs[bge.events.DOWNARROWKEY].values[-1]    
120
+        self.i_la = bge.logic.keyboard.inputs[bge.events.LEFTARROWKEY].values[-1]
121
+        self.i_ra = bge.logic.keyboard.inputs[bge.events.RIGHTARROWKEY].values[-1]
122
+        self.i_w = bge.logic.keyboard.inputs[bge.events.WKEY].values[-1]
123
+        self.i_a = bge.logic.keyboard.inputs[bge.events.AKEY].values[-1]    
124
+        self.i_s = bge.logic.keyboard.inputs[bge.events.SKEY].values[-1]
125
+        self.i_d = bge.logic.keyboard.inputs[bge.events.DKEY].values[-1]  
126
+        self.i_ls = bge.logic.keyboard.inputs[bge.events.LEFTSHIFTKEY].values[-1]    
127
+        self.i_sp = bge.logic.keyboard.inputs[bge.events.SPACEKEY].values[-1]         
128
+
129
+class joystick_input(user_input):
130
+    def __init__(self, itype, stick):
131
+        self.stick = stick
132
+        self.type = itype
133
+        self.i_ua = 0
134
+        self.i_da = 0
135
+        self.i_ra = 0
136
+        self.i_la = 0
137
+        self.i_w = 0
138
+        self.i_a = 0
139
+        self.i_s = 0
140
+        self.i_d = 0
141
+        self.i_ls = 0
142
+        self.i_sp = 0
143
+        self.i_last_ua = 0
144
+        self.i_last_da = 0
145
+        self.i_last_ra = 0
146
+        self.i_last_la = 0
147
+        self.i_last_w = 0
148
+        self.i_last_a = 0
149
+        self.i_last_s = 0
150
+        self.i_last_d = 0
151
+        self.i_last_ls = 0
152
+        self.i_lastsp = 0        
153
+
154
+    def update(self):    
155
+        if bge.logic.joysticks[self.stick]:
156
+            print(bge.logic.joysticks[self.stick].activeButtons)
157
+            sens = .4
158
+            if 0 in bge.logic.joysticks[self.stick].activeButtons:
159
+                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:
163
+                self.i_ra = 1
164
+            if 3 in bge.logic.joysticks[self.stick].activeButtons:
165
+                self.i_ua = 1
166
+            if 9 in bge.logic.joysticks[self.stick].activeButtons:
167
+                self.i_ls = 1
168
+
169
+
170
+            if bge.logic.joysticks[self.stick].axisValues[0] < -sens:
171
+                self.i_a = 1
172
+            if bge.logic.joysticks[self.stick].axisValues[1] < -sens:
173
+                self.i_w = 1            
174
+            if bge.logic.joysticks[self.stick].axisValues[0] > sens:
175
+                self.i_d = 1
176
+            if bge.logic.joysticks[self.stick].axisValues[1] > sens:
177
+                self.i_s = 1                        
178
+            #print(bge.logic.joysticks[0].axisValues[2])    
179
+            # self.i_ua = bge.logic.keyboard.inputs[bge.events.UPARROWKEY].values[-1]
180
+            # self.i_da = bge.logic.keyboard.inputs[bge.events.DOWNARROWKEY].values[-1]    
181
+            # self.i_la = bge.logic.keyboard.inputs[bge.events.LEFTARROWKEY].values[-1]
182
+            # self.i_ra = bge.logic.keyboard.inputs[bge.events.RIGHTARROWKEY].values[-1]
183
+            # self.i_w = bge.logic.keyboard.inputs[bge.events.WKEY].values[-1]
184
+            # self.i_a = bge.logic.keyboard.inputs[bge.events.AKEY].values[-1]    
185
+            # self.i_s = bge.logic.keyboard.inputs[bge.events.SKEY].values[-1]
186
+            # self.i_d = bge.logic.keyboard.inputs[bge.events.DKEY].values[-1]  
187
+            # self.i_ls = bge.logic.keyboard.inputs[bge.events.LEFTSHIFTKEY].values[-1]    
188
+            # self.i_sp = bge.logic.keyboard.inputs[bge.events.SPACEKEY].values[-1]         
189
+
190
+            #inputs.JoystickButton(joystickIndex, buttonIndex)            
32 191
 class team:
33 192
     def __init__(self, name, colors, user):
34 193
         self.name = name
35 194
         self.colors = colors
36 195
         self.players = []
37
-        self.p_closest = []
196
+        self.puck_closest = []
38 197
         self.possession = False
39 198
         self.switch_player_frame = [0,0,0,0]
40 199
         self.user = user
200
+        self.user_input = None
41 201
         
42 202
     def update(self, game):
43 203
         
44 204
         def sortClosestToPuck(e):
45 205
             return e.cont.getDistanceTo(game.puck.worldPosition)
46
-        self.p_closest.sort(reverse=False, key=sortClosestToPuck)
206
+        self.puck_closest.sort(reverse=False, key=sortClosestToPuck)
47 207
         
48 208
         a_list = []
49 209
         for x in self.players:
50
-            #a_list.append(str(x.FSM.FSM.curState.__class__.__name__))
51 210
             a_list.append(x.user)
52
-        #if self.name == 'a':
53
-            #print(a_list)
54 211
 
55 212
         
56 213
 class game:
@@ -76,10 +233,15 @@ class game:
76 233
         self.num_p_b = 3
77 234
         self.team_a_user = 1
78 235
         self.team_b_user = 0
79
-        
236
+        self.center_ice = self.scene.objects['center_ice']
237
+        self.score = [0,0]
80 238
         #team properties: name, colors, user
81 239
         self.a_team = team('a', team_a_colors, 1)
82 240
         self.b_team = team('b', team_b_colors, 0)
241
+        #self.a_team.user_input = keyboard_input(1)
242
+        self.a_team.user_input = joystick_input(2, 0)
243
+        #self.b_team.user_input = joystick_input(3, 1)
244
+        self.b_team.user_input = keyboard_input(1)
83 245
         
84 246
         self.FSM = FSM.GameFSM(self) 
85 247
     
@@ -109,7 +271,7 @@ class game:
109 271
                 p1.cont.worldPosition = [x, y, p1.cont.worldPosition.z]
110 272
                 
111 273
                 iter -= 1
112
-            self.a_team.p_closest = self.a_team.players.copy()    
274
+            self.a_team.puck_closest = self.a_team.players.copy()    
113 275
         #do team b
114 276
         if self.num_p_b > 0:
115 277
             iter = self.num_p_b
@@ -132,7 +294,7 @@ class game:
132 294
                 p1.faceoff_pos = [x,y] 
133 295
                 p1.cont.worldPosition = [x, y, p1.cont.worldPosition.z]
134 296
                 iter -= 1                
135
-            self.b_team.p_closest = self.b_team.players.copy()  
297
+            self.b_team.puck_closest = self.b_team.players.copy()  
136 298
             
137 299
                 
138 300
     def load_puck(self):
@@ -145,10 +307,16 @@ class game:
145 307
         #pass    
146 308
         self.frame += 1
147 309
         run_camera(self)
310
+
148 311
         if self.team_a == []:
149 312
             self.load_players()
150 313
             self.load_puck()
314
+        self.a_team.user_input.clear()
315
+        self.b_team.user_input.clear()    
151 316
         
317
+        self.a_team.user_input.update()
318
+        self.b_team.user_input.update()        
319
+
152 320
         #update team
153 321
         self.a_team.update(self)
154 322
         self.b_team.update(self)
@@ -162,7 +330,13 @@ class game:
162 330
         #print(p)
163 331
                     
164 332
         self.FSM.Execute() 
165
-        self.sound_man.update()   
333
+        self.sound_man.update() 
334
+        
335
+        #print(self.team_a_user_input.i_w)
336
+        #print(self.team_b_user_input.i_da)
337
+        
338
+        
339
+        #print(self.score)  
166 340
 
167 341
 class hockey_player():
168 342
     def __init__(self, team, other, contr):
@@ -277,18 +451,22 @@ class hockey_player():
277 451
 
278 452
     def user_movement(self):
279 453
         own = self.cont
280
-        if self.kb_w == 1:
454
+        #if self.kb_w == 1:
455
+        if self.mates.user_input.i_w == 1:    
281 456
             self.speed_tilt_timer += 1
282 457
             if own.linearVelocity.x < 2:
283 458
                 own.applyForce([13,0,0], True)
284
-            if self.kb_ls == 1:
285
-                if self.last_kb_ls == 0:
459
+            #if self.kb_ls == 1:
460
+            if self.mates.user_input.i_ls == 1:      
461
+                #if self.last_kb_ls == 0:
462
+                if self.mates.user_input.i_last_ls == 0:      
286 463
                     self.speed_tilt_timer = 0
287 464
                 if own.linearVelocity.x < 4:
288 465
                     own.applyForce([16,0,0], True)                    
289 466
         else:
290 467
             self.speed_tilt_timer = 0
291
-        if self.kb_s == 1:
468
+        #if self.kb_s == 1:
469
+        if self.mates.user_input.i_s == 1:     
292 470
             if own.linearVelocity.x > -2:
293 471
                 own.applyForce([-13,0,0], True)
294 472
         
@@ -297,14 +475,16 @@ class hockey_player():
297 475
         time = 25  
298 476
         time2 = 25 
299 477
         aligned = False     
300
-        if self.kb_a == 1:
478
+        #if self.kb_a == 1:
479
+        if self.mates.user_input.i_a == 1: 
301 480
             self.turn_timer += 1
302 481
             own.applyRotation([0, 0, .04], True)
303 482
             if self.turn_timer < time:
304 483
                 self.body.applyRotation([-tilt, 0, 0], True)
305 484
                 self.head.applyRotation([(tilt2 * -1.2), 0, 0], True)
306 485
                 #aligned = True                
307
-        elif self.kb_d == 1:
486
+        #elif self.kb_d == 1:
487
+        elif self.mates.user_input.i_d == 1: 
308 488
             self.turn_timer += 1
309 489
             own.applyRotation([0, 0, -.04], True)  
310 490
             if self.turn_timer < time:
@@ -371,7 +551,7 @@ class hockey_player():
371 551
         self.mates.switch_player_frame.append(g.frame)
372 552
         self.mates.switch_player_frame.pop(0)
373 553
         
374
-        mates = self.mates.p_closest.copy()
554
+        mates = self.mates.puck_closest.copy()
375 555
         mates.remove(self)
376 556
         since_switch_a = g.frame - self.mates.switch_player_frame[2]
377 557
         #print(mates, since_switch_a)
@@ -405,7 +585,8 @@ class hockey_player():
405 585
 
406 586
 
407 587
     def check_check(self):
408
-        if self.kb_ua == 1:
588
+        #if self.kb_ua == 1:
589
+        if self.mates.user_input.i_ua == 1:     
409 590
 
410 591
             #sorted(listasdf, key=lambda x: x[1])
411 592
 
@@ -440,6 +621,10 @@ class hockey_player():
440 621
         else:
441 622
             return False  
442 623
 
624
+    def closest_teammates(self):
625
+        pass
626
+
627
+
443 628
     def simple_align(self, strength):
444 629
         self.base.worldOrientation = self.cont.worldOrientation
445 630
         self.body.alignAxisToVect([0,0,1], 2, strength)
@@ -492,17 +677,19 @@ class hockey_player():
492 677
             e2 = self.stick.worldOrientation.to_euler().z
493 678
             dif = e1 - e2
494 679
             
495
-            if self.kb_la == 1 and self.puck:
680
+            #if self.kb_la == 1 and self.puck:
681
+            if self.mates.user_input.i_la == 1 and self.puck:                 
496 682
                 self.pass_id = 0
497 683
                 a = str(self.FSM.FSM.curState.__class__.__name__)
498 684
                 if state != 'Passing':
499
-                    self.FSM.FSM.ToTransition('toPassing')
685
+                    self.FSM.FSM.ToTransition('toWindPass')
500 686
 
501
-            if self.kb_ra == 1 and self.puck:
687
+            #if self.kb_ra == 1 and self.puck:
688
+            if self.mates.user_input.i_ra == 1 and self.puck:     
502 689
                 self.pass_id = 1
503 690
                 a = str(self.FSM.FSM.curState.__class__.__name__)
504 691
                 if state != 'Passing':
505
-                    self.FSM.FSM.ToTransition('toPassing')
692
+                    self.FSM.FSM.ToTransition('toWindPass')
506 693
                                         
507 694
             # if self.kb_ua == 1 and self.puck == False:
508 695
             #     self.stick.applyRotation([0, -.35, 0], True)                    
@@ -544,17 +731,24 @@ def puck(cont):
544 731
 
545 732
     if g.puck_update:  
546 733
         if own.worldPosition.z < 0: 
547
-           own.worldPosition.z = 0 
734
+           own.worldPosition.z = 0.5 
735
+           print('puck out of bounds -z')            
548 736
         if own.worldPosition.z > .5: 
549 737
            own.worldPosition.z = .5           
550 738
         if own.worldPosition.x > 12:
551 739
             own.worldPosition.x = 11.5
740
+            print('puck out of bounds +x')            
552 741
         if own.worldPosition.x < -12:
553 742
             own.worldPosition.x = -11.5
554
-        if own.worldPosition.y > 8.5:
555
-            own.worldPosition.y = 7.5
556
-        if own.worldPosition.y < -8.5:
557
-            own.worldPosition.y = -7.5  
743
+            print('puck out of bounds -x')
744
+        if own.worldPosition.y > 8.25:
745
+            own.worldPosition.y = 7.0
746
+            #own.linearVelocity.x *= -1
747
+            print('puck out of bounds +y')
748
+        if own.worldPosition.y < -8.25:
749
+            own.worldPosition.y = -7.0
750
+            print('puck out of bounds -y')
751
+            #own.linearVelocity.x *= -1  
558 752
             
559 753
         if cont.sensors['puck-player'].hitObject is not None:
560 754
             ho = cont.sensors['puck-player'].hitObject
@@ -577,7 +771,12 @@ def puck(cont):
577 771
                 
578 772
                 o = cont.sensors['puck-player'].hitObject
579 773
                 if 'goal' in o:
774
+
580 775
                     print('GOOOAAAALLL!!', o['team'])
776
+                    if o['team'] == 'a':
777
+                        g.score[0] += 1
778
+                    if o['team'] == 'b':
779
+                        g.score[1] += 1    
581 780
                     g.FSM.FSM.ToTransition('toGoalScored')
582 781
 
583 782
                     #if 'a2' in cont.sensors['puck-player'].hitObject['name']:

+ 3
- 0
scripts/sound_man.py View File

@@ -11,6 +11,9 @@ def init_sounds(self):
11 11
 	self.check = sounds('check')
12 12
 	self.shoot = sounds('shoot')
13 13
 	self.post = sounds('post')
14
+	self.whistle = sounds('whistle')
15
+	self.goal = sounds('goal')
16
+	self.puck_drop = sounds('puck_drop')
14 17
 	self.board = sounds('board')		
15 18
 	self.board_played = 0
16 19
 

+ 9
- 9
scripts/utils.py View File

@@ -25,13 +25,13 @@ def update_whiskers(self):
25 25
     iter = 0
26 26
 
27 27
     #draw debug
28
-    for w in self.whiskers:
29
-        color = [0,1,0]
30
-        if w[0] is not None:
31
-            if 'player' in w[0] or 'puck' in w[0]:
32
-                color = [1,0,0]        
28
+    # for w in self.whiskers:
29
+    #     color = [0,1,0]
30
+    #     if w[0] is not None:
31
+    #         if 'player' in w[0] or 'puck' in w[0]:
32
+    #             color = [1,0,0]        
33 33
 
34
-                #print(w[0])
35
-        #print(self.whiskers)
36
-        bge.render.drawLine(o.cont.worldPosition, self.whisker_objs[iter].worldPosition, color)
37
-        iter += 1
34
+    #             #print(w[0])
35
+    #     #print(self.whiskers)
36
+    #     bge.render.drawLine(o.cont.worldPosition, self.whisker_objs[iter].worldPosition, color)
37
+    #     iter += 1

+ 3
- 0
sounds/goal.wav View File

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

+ 3
- 0
sounds/puck_drop.wav View File

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

+ 3
- 0
sounds/whistle.wav View File

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

Loading…
Cancel
Save