Inspired by my old Java Mode “Player Move”:
Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp
I’ve made a Python Mode version “Paddle Move”:
"""
Paddle Move (v1.0.2)
by GoToLoop (2019-Jan-09)
https://Discourse.Processing.org/t/player-movement-laggy/7366/2
http://Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp
"""
BG = 0350
def setup():
size(800, 600)
colorMode(RGB)
rectMode(CORNER)
fill(Paddle.INK)
stroke(Paddle.OUTLINE)
strokeWeight(Paddle.BOLD)
global p
p = Paddle()
print p
def draw():
background(BG)
p.move().display()
def keyPressed():
p.control(chr(keyCode) if key != CODED else keyCode, True)
def keyReleased():
p.control(chr(keyCode) if key != CODED else keyCode, False)
class Paddle:
W, H, V, O = 40, 10, 10, 5
INK, OUTLINE, BOLD = 0xff008000, 0, 1.5
def __init__(p):
p.x = width - p.W >> 1
p.y = height - p.H - p.O
p.l = p.r = False
def __str__(p, INFO='{ x: %d, y: %d }'):
return INFO % (p.x, p.y)
def display(p):
rect(p.x, p.y, p.W, p.H)
return p
def move(p):
p.x = constrain(p.x + p.V*(p.r - p.l), 0, width - p.W)
return p
def control(p, k, b):
if k == LEFT or k == 'A' or k == 'Z': p.l = b
elif k == RIGHT or k == 'D' or k == 'X': p.r = b
return p