# Player movement laggy

**URL:** <https://discourse.processing.org/t/player-movement-laggy/7366>\
**Category:** Processing.py\
**Created:** [January 9, 2019, 6:29pm UTC](https://discourse.processing.org/t/player-movement-laggy/7366 "2019-01-09T18:29:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 9, 2019, 7:27pm UTC](https://discourse.processing.org/t/player-movement-laggy/7366/2 "2019-01-09T19:27:35Z")

</div>

Inspired by my old Java Mode “Player Move”: ☕  
[Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp](http://Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp)

I’ve made a Python Mode version “Paddle Move”:🐍

```python
"""
 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

```

---

_[View the full topic](https://discourse.processing.org/t/player-movement-laggy/7366)._
