Browse Source

command argument handling; disabled blib sound

master
Fr3deric 8 years ago committed by Frederic
parent
commit
40376443ba
  1. 54
      balancep0ng.py

54
balancep0ng.py

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

Loading…
Cancel
Save