forked from protonphoton/LJ
idiotIA
This commit is contained in:
parent
89462381db
commit
172ae79105
33 changed files with 1245 additions and 311 deletions
|
|
@ -112,7 +112,7 @@ LOGO = [
|
|||
LOGO_OFFSET_X = 460
|
||||
LOGO_OFFSET_Y = 250
|
||||
|
||||
def LogoDraw():
|
||||
def LogoDraw(plnumber):
|
||||
'''
|
||||
Dessine le logo
|
||||
'''
|
||||
|
|
@ -122,8 +122,7 @@ def LogoDraw():
|
|||
for xy in pl_color[0]:
|
||||
xy_list.append((LOGO_OFFSET_X + xy[0], LOGO_OFFSET_Y + xy[1]))
|
||||
#print xy_list
|
||||
lj.PolyLineOneColor(xy_list, c,0, False)
|
||||
|
||||
lj.PolyLineOneColor(xy_list, c, plnumber, False)
|
||||
|
||||
|
||||
|
||||
|
|
@ -190,23 +189,23 @@ def FlipsMoveJoy(left_key,right_key,up_key,down_key,lvertax):
|
|||
FlipsLy = screen_size[1] - PADDLE_height
|
||||
return FlipsLy, FlipsRy
|
||||
|
||||
def FlipsDraw():
|
||||
def FlipsDraw(plnumber):
|
||||
|
||||
lj.PolyLineOneColor([(FlipsLx,FlipsLy),(FlipsLx,FlipsLy + PADDLE_height),(FlipsLx + PADDLE_width , FlipsLy + PADDLE_height),(FlipsLx + PADDLE_width,FlipsLy)], white,0,True)
|
||||
lj.PolyLineOneColor([(FlipsRx,FlipsRy),(FlipsRx,FlipsRy + PADDLE_height),(FlipsRx + PADDLE_width , FlipsRy + PADDLE_height),(FlipsRx + PADDLE_width,FlipsRy)], white,0,True)
|
||||
lj.PolyLineOneColor([(FlipsLx,FlipsLy),(FlipsLx,FlipsLy + PADDLE_height),(FlipsLx + PADDLE_width , FlipsLy + PADDLE_height),(FlipsLx + PADDLE_width,FlipsLy)], white, plnumber, True)
|
||||
lj.PolyLineOneColor([(FlipsRx,FlipsRy),(FlipsRx,FlipsRy + PADDLE_height),(FlipsRx + PADDLE_width , FlipsRy + PADDLE_height),(FlipsRx + PADDLE_width,FlipsRy)], white, plnumber, True)
|
||||
|
||||
|
||||
def FiletDraw():
|
||||
lj.PolyLineOneColor([(screen_size[0]/2,screen_size[1]),(screen_size[0]/2,0)], white, 0,True)
|
||||
def FiletDraw(plnumber):
|
||||
lj.PolyLineOneColor([(screen_size[0]/2,screen_size[1]),(screen_size[0]/2,0)], white, plnumber,True)
|
||||
|
||||
|
||||
def Score1Draw(score):
|
||||
def Score1Draw(score, plnumber):
|
||||
#print "score1",score
|
||||
lj.Text(str(score),white, 0, 350, 50, 1, 0, 0, 0)
|
||||
lj.Text(str(score),white, plnumber, 350, 50, 1, 0, 0, 0)
|
||||
|
||||
def Score2Draw(score):
|
||||
def Score2Draw(score, plnumber):
|
||||
#print "score2",score
|
||||
lj.Text(str(score),white, 0, 500, 50, 1, 0, 0, 0)
|
||||
lj.Text(str(score),white, plnumber, 500, 50, 1, 0, 0, 0)
|
||||
|
||||
|
||||
|
||||
|
|
@ -235,7 +234,7 @@ def BallMove(xcoord,ycoord):
|
|||
elif BallY >= screen_size[1]:
|
||||
BallY = screen_size[1]
|
||||
|
||||
def BallDraw():
|
||||
def BallDraw(plnumber):
|
||||
global BallX,BallY
|
||||
|
||||
xmin = 0
|
||||
|
|
@ -255,5 +254,5 @@ def BallDraw():
|
|||
|
||||
#print "ball position",xmin,xmax,ymin,ymax
|
||||
|
||||
lj.PolyLineOneColor([(xmin,ymin),(xmin,ymax),(xmax,ymax),(xmax,ymin)], white,0,True)
|
||||
lj.PolyLineOneColor([(xmin,ymin),(xmin,ymax),(xmax,ymax),(xmax,ymin)], white, plnumber, True)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
# coding=UTF-8
|
||||
|
||||
'''
|
||||
LJ v0.8.0
|
||||
Some LJ functions useful for python clients (was framy.py)
|
||||
LJ v0.8.1
|
||||
Some LJ functions useful for python 2.7 clients (was framy.py)
|
||||
Functions and documentation here is low priority as python 2 support will stop soon.
|
||||
Better code your plugin with python 3 and lj3.py.
|
||||
|
||||
|
||||
Config
|
||||
PolyLineOneColor
|
||||
rPolyLineOneColor
|
||||
Text
|
||||
sendlj : remote control
|
||||
SendLJ : remote control
|
||||
LjClient :
|
||||
LjPl :
|
||||
DrawPL
|
||||
WebStatus
|
||||
|
||||
LICENCE : CC
|
||||
Sam Neurohack
|
||||
|
|
@ -29,21 +35,14 @@ point_list = []
|
|||
pl = [[],[],[],[]]
|
||||
|
||||
|
||||
'''
|
||||
LJIP = "127.0.0.1"
|
||||
|
||||
osclientlj = OSCClient()
|
||||
oscmsg = OSCMessage()
|
||||
osclientlj.connect((redisIP, 8002))
|
||||
'''
|
||||
|
||||
def sendlj(oscaddress,oscargs=''):
|
||||
def SendLJ(oscaddress,oscargs=''):
|
||||
|
||||
oscmsg = OSCMessage()
|
||||
oscmsg.setAddress(oscaddress)
|
||||
oscmsg.append(oscargs)
|
||||
|
||||
#print ("sending to bhorosc : ",oscmsg)
|
||||
print ("sending OSC message : ",oscmsg)
|
||||
try:
|
||||
osclientlj.sendto(oscmsg, (redisIP, 8002))
|
||||
oscmsg.clearData()
|
||||
|
|
@ -52,7 +51,8 @@ def sendlj(oscaddress,oscargs=''):
|
|||
pass
|
||||
#time.sleep(0.001
|
||||
|
||||
|
||||
def WebStatus(message):
|
||||
SendLJ("/status", message)
|
||||
|
||||
|
||||
ASCII_GRAPHICS = [
|
||||
|
|
@ -158,6 +158,17 @@ def Config(redisIP,client):
|
|||
ClientNumber = client
|
||||
#print "client configured",ClientNumber
|
||||
|
||||
|
||||
def LjClient(client):
|
||||
global ClientNumber
|
||||
|
||||
ClientNumber = client
|
||||
|
||||
def LjPl(pl):
|
||||
global PL
|
||||
|
||||
PL = pl
|
||||
|
||||
|
||||
def LineTo(xy, c, PL):
|
||||
|
||||
|
|
@ -248,6 +259,7 @@ def LinesPL(PL):
|
|||
print "Stupido !! your code is to old : use DrawPL() instead of LinesPL()"
|
||||
DrawPL(PL)
|
||||
|
||||
|
||||
def DrawPL(PL):
|
||||
#print '/pl/0/'+str(PL), str(pl[PL])
|
||||
if r.set('/pl/'+str(ClientNumber)+'/'+str(PL), str(pl[PL])) == True:
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import math
|
|||
import itertools
|
||||
import sys
|
||||
import os
|
||||
import types
|
||||
|
||||
'''
|
||||
is_py2 = sys.version[0] == '2'
|
||||
|
|
@ -30,6 +31,9 @@ import entities
|
|||
from controller import setup_controls
|
||||
import argparse
|
||||
|
||||
from OSC import OSCServer, OSCClient, OSCMessage
|
||||
OSCIP = "127.0.0.1"
|
||||
OSCPort = 8020
|
||||
|
||||
score = None
|
||||
|
||||
|
|
@ -87,6 +91,9 @@ red = rgb2int(255,0,0)
|
|||
blue = rgb2int(0,0,255)
|
||||
green = rgb2int(0,255,0)
|
||||
|
||||
#
|
||||
# Arguments handling
|
||||
#
|
||||
|
||||
print ("")
|
||||
print ("Arguments parsing if needed...")
|
||||
|
|
@ -129,11 +136,17 @@ def StartPlaying(first_time = False):
|
|||
|
||||
app_path = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
#
|
||||
# Pads via pygame
|
||||
#
|
||||
|
||||
print "Pygame init..."
|
||||
pygame.init()
|
||||
#sounds.InitSounds()
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
|
||||
Nbpads = pygame.joystick.get_count()
|
||||
print ("Joypads : ", str(Nbpads))
|
||||
|
||||
|
|
@ -184,6 +197,66 @@ y = ball_origin[1]
|
|||
|
||||
keystates = pygame.key.get_pressed()
|
||||
|
||||
#
|
||||
# OSC
|
||||
#
|
||||
|
||||
oscserver = OSCServer( (OSCIP, OSCPort) )
|
||||
oscserver.timeout = 0
|
||||
OSCRunning = True
|
||||
|
||||
|
||||
def OSCljclient(path, tags, args, source):
|
||||
|
||||
|
||||
print("LJ Pong got /ljpong/ljclient with value", args[0])
|
||||
lj.WebStatus("LJPong to virtual "+ str(args[0]))
|
||||
ljclient = args[0]
|
||||
lj.LjClient(ljclient)
|
||||
|
||||
def OSCpl(path, tags, args, source):
|
||||
|
||||
print("LJ Pong got /ljpong/pl with value", args[0])
|
||||
lj.WebStatus("LJPong to pl "+ str(args[0]))
|
||||
plnumber = args[0]
|
||||
|
||||
# /ping
|
||||
def OSCping(path, tags, args, source):
|
||||
|
||||
print("LJ Pong got /ping")
|
||||
lj.SendLJ("/pong","ljpong")
|
||||
lj.SendLJ("/ljpong/start",1)
|
||||
|
||||
|
||||
def OSC_frame():
|
||||
# clear timed_out flag
|
||||
oscserver.timed_out = False
|
||||
# handle all pending requests then return
|
||||
while not oscserver.timed_out:
|
||||
oscserver.handle_request()
|
||||
|
||||
|
||||
def handle_timeout(self):
|
||||
self.timed_out = True
|
||||
|
||||
print ""
|
||||
print "Launching OSC server..."
|
||||
print "at", OSCIP, "port",str(OSCPort)
|
||||
|
||||
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
|
||||
|
||||
# OSC callbacks
|
||||
|
||||
oscserver.addMsgHandler( "/ljpong/ljclient", OSCljclient )
|
||||
oscserver.addMsgHandler("/ljpong/pl", OSCpl)
|
||||
oscserver.addMsgHandler("/ping", OSCping)
|
||||
|
||||
print "Running..."
|
||||
|
||||
#
|
||||
# Game main loop
|
||||
#
|
||||
|
||||
|
||||
while fs != GAME_FS_QUIT:
|
||||
|
||||
|
|
@ -192,6 +265,8 @@ while fs != GAME_FS_QUIT:
|
|||
if event.type == pygame.QUIT:
|
||||
fs = GAME_FS_QUIT
|
||||
|
||||
OSC_frame()
|
||||
|
||||
keystates_prev = keystates[:]
|
||||
keystates = pygame.key.get_pressed()[:]
|
||||
|
||||
|
|
@ -346,21 +421,19 @@ while fs != GAME_FS_QUIT:
|
|||
|
||||
if fs == GAME_FS_PLAY or fs == GAME_FS_GAMEOVER or fs == GAME_FS_LAUNCH:
|
||||
|
||||
entities.Score1Draw(lscore)
|
||||
entities.Score2Draw(rscore)
|
||||
entities.FlipsDraw()
|
||||
entities.BallDraw()
|
||||
entities.FiletDraw()
|
||||
lj.DrawPL(0)
|
||||
entities.Score1Draw(lscore, plnumber)
|
||||
entities.Score2Draw(rscore, plnumber)
|
||||
entities.FlipsDraw(plnumber)
|
||||
entities.BallDraw(plnumber)
|
||||
entities.FiletDraw(plnumber)
|
||||
lj.DrawPL(plnumber)
|
||||
|
||||
if fs == GAME_FS_MENU:
|
||||
|
||||
entities.LogoDraw()
|
||||
lj.DrawPL(0)
|
||||
entities.LogoDraw(plnumber)
|
||||
lj.DrawPL(plnumber)
|
||||
|
||||
|
||||
# TODO : rendre indépendante la fréquence de rafraîchissement de l'écran par
|
||||
# rapport à celle de l'animation du jeu
|
||||
clock.tick(100)
|
||||
|
||||
pygame.quit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue