# Problems with translating player to center at screen

**URL:** <https://discourse.processing.org/t/problems-with-translating-player-to-center-at-screen/18230>\
**Category:** Processing.py\
**Created:** [February 28, 2020, 11:19pm UTC](https://discourse.processing.org/t/problems-with-translating-player-to-center-at-screen/18230 "2020-02-28T23:19:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joloporto](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@joloporto](https://discourse.processing.org/u/joloporto)\
**Post date:** [February 28, 2020, 11:19pm UTC](https://discourse.processing.org/t/problems-with-translating-player-to-center-at-screen/18230/1 "2020-02-28T23:19:26Z")

</div>

i am working on a program with the player translated to the center of screen and the background moving around the player. I have working collision detection- when the player hits any of the blocks on the screen, it stops. For example, when the player hits a block while going up, its only choice is to go down. But I would like that the player be able to go left and right.

(self-explanatory) Link: [https://pythonmini.app.oyoclass.com/file/5e597e9e0375bb0f7acc0b36](https://pythonmini.app.oyoclass.com/file/5e597e9e0375bb0f7acc0b36)

Player Movement:

```auto
    if kDict[87]:
        cMove = True
        
        for wall in wList:
            if player.cor.x + player.radius / 2 >= wall.cor.x and player.cor.x - player.radius / 2 <= wall.cor.x + wall.radius and player.cor.y - player.radius / 2 >= wall.cor.y and player.cor.y - player.radius / 2 <= wall.cor.y + wall.radius:
                cMove = False
            
        if cMove:
            player.cor.y -= 5

    if kDict[83]:
        cMove = True
        
        for wall in wList:
            if player.cor.x + player.radius / 2 >= wall.cor.x and player.cor.x - player.radius / 2 <= wall.cor.x + wall.radius and player.cor.y + player.radius / 2 <= wall.cor.y and player.cor.y + player.radius / 2 >= wall.cor.y:
                cMove = False
                
        if cMove:
            player.cor.y += 5

    if kDict[65]:
        cMove = True
        
        for wall in wList:
            if player.cor.x - player.radius / 2 <= wall.cor.x + wall.radius and player.cor.x - player.radius / 2 >= wall.cor.x and ((player.cor.y + player.radius / 2 <= wall.cor.y and player.cor.y + player.radius / 2 >= wall.cor.y) or (player.cor.y + player.radius / 2 >= wall.cor.y and player.cor.y - player.radius / 2 <= wall.cor.y + wall.radius)): #player.cor.y + player.radius <= wall.cor.y and player.cor.y >= wall.cor.y - wall.radius:
                cMove = False
                
        if cMove:
            player.cor.x -= 5

    if kDict[68]:
        cMove = True
        
        for wall in wList:
            if player.cor.x + player.radius / 2 >= wall.cor.x and player.cor.x + player.radius / 2 <= wall.cor.x and ((player.cor.y + player.radius / 2 <= wall.cor.y and player.cor.y + player.radius / 2 >= wall.cor.y) or (player.cor.y + player.radius / 2 >= wall.cor.y and player.cor.y - player.radius / 2 <= wall.cor.y + wall.radius)): #and ((player.cor.y >= wall.cor.y - wall.radius and player.cor.y <= wall.cor.y + wall.radius) and (player.cor.y <= wall.cor.y + wall.radius and player.cor.y >= wall.cor.y)):
                cMove = False
                
        if cMove:
            player.cor.x += 5

```

Player Class:

````auto
class Player(object):
    def __init__ (self, x, y, radius, colList):
        self.cor = PVector(x, y)
        self.radius = radius
        self.colList = colList
        self.radians = 0
        
    def drawPlayer(self):
        fill(self.colList[0], self.colList[1], self.colList[2])
        strokeWeight(5); stroke(0)
        pushMatrix()
        translate(width / 2, height / 2)
        self.radians = atan2(mouseY - height / 2, mouseX - width / 2)
        rotate(self.radians + pi / 2)
        rect(-self.radius / 2, -self.radius / 2, self.radius, self.radius)
        popMatrix() ```
````

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [February 29, 2020, 8:47am UTC](https://discourse.processing.org/t/problems-with-translating-player-to-center-at-screen/18230/2 "2020-02-29T08:47:02Z")

</div>

What if you used four different `cMove` variables? A `cMoveUp`, `cMoveDown`, `cMoveRight`, `cMoveLeft`.

---

<div class="post-metadata">

**Author:** ![commie630](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@commie630](https://discourse.processing.org/u/commie630)\
**Post date:** [February 29, 2020, 9:36pm UTC](https://discourse.processing.org/t/problems-with-translating-player-to-center-at-screen/18230/3 "2020-02-29T21:36:23Z")

</div>

Use separate functions to check if different moves are valid?
