|
|
|
@ -177,6 +177,7 @@ InputEvent = enum.Enum('InputEvent', ['UP', 'DOWN', 'LEFT',
@@ -177,6 +177,7 @@ InputEvent = enum.Enum('InputEvent', ['UP', 'DOWN', 'LEFT',
|
|
|
|
|
|
|
|
|
|
class AbstractInput(): |
|
|
|
|
def __init__(self): |
|
|
|
|
self.player_present = False |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
def get_event(self): |
|
|
|
@ -203,6 +204,8 @@ class TestInput(AbstractInput):
@@ -203,6 +204,8 @@ class TestInput(AbstractInput):
|
|
|
|
|
pygame = self.__pygame |
|
|
|
|
for event in pygame.event.get(): |
|
|
|
|
if event.type == pygame.KEYDOWN: |
|
|
|
|
if self.control.get(event.key, None) == InputEvent.STEP_ON: |
|
|
|
|
self.player_present = True |
|
|
|
|
return self.controls.get(event.key, None) |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
@ -238,7 +241,6 @@ class BalanceInput(AbstractInput, threading.Thread):
@@ -238,7 +241,6 @@ class BalanceInput(AbstractInput, threading.Thread):
|
|
|
|
|
elif self.player_id == 1: |
|
|
|
|
xbal, ybal = p1x, p1y |
|
|
|
|
|
|
|
|
|
print('player_id=%d xbal=%d ybal=%d' % (self.player_id, xbal, ybal)) |
|
|
|
|
THRESHOLD = 40 |
|
|
|
|
MIN_TIMES = { |
|
|
|
|
InputEvent.LEFT: 0.05, |
|
|
|
@ -277,12 +279,13 @@ class BalanceInput(AbstractInput, threading.Thread):
@@ -277,12 +279,13 @@ class BalanceInput(AbstractInput, threading.Thread):
|
|
|
|
|
self.evt = evt |
|
|
|
|
self.lastevt = evt |
|
|
|
|
print('player_id=%d event=%s' % (self.player_id, self.evt)) |
|
|
|
|
|
|
|
|
|
time.sleep(0.005) |
|
|
|
|
else: |
|
|
|
|
if xbal != -128 and ybal != -128: |
|
|
|
|
self.evt = InputEvent.STEP_ON |
|
|
|
|
self.player_present = True |
|
|
|
|
continue |
|
|
|
|
time.sleep(0.05) |
|
|
|
|
|
|
|
|
|
def get_event(self): |
|
|
|
|
evt = self.evt |
|
|
|
@ -325,7 +328,12 @@ if __name__ == '__main__':
@@ -325,7 +328,12 @@ if __name__ == '__main__':
|
|
|
|
|
inp1 = BalanceInput((host, int(port)), 0) |
|
|
|
|
inp2 = BalanceInput((host, int(port)), 1) |
|
|
|
|
|
|
|
|
|
while inp1.get_event() != InputEvent.STEP_ON: |
|
|
|
|
while True: |
|
|
|
|
evt = inp1.get_event() |
|
|
|
|
if evt == InputEvent.STEP_ON: |
|
|
|
|
break |
|
|
|
|
elif evt == InputEvent.QUIT: |
|
|
|
|
sys.exit() |
|
|
|
|
time.sleep(0.05) |
|
|
|
|
|
|
|
|
|
init_frame = create_init_screen(dim) |
|
|
|
@ -360,13 +368,16 @@ if __name__ == '__main__':
@@ -360,13 +368,16 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
p2_frame = create_2player_screen(dim) |
|
|
|
|
out.sendFrame(p2_frame) |
|
|
|
|
wait_time = 3 |
|
|
|
|
wait_time = 2 |
|
|
|
|
start = time.time() |
|
|
|
|
while time.time() < start+wait_time: |
|
|
|
|
if inp2.get_event() == InputEvent.STEP_ON: |
|
|
|
|
evt = inp2.get_event() |
|
|
|
|
if inp2.player_present: |
|
|
|
|
inp1.running = False |
|
|
|
|
inp2.running = False |
|
|
|
|
start_game(game, 2) |
|
|
|
|
elif evt == InputEvent.QUIT: |
|
|
|
|
sys.exit() |
|
|
|
|
time.sleep(0.1) |
|
|
|
|
|
|
|
|
|
inp1.running = False |
|
|
|
|