Browse Source

Merge branch 'master' of blinkenbunt:gitrepos/blup3

master
Fr3deric 7 years ago committed by Frederic
parent
commit
fcc2fa9af7
  1. 21
      gamemenu.py
  2. 37
      wii-pair/daemon.py

21
gamemenu.py

@ -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

37
wii-pair/daemon.py

@ -73,6 +73,7 @@ class StatusThread(Thread): @@ -73,6 +73,7 @@ class StatusThread(Thread):
print(b1.ljust(colw) + b2)
print(w1.ljust(colw) + w2)
print(p1.ljust(colw) + p2)
sys.stdout.flush()
time.sleep(1)
@ -188,18 +189,36 @@ try: @@ -188,18 +189,36 @@ try:
conns.remove(sock)
continue
if len(m) == 0:
conns.remove(sock)
continue
r = b''
for w in wiis:
if w.pos_x is None:
v = -128
if m[0] == ord('w'):
# Return weight
v = 0
if w.weight is not None:
v = round(w.weight)
r += struct.pack('b', v)
elif m[0] == ord('b'):
# Return battery
v = 0
if w.board.battery is not None:
v = round(w.board.battery*100)
r += struct.pack('b', v)
else:
v = int(round(w.pos_x*100))
r += struct.pack('b', v)
if w.pos_y is None:
v = -128
else:
v = int(round(w.pos_y*100))
r += struct.pack('b', v)
# Return balance
if w.pos_x is None:
v = -128
else:
v = int(round(w.pos_x*100))
r += struct.pack('b', v)
if w.pos_y is None:
v = -128
else:
v = int(round(w.pos_y*100))
r += struct.pack('b', v)
try:
sock.send(r)

Loading…
Cancel
Save