Commit e225d8f3 authored by aurel's avatar aurel

ball rotation - python3 port

parent b91d5d93
......@@ -18,15 +18,16 @@
import math
class Ball:
def __init__(self):
self.vector = (1.0,0.0)
self.velocity = 0.5 # per second
self.rotation_velocity = 15 # in degrees per second
self.position = (0.5, 0.5)
self.radius = 0.05
self.codestring = "123"
self.rotation = 0
def doPlayerRebound(self):
self.vector = (-self.vector[0], self.vector[1])
......
......@@ -45,6 +45,12 @@ class GameSim:
vec = (vec[0]*travel, vec[1]*travel)
self.ball.position = (pos[0] + vec[0], pos[1] + vec[1])
# new ball rotation
rot = self.ball.rotation
rot_velocity = self.ball.rotation_velocity
rot_diff = rot_velocity * duration
self.ball.rotation += rot_diff
# do world collisions
self.field.doBallCollisions(self.ball)
......
......@@ -48,8 +48,9 @@ class PongConfig:
# harder game parameters
playerLifes = 3
baseVelocity = 0.23
reboundSpeedUp = 1.03
baseVelocity = 0.28
rotationVelocity = 15 # degrees in seconds
reboundSpeedUp = 1.06
startZoneSize = 0.45
minZoneSize = 0.11
reboundZoneShrink = 0.018
......
#!/usr/bin/python2
#!/usr/bin/python3
##
# Copyright 2014, Aurel Wildfellner.
......@@ -197,6 +197,8 @@ class PongGame:
self.ball.setVector(xdirection, random.random()*3*ydirection)
self.ball.position = self.gamefield.getFieldCenter()
self.ball.velocity = PongConfig.baseVelocity
self.ball.rotation_velocity = PongConfig.rotationVelocity
self.ball.rotation = 0
# setup zones
self.gamefield.leftZoneSize = PongConfig.startZoneSize
......
......@@ -3,13 +3,14 @@ import pyglet
from player import Player
from pongconfig import PongConfig
import math
class Zone():
def __init__(self, gamefield, (ratio, height)):
def __init__(self, gamefield, ratio_height):
self.gamefield = gamefield
self.ratio = ratio
self.height = height
self.ratio, self.height = ratio_height
self.color = (230, 230, 230,
230, 230, 230,
230, 230, 230,
......@@ -20,8 +21,8 @@ class Zone():
class LeftZone(Zone):
def __init__(self, gamefield, (ratio, height)):
Zone.__init__(self, gamefield, (ratio, height))
def __init__(self, gamefield, ratio_height):
Zone.__init__(self, gamefield, ratio_height)
def draw(self):
pyglet.graphics.draw(6, pyglet.gl.GL_TRIANGLES,
......@@ -36,8 +37,8 @@ class LeftZone(Zone):
class RightZone(Zone):
def __init__(self, gamefield, (ratio, height)):
Zone.__init__(self, gamefield, (ratio, height))
def __init__(self, gamefield, ratio_height):
Zone.__init__(self, gamefield, ratio_height)
def draw(self):
pyglet.graphics.draw(6, pyglet.gl.GL_TRIANGLES,
......@@ -66,10 +67,17 @@ class BallView():
#self.ball = BallView(ball, self.ratio, self.ball_image)
self.sprite = pyglet.sprite.Sprite(img=self.image)
self.sprite.scale = (self.size[0] / float(self.sprite.width))
self.sprite.image.anchor_x = self.sprite.image.width / 2.
self.sprite.image.anchor_y = self.sprite.image.height / 2.
def update(self):
self.sprite.x = (self.model.position[0] - self.model.radius) * self.ratio
self.sprite.y = (self.model.position[1] - self.model.radius) * self.ratio
x = (self.model.position[0] - self.model.radius) * self.ratio
y = (self.model.position[1] - self.model.radius) * self.ratio
#self.sprite.x = x + ((math.sin(math.radians(self.model.rotation) ) * self.model.radius) * self.ratio)
self.sprite.x = x + self.sprite.image.width / 3.
#self.sprite.y = y + (((math.sin(math.radians(self.model.rotation)) / 2. ) * self.model.radius) * self.ratio)
self.sprite.y = y + self.sprite.image.height / 3.
self.sprite.rotation = self.model.rotation
def draw(self):
self.sprite.draw()
......@@ -89,9 +97,8 @@ class Jumbo():
class PlayerCode1():
def __init__(self, (ratio, height)):
self.ratio = ratio
self.height = height
def __init__(self, ratio_height):
self.ratio, self.height = ratio_height
self.ready = False
self.image = pyglet.image.load('../img/101_272.png')
self.size = (
......@@ -115,9 +122,8 @@ class PlayerCode1():
class PlayerCode2():
def __init__(self, (ratio, height)):
self.ratio = ratio
self.height = height
def __init__(self, ratio_height):
self.ratio, self.height = ratio_height
self.ready = False
self.image = pyglet.image.load('../img/102_272.png')
self.size = (
......@@ -142,9 +148,8 @@ class PlayerCode2():
class Heart():
def __init__(self, (ratio, height), side, i):
self.ratio = ratio
self.height = height
def __init__(self, ratio_height, side, i):
self.ratio, self.height = ratio_height
self.image = pyglet.image.load('../img/heart.png')
self.sprite = pyglet.sprite.Sprite(img=self.image)
self.sprite.y = self.height - self.image.height - 10
......
......@@ -21,17 +21,17 @@ import os
def getBarcodeIds():
vocabular = ["Barcode", "Datalogic", "DataLogic"]
vocabular = [b"Barcode", b"Datalogic", b"DataLogic"]
ids = []
out = subprocess.check_output("xinput")
lines = out.split("\n")
lines = out.split(b"\n")
# parse xinput output
for line in lines:
if any(voc in line for voc in vocabular):
# get the number after id=
s = line.split("id=")[1]
sid = s.split("\t")[0]
s = line.split(b"id=")[1]
sid = s.split(b"\t")[0]
try:
iid = int(sid)
ids.append(iid)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment