|
@@ -26,7 +26,7 @@ class Example(State):
|
26
|
26
|
def Execute(self):
|
27
|
27
|
self.FSM.stateLife += 1
|
28
|
28
|
o = self.FSM.owner
|
29
|
|
- g = o.me
|
|
29
|
+ g = o.me['game']
|
30
|
30
|
self.FSM.ToTransition('toNewState')
|
31
|
31
|
|
32
|
32
|
def Exit(self):
|
|
@@ -64,6 +64,10 @@ class GetPuck(State):
|
64
|
64
|
if o.kb_da == 0 and o.last_kb_da == 1:
|
65
|
65
|
o.switch_player()
|
66
|
66
|
print('fsm switch')
|
|
67
|
+ o.check_check()
|
|
68
|
+ # if o.kb_ua == 1:
|
|
69
|
+ # self.FSM.ToTransition('toCheckMissOn')
|
|
70
|
+
|
67
|
71
|
if o.team == 1:
|
68
|
72
|
self.FSM.ToTransition('toDefendPuck')
|
69
|
73
|
|
|
@@ -146,63 +150,69 @@ class DefendPuck(State):
|
146
|
150
|
self.FSM.stateLife += 1
|
147
|
151
|
|
148
|
152
|
o = self.FSM.owner
|
149
|
|
-
|
150
|
153
|
g = o.me['game']
|
151
|
|
-
|
152
|
154
|
d = o.cont.getDistanceTo(g.puck)
|
153
|
155
|
|
154
|
156
|
utils.update_whiskers(o)
|
155
|
157
|
|
156
|
|
- if g.puck.worldPosition.y > 0:
|
157
|
|
- y = -4
|
158
|
|
- else:
|
159
|
|
- y = 4
|
160
|
|
- if o.player_col:
|
161
|
|
- #print('hitting', o.player_col)
|
162
|
|
- pass
|
163
|
|
- if o == g.players[1]:
|
164
|
|
- poi = [0, y, o.cont.worldPosition.z]
|
165
|
|
- if g.puck.worldPosition.x > 4:
|
166
|
|
- poi = [-6, y, o.cont.worldPosition.z]
|
167
|
|
- if g.puck.worldPosition.x < -4:
|
168
|
|
- poi = [4, y, o.cont.worldPosition.z]
|
169
|
|
- #distance to point of interest
|
170
|
|
- dto_poi = o.cont.getDistanceTo(poi)
|
171
|
|
- if dto_poi > .5:
|
172
|
|
- v = o.cont.getVectTo(poi)
|
173
|
|
- o.cont.alignAxisToVect(v[1], 0, .1)
|
174
|
|
- if o.cont.linearVelocity.x < 2:
|
175
|
|
- o.cont.applyForce([o.speed, 0, 0], True)
|
176
|
|
- else:
|
177
|
|
- v = o.cont.getVectTo(g.puck)
|
178
|
|
- o.cont.alignAxisToVect(v[1], 0, .05)
|
179
|
|
- o.cont.linearVelocity = [0, 0, 0]
|
|
158
|
+ if o.checked != None:
|
|
159
|
+ self.FSM.ToTransition('toChecked')
|
|
160
|
+
|
|
161
|
+ o.simple_align(.04)
|
|
162
|
+
|
|
163
|
+ # if g.puck.worldPosition.y > 0:
|
|
164
|
+ # y = -4
|
|
165
|
+ # else:
|
|
166
|
+ # y = 4
|
|
167
|
+ # if o.player_col:
|
|
168
|
+ # #print('hitting', o.player_col)
|
|
169
|
+ # pass
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+ # if o == g.players[1]:
|
|
174
|
+ # poi = [0, y, o.cont.worldPosition.z]
|
|
175
|
+ # if g.puck.worldPosition.x > 4:
|
|
176
|
+ # poi = [-6, y, o.cont.worldPosition.z]
|
|
177
|
+ # if g.puck.worldPosition.x < -4:
|
|
178
|
+ # poi = [4, y, o.cont.worldPosition.z]
|
|
179
|
+ # #distance to point of interest
|
|
180
|
+ # dto_poi = o.cont.getDistanceTo(poi)
|
|
181
|
+ # if dto_poi > .5:
|
|
182
|
+ # v = o.cont.getVectTo(poi)
|
|
183
|
+ # o.cont.alignAxisToVect(v[1], 0, .1)
|
|
184
|
+ # if o.cont.linearVelocity.x < 2:
|
|
185
|
+ # o.cont.applyForce([o.speed, 0, 0], True)
|
|
186
|
+ # else:
|
|
187
|
+ # v = o.cont.getVectTo(g.puck)
|
|
188
|
+ # o.cont.alignAxisToVect(v[1], 0, .05)
|
|
189
|
+ # o.cont.linearVelocity = [0, 0, 0]
|
180
|
190
|
|
181
|
|
- o.align_to_base()
|
182
|
|
- if abs(o.cont.linearVelocity.y) > .5:
|
183
|
|
- o.cont.linearVelocity *= .5
|
|
191
|
+ # o.align_to_base()
|
|
192
|
+ # if abs(o.cont.linearVelocity.y) > .5:
|
|
193
|
+ # o.cont.linearVelocity *= .5
|
184
|
194
|
|
185
|
|
- if o == g.players[2]:
|
186
|
|
- poi = [0-6, -y, o.cont.worldPosition.z]
|
187
|
|
- if g.puck.worldPosition.x > 4:
|
188
|
|
- poi = [6-6, -y, o.cont.worldPosition.z]
|
189
|
|
- if g.puck.worldPosition.x < -4:
|
190
|
|
- poi = [-4-6, y, o.cont.worldPosition.z]
|
191
|
|
- #distance to point of interest
|
192
|
|
- dto_poi = o.cont.getDistanceTo(poi)
|
193
|
|
- if dto_poi > .5:
|
194
|
|
- v = o.cont.getVectTo(poi)
|
195
|
|
- o.cont.alignAxisToVect(v[1], 0, .1)
|
196
|
|
- if o.cont.linearVelocity.x < 2:
|
197
|
|
- o.cont.applyForce([o.speed, 0, 0], True)
|
198
|
|
- else:
|
199
|
|
- v = o.cont.getVectTo(g.puck)
|
200
|
|
- o.cont.alignAxisToVect(v[1], 0, .05)
|
201
|
|
- o.cont.linearVelocity = [0, 0, 0]
|
|
195
|
+ # if o == g.players[2]:
|
|
196
|
+ # poi = [0-6, -y, o.cont.worldPosition.z]
|
|
197
|
+ # if g.puck.worldPosition.x > 4:
|
|
198
|
+ # poi = [6-6, -y, o.cont.worldPosition.z]
|
|
199
|
+ # if g.puck.worldPosition.x < -4:
|
|
200
|
+ # poi = [-4-6, y, o.cont.worldPosition.z]
|
|
201
|
+ # #distance to point of interest
|
|
202
|
+ # dto_poi = o.cont.getDistanceTo(poi)
|
|
203
|
+ # if dto_poi > .5:
|
|
204
|
+ # v = o.cont.getVectTo(poi)
|
|
205
|
+ # o.cont.alignAxisToVect(v[1], 0, .1)
|
|
206
|
+ # if o.cont.linearVelocity.x < 2:
|
|
207
|
+ # o.cont.applyForce([o.speed, 0, 0], True)
|
|
208
|
+ # else:
|
|
209
|
+ # v = o.cont.getVectTo(g.puck)
|
|
210
|
+ # o.cont.alignAxisToVect(v[1], 0, .05)
|
|
211
|
+ # o.cont.linearVelocity = [0, 0, 0]
|
202
|
212
|
|
203
|
|
- o.align_to_base()
|
204
|
|
- if abs(o.cont.linearVelocity.y) > .5:
|
205
|
|
- o.cont.linearVelocity *= .5
|
|
213
|
+ # o.align_to_base()
|
|
214
|
+ # if abs(o.cont.linearVelocity.y) > .5:
|
|
215
|
+ # o.cont.linearVelocity *= .5
|
206
|
216
|
|
207
|
217
|
|
208
|
218
|
def Exit(self):
|
|
@@ -290,45 +300,7 @@ class Shooting(State):
|
290
|
300
|
|
291
|
301
|
def Execute(self):
|
292
|
302
|
pass
|
293
|
|
-# self.FSM.stateLife += 1
|
294
|
|
-# o = self.FSM.owner
|
295
|
|
-# g = o.me['game']
|
296
|
|
-# o.state = 'shooting'
|
297
|
|
-# v = o.cont.getVectTo(o.goal_t)
|
298
|
|
-#
|
299
|
|
-# stre = .1
|
300
|
|
-# o.stick.alignAxisToVect(v[1], 0, stre)
|
301
|
|
-# o.cont.alignAxisToVect(v[1], 0, stre)
|
302
|
|
-# e1 = o.cont.worldOrientation.to_euler().z
|
303
|
|
-# e2 = o.stick.worldOrientation.to_euler().z
|
304
|
|
-# dif = e1 - e2
|
305
|
|
-# if dif > -1.5:
|
306
|
|
-# o.stick.applyRotation([0,0,.15], True)
|
307
|
|
-#
|
308
|
|
-# if o.shooting > 15:
|
309
|
|
-# g.puck.worldPosition = o.puck_empty.worldPosition
|
310
|
|
-# g.puck.linearVelocity = [0,0,0]
|
311
|
|
-#
|
312
|
|
-# if o.shooting == 15:
|
313
|
|
-# g.sound_man.queue_sound(['shoot', o.cont, g.camera])
|
314
|
|
-#
|
315
|
|
-# if o.kb_da == 1:
|
316
|
|
-# o.shooting = 25
|
317
|
|
-# #print('kb')
|
318
|
|
-# else:
|
319
|
|
-# print(o.shooting)
|
320
|
|
-# if o.shooting > 0:
|
321
|
|
-# #print('oshooting')
|
322
|
|
-# dif = e1 - e2
|
323
|
|
-# o.shooting -= 1
|
324
|
|
-# o.stick.applyRotation([0,0,-.22], True)
|
325
|
|
-# #print(dif)
|
326
|
|
-# #if dif > 1.8 and o.shooting < 5:
|
327
|
|
-# if o.shooting < 1:
|
328
|
|
-# o.state = 'chasing'
|
329
|
|
-# self.FSM.ToTransition('toGetPuck')
|
330
|
|
-# #print('exit')
|
331
|
|
-# o.puck = False
|
|
303
|
+
|
332
|
304
|
|
333
|
305
|
def Exit(self):
|
334
|
306
|
print('Waking up from Shooting.')
|
|
@@ -575,4 +547,172 @@ class ShootShot(State):
|
575
|
547
|
def Exit(self):
|
576
|
548
|
pass
|
577
|
549
|
|
578
|
|
-#====================================
|
|
550
|
+#====================================
|
|
551
|
+
|
|
552
|
+class CheckMissOn(State):
|
|
553
|
+ def __init__(self,FSM):
|
|
554
|
+ super(CheckMissOn, self).__init__(FSM)
|
|
555
|
+
|
|
556
|
+ def Enter(self):
|
|
557
|
+ self.FSM.stateLife = 1
|
|
558
|
+ super(CheckMissOn, self).Enter()
|
|
559
|
+ o = self.FSM.owner
|
|
560
|
+ g = o.me['game']
|
|
561
|
+ g.sound_man.queue_sound(['check_miss', o.cont, g.camera])
|
|
562
|
+ def Execute(self):
|
|
563
|
+ self.FSM.stateLife += 1
|
|
564
|
+ o = self.FSM.owner
|
|
565
|
+ g = o.me['game']
|
|
566
|
+
|
|
567
|
+ length = 3
|
|
568
|
+ sr = -.35
|
|
569
|
+ sm = .4
|
|
570
|
+
|
|
571
|
+ if self.FSM.stateLife < length + 2:
|
|
572
|
+ sr = sr * (self.FSM.stateLife / (length + 2))
|
|
573
|
+ sm = sm * (self.FSM.stateLife / (length + 2))
|
|
574
|
+ #print(sr, sm, 'hittting')
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+ o.stick.applyRotation([0, sr, 0], True)
|
|
578
|
+ o.stick.applyMovement([sm, 0, 0], True)
|
|
579
|
+
|
|
580
|
+ if o.kb_ua != 1:
|
|
581
|
+ self.FSM.ToTransition('toCheckMissOff')
|
|
582
|
+
|
|
583
|
+ def Exit(self):
|
|
584
|
+ pass
|
|
585
|
+
|
|
586
|
+#====================================
|
|
587
|
+
|
|
588
|
+class CheckMissOff(State):
|
|
589
|
+ def __init__(self,FSM):
|
|
590
|
+ super(CheckMissOff, self).__init__(FSM)
|
|
591
|
+
|
|
592
|
+ def Enter(self):
|
|
593
|
+ self.FSM.stateLife = 1
|
|
594
|
+ super(CheckMissOff, self).Enter()
|
|
595
|
+
|
|
596
|
+ def Execute(self):
|
|
597
|
+ self.FSM.stateLife += 1
|
|
598
|
+ o = self.FSM.owner
|
|
599
|
+ g = o.me['game']
|
|
600
|
+ self.FSM.ToTransition('toGetPuck')
|
|
601
|
+
|
|
602
|
+ def Exit(self):
|
|
603
|
+ pass
|
|
604
|
+
|
|
605
|
+#====================================
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+class CheckOn(State):
|
|
609
|
+ def __init__(self,FSM):
|
|
610
|
+ super(CheckOn, self).__init__(FSM)
|
|
611
|
+
|
|
612
|
+ def Enter(self):
|
|
613
|
+ self.FSM.stateLife = 1
|
|
614
|
+ super(CheckOn, self).Enter()
|
|
615
|
+ o = self.FSM.owner
|
|
616
|
+ g = o.me['game']
|
|
617
|
+ g.sound_man.queue_sound(['check', o.cont, g.camera])
|
|
618
|
+
|
|
619
|
+ def Execute(self):
|
|
620
|
+ self.FSM.stateLife += 1
|
|
621
|
+ o = self.FSM.owner
|
|
622
|
+ g = o.me['game']
|
|
623
|
+
|
|
624
|
+ length = 3
|
|
625
|
+ sr = -.35
|
|
626
|
+ sm = .4
|
|
627
|
+
|
|
628
|
+ if self.FSM.stateLife < length + 2:
|
|
629
|
+ sr = sr * (self.FSM.stateLife / (length + 2))
|
|
630
|
+ sm = sm * (self.FSM.stateLife / (length + 2))
|
|
631
|
+ #print(sr, sm, 'hittting')
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+ o.stick.applyRotation([0, sr, 0], True)
|
|
635
|
+ o.stick.applyMovement([sm, 0, 0], True)
|
|
636
|
+
|
|
637
|
+ if o.kb_ua != 1:
|
|
638
|
+ self.FSM.ToTransition('toCheckOff')
|
|
639
|
+
|
|
640
|
+ def Exit(self):
|
|
641
|
+ pass
|
|
642
|
+
|
|
643
|
+#====================================
|
|
644
|
+
|
|
645
|
+class CheckOff(State):
|
|
646
|
+ def __init__(self,FSM):
|
|
647
|
+ super(CheckOff, self).__init__(FSM)
|
|
648
|
+
|
|
649
|
+ def Enter(self):
|
|
650
|
+ self.FSM.stateLife = 1
|
|
651
|
+ super(CheckOff, self).Enter()
|
|
652
|
+
|
|
653
|
+ def Execute(self):
|
|
654
|
+ self.FSM.stateLife += 1
|
|
655
|
+ o = self.FSM.owner
|
|
656
|
+ g = o.me['game']
|
|
657
|
+ self.FSM.ToTransition('toGetPuck')
|
|
658
|
+
|
|
659
|
+ def Exit(self):
|
|
660
|
+ pass
|
|
661
|
+
|
|
662
|
+#====================================
|
|
663
|
+
|
|
664
|
+class Checked(State):
|
|
665
|
+ def __init__(self,FSM):
|
|
666
|
+ super(Checked, self).__init__(FSM)
|
|
667
|
+
|
|
668
|
+ def Enter(self):
|
|
669
|
+ self.FSM.stateLife = 1
|
|
670
|
+ super(Checked, self).Enter()
|
|
671
|
+ o = self.FSM.owner
|
|
672
|
+ self.checker = o.checked
|
|
673
|
+ o.checked = None
|
|
674
|
+
|
|
675
|
+ def Execute(self):
|
|
676
|
+ self.FSM.stateLife += 1
|
|
677
|
+ o = self.FSM.owner
|
|
678
|
+ g = o.me['game']
|
|
679
|
+
|
|
680
|
+ tilt = -.01
|
|
681
|
+
|
|
682
|
+ local = o.cont.worldOrientation.inverted() * (self.checker.cont.worldPosition - o.cont.worldPosition)
|
|
683
|
+ print(local)
|
|
684
|
+ if local.x > 0:
|
|
685
|
+ #target is in front
|
|
686
|
+ print('in front')
|
|
687
|
+ pass
|
|
688
|
+ else:
|
|
689
|
+ #target is behind
|
|
690
|
+ print('behind')
|
|
691
|
+ pass
|
|
692
|
+ if local.y > 0:
|
|
693
|
+ #object on right
|
|
694
|
+ print('on right')
|
|
695
|
+ rot = 'right'
|
|
696
|
+ o.body.applyRotation([-tilt, 0, 0], True)
|
|
697
|
+ o.head.applyRotation([(-tilt * 1.2), 0, 0], True)
|
|
698
|
+ else:
|
|
699
|
+ #object is on left
|
|
700
|
+ print('on left')
|
|
701
|
+ rot = 'left'
|
|
702
|
+ o.body.applyRotation([tilt, 0, 0], True)
|
|
703
|
+ o.head.applyRotation([(tilt * 1.2), 0, 0], True)
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+ tilt2 = -.02
|
|
708
|
+
|
|
709
|
+ o.body.applyRotation([0, tilt2, 0], True)
|
|
710
|
+ o.head.applyRotation([0, (tilt2 * 1.2), 0], True)
|
|
711
|
+ if self.FSM.stateLife > 20:
|
|
712
|
+ self.FSM.ToTransition('toDefendPuck')
|
|
713
|
+
|
|
714
|
+ def Exit(self):
|
|
715
|
+ pass
|
|
716
|
+
|
|
717
|
+#====================================
|
|
718
|
+
|