|
@@ -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']:
|