|
|
|
@ -1,6 +1,7 @@
@@ -1,6 +1,7 @@
|
|
|
|
|
#!/usr/bin/python3 |
|
|
|
|
|
|
|
|
|
import time |
|
|
|
|
import argparse |
|
|
|
|
import threading |
|
|
|
|
import sys |
|
|
|
|
import os |
|
|
|
@ -110,6 +111,7 @@ class BalanceBoardPlayer(object):
@@ -110,6 +111,7 @@ class BalanceBoardPlayer(object):
|
|
|
|
|
self.__wiimote_sock.close() |
|
|
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
|
bal = -bal |
|
|
|
|
MAX_AMPLITUDE = 65 |
|
|
|
|
if bal < -MAX_AMPLITUDE: |
|
|
|
|
bal = -MAX_AMPLITUDE |
|
|
|
@ -127,10 +129,15 @@ class BalanceBoardPlayer(object):
@@ -127,10 +129,15 @@ class BalanceBoardPlayer(object):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class B4lancePong(object): |
|
|
|
|
def __init__(self, out, color=True): |
|
|
|
|
def __init__(self, out, balanceserver=None, color=True, numplayers=None): |
|
|
|
|
self.__playground = None |
|
|
|
|
self.__out = out |
|
|
|
|
self.__color = color |
|
|
|
|
if balanceserver is None: |
|
|
|
|
self.__balanceserver = ('localhost', 4711) |
|
|
|
|
else: |
|
|
|
|
self.__balanceserver = balanceserver |
|
|
|
|
self.__numplayers = numplayers |
|
|
|
|
|
|
|
|
|
if color: |
|
|
|
|
self.__dimension = blup.frame.FrameDimension(22, 16, 256, 3) |
|
|
|
@ -146,8 +153,7 @@ class B4lancePong(object):
@@ -146,8 +153,7 @@ class B4lancePong(object):
|
|
|
|
|
pp = pong.PlaygroundPainter(out, self.__dimension, self.__playground) |
|
|
|
|
|
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
|
|
|
#sock.connect(('localhost', 4711)) |
|
|
|
|
sock.connect(('blinkenbunt', 4711)) |
|
|
|
|
sock.connect(self.__balanceserver) |
|
|
|
|
print('connected!') |
|
|
|
|
|
|
|
|
|
while get_balance_from_sock(sock, 0) == -128: |
|
|
|
@ -157,7 +163,9 @@ class B4lancePong(object):
@@ -157,7 +163,9 @@ class B4lancePong(object):
|
|
|
|
|
self.__players = [] |
|
|
|
|
self.__players.append(BalanceBoardPlayer(self.__playground, self.__playground.leftPaddle, sock, 0)) |
|
|
|
|
|
|
|
|
|
global logo |
|
|
|
|
if self.__numplayers == 2: |
|
|
|
|
self.__players.append(BalanceBoardPlayer(self.__playground, self.__playground.rightPaddle, sock, 1)) |
|
|
|
|
elif self.__numplayers is None: |
|
|
|
|
for i in range(5): |
|
|
|
|
frame = mk_logo_frame(self.__dimension, onePlayer) |
|
|
|
|
self.__out.sendFrame(frame) |
|
|
|
@ -172,10 +180,10 @@ class B4lancePong(object):
@@ -172,10 +180,10 @@ class B4lancePong(object):
|
|
|
|
|
self.__out.sendFrame(frame) |
|
|
|
|
time.sleep(2) |
|
|
|
|
|
|
|
|
|
def blib(obj): |
|
|
|
|
if isinstance(obj, pong.Paddle): |
|
|
|
|
subprocess.Popen(['mplayer','pongblib1.wav']) |
|
|
|
|
self.__playground.ball.addHitCallback(blib) |
|
|
|
|
#def blib(obj): |
|
|
|
|
# if isinstance(obj, pong.Paddle): |
|
|
|
|
# subprocess.Popen(['mplayer','pongblib1.wav']) |
|
|
|
|
#self.__playground.ball.addHitCallback(blib) |
|
|
|
|
|
|
|
|
|
frame = mk_logo_frame(self.__dimension, logo_go) |
|
|
|
|
self.__out.sendFrame(frame) |
|
|
|
@ -206,20 +214,20 @@ class B4lancePong(object):
@@ -206,20 +214,20 @@ class B4lancePong(object):
|
|
|
|
|
|
|
|
|
|
sock.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) > 1: |
|
|
|
|
outspec = sys.argv[1] |
|
|
|
|
else: |
|
|
|
|
outspec = 'e3blp:localhost:4242' |
|
|
|
|
out = blup.output.getOutput(outspec) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p0ng = B4lancePong(out, color=True) |
|
|
|
|
while True: |
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
parser = argparse.ArgumentParser(description='Blinkenbunt Pong!') |
|
|
|
|
parser.add_argument('--players', dest='players', type=int, |
|
|
|
|
help='number of players (autodetect if unspecified)') |
|
|
|
|
parser.add_argument('--balance', dest='balance', type=str, |
|
|
|
|
metavar='HOST:PORT', help='use balance input') |
|
|
|
|
parser.add_argument('--out', dest='out', type=str, metavar='OUTPUT', |
|
|
|
|
default='e3blp', help='blup output specification') |
|
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
|
|
out = blup.output.getOutput(args.out) |
|
|
|
|
bhost, bport = args.balance.split(':') |
|
|
|
|
|
|
|
|
|
p0ng = B4lancePong(out, balanceserver=(bhost, int(bport)), color=True, |
|
|
|
|
numplayers=args.players) |
|
|
|
|
p0ng.runGame() |
|
|
|
|
|
|
|
|
|
sys.exit(0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|