forked from protonphoton/LJ
Laser Pong
This commit is contained in:
parent
531a5f0490
commit
e6366649a4
25 changed files with 1837 additions and 563 deletions
255
clients/games/ljpong/controller.py
Executable file
255
clients/games/ljpong/controller.py
Executable file
|
|
@ -0,0 +1,255 @@
|
|||
"""
|
||||
Directions Buttons defined correctly only for PS3 and USBJoystick
|
||||
|
||||
|
||||
Represent various videogame controllers
|
||||
|
||||
TODO: Various play schemes/configs
|
||||
XXX: UNTESTED
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
def setup_controls(joystick):
|
||||
"""
|
||||
Joystick wrapper.
|
||||
"""
|
||||
if re.search('playstation', joystick.get_name(), re.I):
|
||||
return Ps3Controller(joystick)
|
||||
|
||||
elif re.search('X-box', joystick.get_name(), re.I):
|
||||
return XboxController(joystick)
|
||||
|
||||
elif re.search('Saitek', joystick.get_name(), re.I):
|
||||
return MySaitekController(joystick)
|
||||
|
||||
elif re.search('Thrustmaster dual analog 3.2', joystick.get_name(), re.I):
|
||||
return MyThrustController(joystick)
|
||||
|
||||
elif re.search('2n1 USB', joystick.get_name(), re.I):
|
||||
return CSLController(joystick)
|
||||
|
||||
elif re.search('Joystick', joystick.get_name(), re.I):
|
||||
return USBController(joystick)
|
||||
|
||||
return Controller(joystick)
|
||||
|
||||
class Controller(object):
|
||||
|
||||
def __init__(self, joystick):
|
||||
"""Pass a PyGame joystick instance."""
|
||||
self.js = joystick
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(2)
|
||||
|
||||
class XboxController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(XboxController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(4)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(11)
|
||||
|
||||
class Ps3Controller(Controller):
|
||||
|
||||
#up 4 _DOWN 6 left 7 right 5 croix 14 rond 13 triangle 12
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(Ps3Controller, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
# TODO: Verify
|
||||
return self.js.get_button(8)
|
||||
|
||||
def getRightTrigger(self):
|
||||
# TODO: Verify
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getUp(self):
|
||||
return self.js.get_button(4)
|
||||
|
||||
def getDown(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getLeft(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
def getRight(self):
|
||||
return self.js.get_button(5)
|
||||
|
||||
def getFire1(self):
|
||||
return self.js.get_button(14)
|
||||
|
||||
def getFire2(self):
|
||||
return self.js.get_button(13)
|
||||
|
||||
|
||||
class MySaitekController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(MySaitekController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
class MyThrustController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(MyThrustController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(5)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
|
||||
class CSLController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(CSLController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
def getFire1(self):
|
||||
return self.js.get_button(2)
|
||||
|
||||
def getFire2(self):
|
||||
return self.js.get_button(1)
|
||||
|
||||
class USBController(Controller):
|
||||
|
||||
|
||||
# my USB Joystick
|
||||
#up axis 0 -1 DOWN axis 0 1 left axis 1 1 right axis 1 -1 bouton gauche 10 bouton droite 9
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(USBController, self).__init__(joystick)
|
||||
|
||||
|
||||
def getUp(self):
|
||||
if self.js.get_axis(0) == -1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getDown(self):
|
||||
if self.js.get_axis(0) > 0.9:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getLeft(self):
|
||||
if self.js.get_axis(1) == 1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getRight(self):
|
||||
if self.js.get_axis(1) == -1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(10)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getFire1(self):
|
||||
if self.js.get_button(10) == 1:
|
||||
print "fire 1"
|
||||
return self.js.get_button(10)
|
||||
|
||||
def getFire2(self):
|
||||
if self.js.get_button(9) == 1:
|
||||
print "fire 2"
|
||||
return self.js.get_button(9)
|
||||
|
||||
259
clients/games/ljpong/entities.py
Normal file
259
clients/games/ljpong/entities.py
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
#!/usr/bin/python2.7
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- mode: Python -*-
|
||||
'''
|
||||
|
||||
LJ Laser Pong entities
|
||||
v0.1
|
||||
|
||||
Sam Neurohack
|
||||
|
||||
'''
|
||||
|
||||
|
||||
# STDLIB
|
||||
import math
|
||||
import itertools
|
||||
import sys
|
||||
import os
|
||||
import lj
|
||||
|
||||
import time
|
||||
import random
|
||||
|
||||
|
||||
|
||||
screen_size = [800,600]
|
||||
|
||||
top_left = [200,100]
|
||||
bottom_left = [200,300]
|
||||
top_right = [600,100]
|
||||
bottom_right = [600,300]
|
||||
|
||||
score_pos = [550,40]
|
||||
score2_pos = [259,40]
|
||||
|
||||
# X Y position on bottom left of each paddle (="flips")
|
||||
ball_origin = [400,300,200]
|
||||
text_pos = [300,500,200]
|
||||
BALL_acc = 0.06
|
||||
PADDLE_height = 100
|
||||
PADDLE_width = 10
|
||||
PADDLE3D_height = 100
|
||||
PADDLE3D_width = 100
|
||||
FACT3D = 2
|
||||
FLIPS_lorigin = [10,300,0]
|
||||
FLIPS_rorigin = [780,300,400]
|
||||
flips_attraction = 0.007
|
||||
|
||||
xy_center = [screen_size[0]/2,screen_size[1]/2]
|
||||
|
||||
DEFAULT_SPOKES = range(0,359,60)
|
||||
DEFAULT_PLAYER_EXPLODE_COLOR = 0xFFFF00
|
||||
DEFAULT_SIDE_COUNT = 6
|
||||
DREARRANGE_SIDES = .02
|
||||
|
||||
|
||||
CRASH_SHAKE_MAX = 6
|
||||
TDN_CRASH = 200
|
||||
|
||||
GAME_FS_QUIT = -1
|
||||
GAME_FS_MENU = 0
|
||||
GAME_FS_PLAY = 1
|
||||
GAME_FS_LAUNCH = 2
|
||||
GAME_FS_GAMEOVER = 3
|
||||
|
||||
BUMPERS_COLOR_YELLOW = 0xFFFF00
|
||||
BUMPERS_COLOR_RED = 0xFF0000
|
||||
BUMPERS_COLOR_BLACK = 0x000000
|
||||
BUMPERS_SIZE_X = 60
|
||||
BUMPERS_SIZE_Y = 110
|
||||
BUMPERS_FORCE = 1.1
|
||||
|
||||
|
||||
BALL_SPEED = 5
|
||||
BALL_MAX = 4
|
||||
BALL_SIZE_X = 3
|
||||
BALL_SIZE_Y = 3
|
||||
LASER_ANGLE = 0
|
||||
|
||||
|
||||
|
||||
GRAVITY = 0.0001
|
||||
|
||||
NO_BGM = False
|
||||
#NO_BGM = True
|
||||
|
||||
def rgb2int(r,g,b):
|
||||
return int('0x%02x%02x%02x' % (r,g,b),0)
|
||||
|
||||
white = rgb2int(255,255,255)
|
||||
red = rgb2int(255,0,0)
|
||||
blue = rgb2int(0,0,255)
|
||||
green = rgb2int(0,255,0)
|
||||
|
||||
|
||||
LOGO = [
|
||||
# L/o
|
||||
[[(-140,-100),(-200,20),(40,20)],0xFF00],
|
||||
# aser
|
||||
[[(-140,-40),(-100,-40,),(-120,0),(-160,0),(-110,-20)],0xFFFF],
|
||||
[[(-40,-40),(-60,-40),(-90,-20),(-50,-20),(-80,0),(-100,0)],0xFFFF],
|
||||
[[(-30,-20),(10,-20),(0,-40),(-20,-40),(-30,-20),(-30,0),(-10,0)],0xFFFF],
|
||||
[[(20,0),(40,-40),(35,-30),(50,-40),(70,-40)],0xFFFF],
|
||||
# Pinball
|
||||
[[(-185,50),(-145,50),(-130,20),(-170,20),(-200,80)],0xFFFF00], #P
|
||||
[[(-80,40),(-120,40),(-140,80),(-100,80),(-80,40)],0xFFFF], #O
|
||||
[[(-80,80),(-60,40),(-65,50),(-40,40),(-25,50),(-40,80)],0xFFFF], #N
|
||||
[[(40,40),(0,40),(-20,80),(20,80),(30,60),(10,60)],0xFFFF], #G
|
||||
]
|
||||
|
||||
|
||||
LOGO_OFFSET_X = 460
|
||||
LOGO_OFFSET_Y = 250
|
||||
|
||||
def LogoDraw():
|
||||
'''
|
||||
Dessine le logo
|
||||
'''
|
||||
for pl_color in LOGO:
|
||||
c = pl_color[1]
|
||||
xy_list = []
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
FlipsLx, FlipsLy = FLIPS_lorigin[0], FLIPS_lorigin[1]
|
||||
FlipsRx, FlipsRy = FLIPS_rorigin[0], FLIPS_rorigin[1]
|
||||
FlipsSpeed = 7
|
||||
|
||||
|
||||
def FlipsMove(left_key,right_key,up_key,down_key):
|
||||
global FlipsLx, FlipsLy, FlipsRx, FlipsRy
|
||||
|
||||
if left_key:
|
||||
FlipsLy -= FlipsSpeed
|
||||
if FlipsLy < 1:
|
||||
FlipsLy = 1
|
||||
|
||||
if right_key:
|
||||
FlipsLy += FlipsSpeed
|
||||
if FlipsLy > screen_size[1] - PADDLE_height:
|
||||
FlipsLy = screen_size[1] - PADDLE_height
|
||||
|
||||
if up_key:
|
||||
FlipsRy -= FlipsSpeed
|
||||
if FlipsRy < 1:
|
||||
FlipsRy = 1
|
||||
|
||||
if down_key:
|
||||
FlipsRy += FlipsSpeed
|
||||
if FlipsRy > screen_size[1] - PADDLE_height:
|
||||
FlipsRy = screen_size[1] - PADDLE_height
|
||||
|
||||
return FlipsLy, FlipsRy
|
||||
|
||||
def FlipsMoveJoy(left_key,right_key,up_key,down_key,lvertax):
|
||||
|
||||
if left_key:
|
||||
FlipsLy -= FlipsSpeed
|
||||
if FlipsLy < 1:
|
||||
FlipsLy = 1
|
||||
|
||||
if right_key:
|
||||
FlipsLy += FlipsSpeed
|
||||
if FlipsLy > screen_size[1] - PADDLE_height:
|
||||
FlipsLy = screen_size[1] - PADDLE_height
|
||||
|
||||
if up_key:
|
||||
FlipsRy -= FlipsSpeed
|
||||
if FlipsRy < 1:
|
||||
FlipsRy = 1
|
||||
if down_key > 0.01:
|
||||
FlipsRy += FlipsSpeed
|
||||
if FlipsRy > screen_size[1] - PADDLE_height:
|
||||
FlipsRy = screen_size[1] - PADDLE_height
|
||||
|
||||
if lvertax:
|
||||
print lvertax
|
||||
if lvertax < 0:
|
||||
FlipsLy -= FlipsSpeed
|
||||
if FlipsLy < 1:
|
||||
FlipsLy = 1
|
||||
elif lvertax > 0.01:
|
||||
FlipsLy += FlipsSpeed
|
||||
if FlipsLy > screen_size[1] - PADDLE_height:
|
||||
FlipsLy = screen_size[1] - PADDLE_height
|
||||
return FlipsLy, FlipsRy
|
||||
|
||||
def FlipsDraw():
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def FiletDraw():
|
||||
lj.PolyLineOneColor([(screen_size[0]/2,screen_size[1]),(screen_size[0]/2,0)], white, 0,True)
|
||||
|
||||
|
||||
def Score1Draw(score):
|
||||
#print "score1",score
|
||||
lj.Text(str(score),white, 0, 350, 50, 1, 0, 0, 0)
|
||||
|
||||
def Score2Draw(score):
|
||||
#print "score2",score
|
||||
lj.Text(str(score),white, 0, 500, 50, 1, 0, 0, 0)
|
||||
|
||||
|
||||
|
||||
BallX, BallY = ball_origin[0], ball_origin[1]
|
||||
BallZoom = 1
|
||||
|
||||
|
||||
def BallMove(xcoord,ycoord):
|
||||
global BallX,BallY
|
||||
|
||||
BallX = xcoord
|
||||
BallY = ycoord
|
||||
#print "ball move",xcoord,ycoord
|
||||
|
||||
#BallZoom = ?
|
||||
|
||||
if BallX < 0:
|
||||
BallX = 0
|
||||
|
||||
elif BallX >= screen_size[0]:
|
||||
BallX = screen_size[0]
|
||||
|
||||
if BallY < 0:
|
||||
BallY = 0
|
||||
|
||||
elif BallY >= screen_size[1]:
|
||||
BallY = screen_size[1]
|
||||
|
||||
def BallDraw():
|
||||
global BallX,BallY
|
||||
|
||||
xmin = 0
|
||||
xmax = BALL_SIZE_X * 2
|
||||
ymin = 0
|
||||
ymax = BALL_SIZE_Y * 2
|
||||
|
||||
xmin = (xmin*BallZoom)
|
||||
ymin = (ymin*BallZoom)
|
||||
xmax = (xmax*BallZoom)
|
||||
ymax = (ymax*BallZoom)
|
||||
|
||||
xmin += BallX
|
||||
xmax += BallX
|
||||
ymin += BallY
|
||||
ymax += BallY
|
||||
|
||||
#print "ball position",xmin,xmax,ymin,ymax
|
||||
|
||||
lj.PolyLineOneColor([(xmin,ymin),(xmin,ymax),(xmax,ymax),(xmax,ymin)], white,0,True)
|
||||
|
||||
17
clients/games/ljpong/gstt.py
Executable file
17
clients/games/ljpong/gstt.py
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
# coding=UTF-8
|
||||
'''
|
||||
Etat global (anciennement singleton de la classe GameState + autres VARIABLES nécessaires partout)"
|
||||
'''
|
||||
|
||||
from globalVars import *
|
||||
|
||||
# Etat global général
|
||||
app_path = ""
|
||||
|
||||
# anciennement GameState
|
||||
fs = GAME_FS_GAMEOVER
|
||||
plyr = None
|
||||
score = None
|
||||
bmprs = None
|
||||
|
||||
|
||||
310
clients/games/ljpong/lj.py
Normal file
310
clients/games/ljpong/lj.py
Normal file
|
|
@ -0,0 +1,310 @@
|
|||
# coding=UTF-8
|
||||
|
||||
'''
|
||||
LJ v0.8.0
|
||||
Some LJ functions useful for python clients (was framy.py)
|
||||
|
||||
Config
|
||||
PolyLineOneColor
|
||||
rPolyLineOneColor
|
||||
Text
|
||||
sendlj : remote control
|
||||
DrawPL
|
||||
|
||||
LICENCE : CC
|
||||
Sam Neurohack
|
||||
|
||||
'''
|
||||
|
||||
import math
|
||||
import redis
|
||||
from OSC import OSCServer, OSCClient, OSCMessage
|
||||
|
||||
redisIP = '127.0.0.1'
|
||||
r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
ClientNumber = 0
|
||||
|
||||
point_list = []
|
||||
pl = [[],[],[],[]]
|
||||
|
||||
|
||||
'''
|
||||
LJIP = "127.0.0.1"
|
||||
|
||||
osclientlj = OSCClient()
|
||||
oscmsg = OSCMessage()
|
||||
osclientlj.connect((redisIP, 8002))
|
||||
'''
|
||||
|
||||
def sendlj(oscaddress,oscargs=''):
|
||||
|
||||
oscmsg = OSCMessage()
|
||||
oscmsg.setAddress(oscaddress)
|
||||
oscmsg.append(oscargs)
|
||||
|
||||
#print ("sending to bhorosc : ",oscmsg)
|
||||
try:
|
||||
osclientlj.sendto(oscmsg, (redisIP, 8002))
|
||||
oscmsg.clearData()
|
||||
except:
|
||||
print ('Connection to LJ refused : died ?')
|
||||
pass
|
||||
#time.sleep(0.001
|
||||
|
||||
|
||||
|
||||
|
||||
ASCII_GRAPHICS = [
|
||||
|
||||
#implementé
|
||||
|
||||
[(-50,30), (-30,-30), (30,-30), (10,30), (-50,30)], #0
|
||||
[(-20,30), (0,-30), (-20,30)], #1
|
||||
[(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #2
|
||||
[(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #3
|
||||
[(30,10), (-30,10), (0,-30), (0,30)], #4
|
||||
[(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #5
|
||||
[(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #6
|
||||
[(-30,-30), (30,-30), (-30,30)], #7
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (-30,30), (-30,0), (30,0)], #8
|
||||
[(30,0), (-30,0), (-30,-10), (0,-30), (30,-30), (30,10), (0,30), (-30,30)], #9
|
||||
|
||||
# A implementer
|
||||
[(-30,10), (30,-10), (30,10), (0,30), (-30,10), (-30,-10), (0,-30), (30,-10)], #:
|
||||
[(-30,-10), (0,-30), (0,30)], [(-30,30), (30,30)], #;
|
||||
[(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #<
|
||||
[(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #=
|
||||
[(30,10), (-30,10), (0,-30), (0,30)], #>
|
||||
[(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #?
|
||||
[(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #@
|
||||
|
||||
# Implementé
|
||||
|
||||
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (30,0), (-30,0)], #A
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (30,0), (-30,0)], #A
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (-30,30), (-30,0), (30,0)], #B
|
||||
[(30,30), (-30,30), (-30,-30), (30,-30)], #C
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (-30,30)], #D
|
||||
[(30,30), (-30,30), (-30,-0), (30,0), (-30,0), (-30,-30), (30,-30)], #E
|
||||
[(-30,30), (-30,-0), (30,0), (-30,0), (-30,-30), (30,-30)], #F
|
||||
[(0,0), (30,0), (30,30), (-30,30), (-30,-30),(30,-30)], #G
|
||||
[(-30,-30), (-30,30), (-30,0), (30,0), (30,30), (30,-30)], #H
|
||||
[(0,30), (0,-30)], #I
|
||||
[(-30,30), (0,-30), (0,-30), (-30,-30), (30,-30)], #J
|
||||
[(-30,-30), (-30,30), (-30,0), (30,-30), (-30,0), (30,30)], #K
|
||||
[(30,30), (-30,30), (-30,-30)], #L
|
||||
[(-30,30), (-30,-30), (0,0), (30,-30), (30,30)], #M
|
||||
[(-30,30), (-30,-30), (30,30), (30,-30)], #N
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (-30,30)], #O
|
||||
[(-30,0), (30,0), (30,-30), (-30,-30), (-30,30)], #P
|
||||
[(30,30), (30,-30), (-30,-30), (-30,30), (30,30),(35,35)], #Q
|
||||
[(-30,30), (-30,-30), (30,-30), (30,0), (-30,0), (30,30)], #R
|
||||
[(30,-30), (-30,-30), (-30,0), (30,0), (30,30), (-30,30)], #S
|
||||
[(0,30), (0,-30), (-30,-30), (30,-30)], #T
|
||||
[(-30,-30), (-30,30), (30,30), (30,-30)], #U
|
||||
[(-30,-30), (0,30), (30,-30)], #V
|
||||
[(-30,-30), (-30,30), (0,0), (30,30), (30,-30)], #W
|
||||
[(-30,30), (30,-30)], [(-30,-30), (30,30)], #X
|
||||
[(0,30), (0,0), (30,-30), (0,0), (-30,-30)], #Y
|
||||
[(30,30), (-30,30), (30,-30), (-30,-30)], #Z
|
||||
|
||||
# A implementer
|
||||
|
||||
[(-30,-10), (0,-30), (0,30)], [(-30,30), (30,30)], #[
|
||||
[(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #\
|
||||
[(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #]
|
||||
[(30,10), (-30,10), (0,-30), (0,30)], #^
|
||||
[(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #_
|
||||
[(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #`
|
||||
|
||||
# Implementé
|
||||
|
||||
[(-20,20), (-20,-20), (20,-20), (20,20), (20,0), (-20,0)], #a
|
||||
[(-20,20), (-20,-20), (20,-20), (20,20), (-20,20), (-20,0), (20,0)], #b
|
||||
[(20,20), (-20,20), (-20,-20), (20,-20)], #c
|
||||
[(-20,20), (-20,-20), (20,-20), (20,20), (-20,20)], #d
|
||||
[(20,20), (-20,20), (-20,-0), (20,0), (-20,0), (-20,-20), (20,-20)], #e
|
||||
[(-20,20), (-20,-0), (20,0), (-20,0), (-20,-20), (20,-20)], #f
|
||||
[(0,0), (20,0), (20,20), (-20,20), (-20,-20),(20,-20)], #g
|
||||
[(-20,-20), (-20,20), (-20,0), (20,0), (20,20), (20,-20)], #H
|
||||
[(0,20), (0,-20)], #I
|
||||
[(-20,20), (0,-20), (0,-20), (-20,-20), (20,-20)], #J
|
||||
[(-20,-20), (-20,20), (-20,0), (20,-20), (-20,0), (20,20)], #K
|
||||
[(20,20), (-20,20), (-20,-20)], #L
|
||||
[(-20,20), (-20,-20), (0,0), (20,-20), (20,20)], #M
|
||||
[(-20,20), (-20,-20), (20,20), (20,-20)], #N
|
||||
[(-20,20), (-20,-20), (20,-20), (20,20), (-20,20)], #O
|
||||
[(-20,0), (20,0), (20,-20), (-20,-20), (-20,20)], #P
|
||||
[(20,20), (20,-20), (-20,-20), (-20,20), (20,20),(25,25)], #Q
|
||||
[(-20,20), (-20,-20), (20,-20), (20,0), (-20,0), (20,20)], #R
|
||||
[(20,-20), (-20,-20), (-20,0), (20,0), (20,20), (-20,20)], #S
|
||||
[(0,20), (0,-20), (-20,-20), (20,-20)], #T
|
||||
[(-20,-20), (-20,20), (20,20), (20,-20)], #U
|
||||
[(-20,-20), (0,20), (20,-20)], #V
|
||||
[(-20,-20), (-20,20), (0,0), (20,20), (20,-20)], #W
|
||||
[(-20,20), (20,-20)], [(-20,-20), (20,20)], #X
|
||||
[(0,20), (0,0), (20,-20), (0,0), (-20,-20)], #Y
|
||||
[(20,20), (-20,20), (20,-20), (-20,-20)], #Z
|
||||
|
||||
[(-2,15), (2,15)] # Point a la place de {
|
||||
]
|
||||
|
||||
def Config(redisIP,client):
|
||||
global ClientNumber
|
||||
|
||||
r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
ClientNumber = client
|
||||
#print "client configured",ClientNumber
|
||||
|
||||
|
||||
def LineTo(xy, c, PL):
|
||||
|
||||
pl[PL].append((xy + (c,)))
|
||||
|
||||
def Line(xy1, xy2, c, PL):
|
||||
LineTo(xy1, 0, PL)
|
||||
LineTo(xy2, c , PL)
|
||||
|
||||
|
||||
def PolyLineOneColor(xy_list, c, PL , closed ):
|
||||
#print "--"
|
||||
#print "c",c
|
||||
#print "xy_list",xy_list
|
||||
#print "--"
|
||||
xy0 = None
|
||||
for xy in xy_list:
|
||||
if xy0 is None:
|
||||
xy0 = xy
|
||||
#print "xy0:",xy0
|
||||
LineTo(xy0,0, PL)
|
||||
LineTo(xy0,c, PL)
|
||||
else:
|
||||
#print "xy:",xy
|
||||
LineTo(xy,c, PL)
|
||||
if closed:
|
||||
LineTo(xy0,c, PL)
|
||||
|
||||
|
||||
# Computing points coordinates for rPolyline function from 3D and around 0,0 to pygame coordinates
|
||||
def Pointransf(xy, xpos = 0, ypos =0, resize =1, rotx =0, roty =0 , rotz=0):
|
||||
|
||||
x = xy[0] * resize
|
||||
y = xy[1] * resize
|
||||
z = 0
|
||||
|
||||
rad = math.radians(rotx)
|
||||
cosaX = math.cos(rad)
|
||||
sinaX = math.sin(rad)
|
||||
|
||||
y2 = y
|
||||
y = y2 * cosaX - z * sinaX
|
||||
z = y2 * sinaX + z * cosaX
|
||||
|
||||
rad = math.radians(roty)
|
||||
cosaY = math.cos(rad)
|
||||
sinaY = math.sin(rad)
|
||||
|
||||
z2 = z
|
||||
z = z2 * cosaY - x * sinaY
|
||||
x = z2 * sinaY + x * cosaY
|
||||
|
||||
rad = math.radians(rotz)
|
||||
cosZ = math.cos(rad)
|
||||
sinZ = math.sin(rad)
|
||||
|
||||
x2 = x
|
||||
x = x2 * cosZ - y * sinZ
|
||||
y = x2 * sinZ + y * cosZ
|
||||
|
||||
#print xy, (x + xpos,y+ ypos)
|
||||
return (x + xpos,y+ ypos)
|
||||
'''
|
||||
to understand why it get negative Y
|
||||
|
||||
# 3D to 2D projection
|
||||
factor = 4 * gstt.cc[22] / ((gstt.cc[21] * 8) + z)
|
||||
print xy, (x * factor + xpos, - y * factor + ypos )
|
||||
return (x * factor + xpos, - y * factor + ypos )
|
||||
'''
|
||||
|
||||
# Send 2D point list around 0,0 with 3D rotation resizing and reposition around xpos ypos
|
||||
#def rPolyLineOneColor(self, xy_list, c, PL , closed, xpos = 0, ypos =0, resize =1, rotx =0, roty =0 , rotz=0):
|
||||
def rPolyLineOneColor(xy_list, c, PL , closed, xpos = 0, ypos =0, resize =0.7, rotx =0, roty =0 , rotz=0):
|
||||
xy0 = None
|
||||
for xy in xy_list:
|
||||
if xy0 is None:
|
||||
xy0 = xy
|
||||
LineTo(Pointransf(xy0, xpos, ypos, resize, rotx, roty, rotz),0, PL)
|
||||
LineTo(Pointransf(xy0, xpos, ypos, resize, rotx, roty, rotz),c, PL)
|
||||
else:
|
||||
LineTo(Pointransf(xy, xpos, ypos, resize, rotx, roty, rotz),c, PL)
|
||||
if closed:
|
||||
LineTo(Pointransf(xy0, xpos, ypos, resize, rotx, roty, rotz),c, PL)
|
||||
|
||||
|
||||
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:
|
||||
#print '/pl/'+str(ClientNumber)+'/'+str(PL), str(pl[PL])
|
||||
pl[PL] = []
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def ResetPL(self, PL):
|
||||
pl[PL] = []
|
||||
|
||||
|
||||
|
||||
def DigitsDots(number,color):
|
||||
dots =[]
|
||||
for dot in ASCII_GRAPHICS[number]:
|
||||
#print dot
|
||||
dots.append((gstt.xy_center[0]+dot[0],gstt.xy_center[1]+dot[1],color))
|
||||
#self.point_list.append((xy + (c,)))
|
||||
return dots
|
||||
|
||||
def CharDots(char,color):
|
||||
|
||||
dots =[]
|
||||
for dot in ASCII_GRAPHICS[ord(char)-46]:
|
||||
dots.append((dot[0],dot[1],color))
|
||||
return dots
|
||||
|
||||
def Text(message,c, PL, xpos, ypos, resize, rotx, roty, rotz):
|
||||
|
||||
dots =[]
|
||||
|
||||
l = len(message)
|
||||
i= 0
|
||||
#print message
|
||||
|
||||
for ch in message:
|
||||
|
||||
#print ""
|
||||
# texte centre en x automatiquement selon le nombre de lettres l
|
||||
x_offset = 26 * (- (0.9*l) + 3*i)
|
||||
# Digits
|
||||
if ord(ch)<58:
|
||||
char_pl_list = ASCII_GRAPHICS[ord(ch) - 48]
|
||||
else:
|
||||
char_pl_list = ASCII_GRAPHICS[ord(ch) - 46]
|
||||
char_draw = []
|
||||
#dots.append((char_pl_list[0][0] + x_offset,char_pl_list[0][1],0))
|
||||
|
||||
for xy in char_pl_list:
|
||||
char_draw.append((xy[0] + x_offset,xy[1],c))
|
||||
i +=1
|
||||
#print ch,char_pl_list,char_draw
|
||||
rPolyLineOneColor(char_draw, c, PL , False, xpos, ypos, resize, rotx, roty, rotz)
|
||||
#dots.append(char_draw)
|
||||
|
||||
|
||||
|
||||
|
||||
367
clients/games/ljpong/main.py
Executable file
367
clients/games/ljpong/main.py
Executable file
|
|
@ -0,0 +1,367 @@
|
|||
#!/usr/bin/python2.7
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- mode: Python -*-
|
||||
'''
|
||||
LJ Laser Pong v0.8
|
||||
|
||||
Sam Neurohack
|
||||
|
||||
'''
|
||||
|
||||
import pygame
|
||||
import math
|
||||
import itertools
|
||||
import sys
|
||||
import os
|
||||
|
||||
'''
|
||||
is_py2 = sys.version[0] == '2'
|
||||
if is_py2:
|
||||
from Queue import Queue
|
||||
else:
|
||||
from queue import Queue
|
||||
'''
|
||||
|
||||
import thread
|
||||
import time
|
||||
import random
|
||||
import lj
|
||||
import entities
|
||||
from controller import setup_controls
|
||||
import argparse
|
||||
|
||||
|
||||
score = None
|
||||
|
||||
screen_size = [800,600]
|
||||
|
||||
top_left = [200,100]
|
||||
bottom_left = [200,300]
|
||||
top_right = [600,100]
|
||||
bottom_right = [600,300]
|
||||
|
||||
score_pos = [550,40]
|
||||
score2_pos = [259,40]
|
||||
text_pos = [300,500,200]
|
||||
|
||||
ball_origin = [400,300,200]
|
||||
BALL_SPEED = 5
|
||||
BALL_SIZE_X = 3
|
||||
BALL_SIZE_Y = 3
|
||||
BALL_acc = 0.06
|
||||
|
||||
PADDLE_height = 100
|
||||
PADDLE_width = 10
|
||||
|
||||
FlipsSpeed = 7
|
||||
FLIPS_lorigin = [10,300,0]
|
||||
FLIPS_rorigin = [780,300,400]
|
||||
FlipsLx, FlipsLy = FLIPS_lorigin[0], FLIPS_lorigin[1]
|
||||
FlipsRx, FlipsRy = FLIPS_rorigin[0], FLIPS_rorigin[1]
|
||||
|
||||
|
||||
xy_center = [screen_size[0]/2,screen_size[1]/2]
|
||||
|
||||
GAME_FS_QUIT = -1
|
||||
GAME_FS_MENU = 0
|
||||
GAME_FS_PLAY = 1
|
||||
GAME_FS_GAMEOVER = 2
|
||||
GAME_FS_LAUNCH = 2
|
||||
|
||||
SCORE_ZOOM_PLAYING = 1.6
|
||||
SCORE_ZOOM_GAMEOVER = 5.0
|
||||
SCORE_DZOOM_PLAYING = -0.4
|
||||
SCORE_DZOOM_GAMEOVER = 0.1
|
||||
|
||||
Score1Zoom = SCORE_ZOOM_PLAYING
|
||||
|
||||
GRAVITY = 0.0001
|
||||
|
||||
fs = GAME_FS_MENU
|
||||
|
||||
def rgb2int(r,g,b):
|
||||
return int('0x%02x%02x%02x' % (r,g,b),0)
|
||||
|
||||
white = rgb2int(255,255,255)
|
||||
red = rgb2int(255,0,0)
|
||||
blue = rgb2int(0,0,255)
|
||||
green = rgb2int(0,255,0)
|
||||
|
||||
|
||||
print ("")
|
||||
print ("Arguments parsing if needed...")
|
||||
argsparser = argparse.ArgumentParser(description="Laserpong")
|
||||
|
||||
argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ (127.0.0.1 by default) ",type=str)
|
||||
argsparser.add_argument("-c","--client",help="LJ client number (0 by default)",type=int)
|
||||
argsparser.add_argument("-l","--laser",help="Laser number to be displayed (0 by default)",type=int)
|
||||
|
||||
args = argsparser.parse_args()
|
||||
|
||||
|
||||
if args.client:
|
||||
ljclient = args.client
|
||||
else:
|
||||
ljclient = 0
|
||||
|
||||
if args.laser:
|
||||
plnumber = args.laser
|
||||
else:
|
||||
plnumber = 0
|
||||
|
||||
# Redis Computer IP
|
||||
if args.redisIP != None:
|
||||
redisIP = args.redisIP
|
||||
else:
|
||||
redisIP = '127.0.0.1'
|
||||
|
||||
lj.Config(redisIP,ljclient)
|
||||
|
||||
|
||||
def StartPlaying(first_time = False):
|
||||
global fs
|
||||
|
||||
lscore = 0
|
||||
rscore = 0
|
||||
fs = GAME_FS_LAUNCH
|
||||
x = ball_origin[0]
|
||||
y = ball_origin[1]
|
||||
|
||||
app_path = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
pygame.init()
|
||||
#sounds.InitSounds()
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
Nbpads = pygame.joystick.get_count()
|
||||
print ("Joypads : ", str(Nbpads))
|
||||
|
||||
if Nbpads != 2:
|
||||
|
||||
print ('')
|
||||
print ('')
|
||||
print ("THIS VERSION NEEDS 2 PADS. PLEASE CONNECT THEM.")
|
||||
print ('')
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
if Nbpads > 1:
|
||||
|
||||
pad2 = pygame.joystick.Joystick(1)
|
||||
pad2.init()
|
||||
print "Pad2 :", pad2.get_name()
|
||||
numButtons = pad2.get_numbuttons()
|
||||
#print ("Axis Pad 2 :", str(pad2.get_numaxes()))
|
||||
#print ("Buttons Pad 2 :" , str(numButtons))
|
||||
|
||||
# joy is pad abstraction to handle many different devices.
|
||||
joy2 = setup_controls(pad2)
|
||||
|
||||
if Nbpads > 0:
|
||||
|
||||
pad1 = pygame.joystick.Joystick(0)
|
||||
pad1.init()
|
||||
print "Pad1 :",pad1.get_name()
|
||||
numButtons = pad1.get_numbuttons()
|
||||
joy1 = setup_controls(pad1)
|
||||
#print ("Axis Pad 1 :", str(pad1.get_numaxes()))
|
||||
#print ("Buttons Pad 1 :" , str(numButtons))
|
||||
|
||||
update_screen = False
|
||||
|
||||
xvel = - 1
|
||||
yvel = 0
|
||||
lscore = 0
|
||||
rscore = 0
|
||||
ly = FLIPS_lorigin[1]
|
||||
ry = FLIPS_rorigin[1]
|
||||
flipsy = [ly, ry]
|
||||
stick = 0
|
||||
x = ball_origin[0]
|
||||
y = ball_origin[1]
|
||||
|
||||
keystates = pygame.key.get_pressed()
|
||||
|
||||
|
||||
while fs != GAME_FS_QUIT:
|
||||
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
fs = GAME_FS_QUIT
|
||||
|
||||
keystates_prev = keystates[:]
|
||||
keystates = pygame.key.get_pressed()[:]
|
||||
|
||||
|
||||
# Etats du jeu
|
||||
|
||||
if fs == GAME_FS_MENU:
|
||||
|
||||
if keystates[pygame.K_ESCAPE] and not keystates_prev[pygame.K_ESCAPE]:
|
||||
fs = GAME_FS_QUIT
|
||||
elif keystates[pygame.K_SPACE] and not keystates_prev[pygame.K_SPACE]:
|
||||
StartPlaying(True)
|
||||
lscore = 0
|
||||
rscore = 0
|
||||
|
||||
if joy1.getFire1() or joy2.getFire1():
|
||||
StartPlaying(False)
|
||||
lscore =0
|
||||
rscore = 0
|
||||
|
||||
|
||||
|
||||
elif fs == GAME_FS_PLAY:
|
||||
|
||||
if keystates[pygame.K_ESCAPE] and not keystates_prev[pygame.K_ESCAPE]:
|
||||
fs = GAME_FS_MENU
|
||||
|
||||
'''
|
||||
if Nbpads > 0:
|
||||
print "pad 1 :", joy1.getUp(), joy1.getDown(), joy1.getLeftTrigger(),joy1.getRightTrigger()
|
||||
print "pad 2 :", joy2.getUp(), joy2.getDown(), joy2.getLeftTrigger(),joy2.getRightTrigger()
|
||||
'''
|
||||
|
||||
# Lost ball / first to ten points ?
|
||||
#print " ball : " , x, y, " left : ", ly, " right : ", ry
|
||||
|
||||
if x < FLIPS_lorigin[0] + PADDLE_width:
|
||||
|
||||
print ("ball.y : ", y, " ly : ", ly)
|
||||
if y > (ly + PADDLE_height + 1) or y < (ly - BALL_SIZE_Y - 1):
|
||||
rscore += 1
|
||||
xvel = random.uniform(-1,-0.6)
|
||||
if rscore == 11:
|
||||
fs = GAME_FS_MENU
|
||||
else:
|
||||
fs = GAME_FS_LAUNCH
|
||||
else:
|
||||
x = FLIPS_lorigin[0] + PADDLE_width
|
||||
xvel *= -1
|
||||
|
||||
|
||||
if x > FLIPS_rorigin[0] - PADDLE_width:
|
||||
|
||||
print ("ball.y : ", y, " ry : ", ry)
|
||||
|
||||
if y < (ry - BALL_SIZE_Y - 1) or y > (ry + PADDLE_height + 1):
|
||||
lscore += 1
|
||||
xvel = random.uniform(1,0.6)
|
||||
if lscore == 11:
|
||||
fs = GAME_FS_MENU
|
||||
else:
|
||||
fs = GAME_FS_LAUNCH
|
||||
else:
|
||||
xvel *= -1
|
||||
x = FLIPS_rorigin[0] - PADDLE_width
|
||||
|
||||
# wall detect
|
||||
|
||||
if y < 0:
|
||||
y = 1
|
||||
yvel *= -1
|
||||
|
||||
if y > screen_size[1]:
|
||||
y = screen_size[1] - 1
|
||||
yvel *= -1
|
||||
|
||||
# Anim
|
||||
|
||||
x += BALL_SPEED * xvel
|
||||
y += BALL_SPEED * yvel
|
||||
yvel += GRAVITY
|
||||
entities.BallMove(x,y)
|
||||
|
||||
if Nbpads > 0:
|
||||
flipsy = entities.FlipsMove(joy1.getUp(),joy1.getDown(),joy2.getUp(),joy2.getDown())
|
||||
|
||||
else:
|
||||
flipsy = entities.FlipsMove(keystates[pygame.K_a],keystates[pygame.K_q],keystates[pygame.K_UP],keystates[pygame.K_DOWN])
|
||||
|
||||
ly = flipsy[0]
|
||||
ry = flipsy[1]
|
||||
|
||||
|
||||
|
||||
elif fs == GAME_FS_LAUNCH:
|
||||
|
||||
'''
|
||||
if Nbpads > 0:
|
||||
print "pad 1 :", joy1.getUp(), joy1.getDown(), joy1.getLeftTrigger(),joy1.getRightTrigger()
|
||||
print "pad 2 :", joy2.getUp(), joy2.getDown(), joy2.getLeftTrigger(),joy2.getRightTrigger()
|
||||
print pad1.get_axis(0),pad2.get_axis(0)
|
||||
'''
|
||||
|
||||
if keystates[pygame.K_ESCAPE] and not keystates_prev[pygame.K_ESCAPE]:
|
||||
fs = GAME_FS_MENU
|
||||
|
||||
if keystates[pygame.K_SPACE] and not keystates_prev[pygame.K_SPACE]:
|
||||
fs = GAME_FS_PLAY
|
||||
yvel = 0
|
||||
while math.fabs(xvel + yvel) < 1:
|
||||
#xvel = random.uniform(-1,1)
|
||||
yvel = random.uniform(-1,1)
|
||||
|
||||
if joy1.getFire1() or joy2.getFire1():
|
||||
fs = GAME_FS_PLAY
|
||||
yvel = 0
|
||||
while math.fabs(xvel + yvel) < 1:
|
||||
#xvel = random.uniform(-1,1)
|
||||
yvel = random.uniform(-1,1)
|
||||
|
||||
x = ball_origin[0]
|
||||
y = ball_origin[1]
|
||||
entities.BallMove(x,y)
|
||||
|
||||
if Nbpads > 0:
|
||||
flipsy = entities.FlipsMove(joy1.getUp(),joy1.getDown(),joy2.getUp(),joy2.getDown())
|
||||
|
||||
else:
|
||||
flipsy = entities.FlipsMove(keystates[pygame.K_a],keystates[pygame.K_q],keystates[pygame.K_UP],keystates[pygame.K_DOWN])
|
||||
ly = flipsy[0]
|
||||
ry = flipsy[1]
|
||||
|
||||
|
||||
|
||||
elif fs == GAME_FS_GAMEOVER:
|
||||
|
||||
#TODO : MODE GAME OVER, autres opérations d'animation
|
||||
# Remarque : on peut supprimer le mode GAME OVER et le gérer dans le mode jeu
|
||||
# si les traitements sont les mêmes
|
||||
'''
|
||||
if keystates[pygame.K_SPACE] and not keystates_prev[pygame.K_SPACE]:
|
||||
StartPlaying(False)
|
||||
'''
|
||||
|
||||
if joy1.getFire1() or joy2.getFire1():
|
||||
StartPlaying(False)
|
||||
|
||||
elif keystates[pygame.K_ESCAPE] and not keystates_prev[pygame.K_ESCAPE]:
|
||||
fs = GAME_FS_MENU
|
||||
# Peut-être aussi réinitialiser l'état dans le mode menu
|
||||
|
||||
|
||||
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)
|
||||
|
||||
if fs == GAME_FS_MENU:
|
||||
|
||||
entities.LogoDraw()
|
||||
lj.DrawPL(0)
|
||||
|
||||
|
||||
# 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()
|
||||
|
||||
76
clients/games/ljpong/vectors.py
Executable file
76
clients/games/ljpong/vectors.py
Executable file
|
|
@ -0,0 +1,76 @@
|
|||
# coding=UTF-8
|
||||
'''
|
||||
Created on 13 nov. 2014
|
||||
|
||||
@author: pclf
|
||||
'''
|
||||
import math
|
||||
|
||||
class Polar2D(object):
|
||||
'''
|
||||
classdocs
|
||||
'''
|
||||
|
||||
|
||||
def __init__(self, r, theta):
|
||||
'''
|
||||
Constructor
|
||||
'''
|
||||
self.r = r
|
||||
self.theta = theta
|
||||
|
||||
def Rotate(self, theta):
|
||||
return Polar2D(self.r, self.theta + theta)
|
||||
|
||||
def RotateSelf(self, theta):
|
||||
self.theta += theta
|
||||
|
||||
def Zoom(self, r):
|
||||
return Polar2D(self.r * r, self.theta)
|
||||
|
||||
def ZoomSelf(self, r):
|
||||
self.r *= r
|
||||
|
||||
def RotateZoom(self, r, theta):
|
||||
return Polar2D(self.r * r, self.theta + theta)
|
||||
|
||||
def RotateZoomSelf(self, r, theta):
|
||||
self.r *= r
|
||||
self.theta += theta
|
||||
|
||||
def ToXY(self):
|
||||
theta_rd = math.radians(self.theta)
|
||||
return Vector2D(self.r * math.sin(theta_rd), - self.r * math.cos(theta_rd))
|
||||
|
||||
class Vector2D(object):
|
||||
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def __add__(self, other):
|
||||
return Vector2D(self.x + other.x, self.y + other.y)
|
||||
|
||||
def __sub__(self, other):
|
||||
return Vector2D(self.x - other.x, self.y - other.y)
|
||||
|
||||
# __iadd__ et __isub__ si nécessaire
|
||||
|
||||
def __mul__(self, k):
|
||||
return Vector2D(self.x * k, self.y * k)
|
||||
|
||||
def __div__(self, k):
|
||||
return Vector2D(self.x / k, self.y / k)
|
||||
|
||||
def ScalarProduct(self, v):
|
||||
return self.x*v.x + self.y*v.y
|
||||
|
||||
def Det(self, v):
|
||||
return self.x*v.y - self.y*v.x
|
||||
|
||||
def MatrixProduct(self, vx, vy):
|
||||
return Vector2D(self.ScalarProduct(vx),self.ScalarProduct(vy))
|
||||
|
||||
def ToTuple(self):
|
||||
return (self.x,self.y)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue