Problems with translating player to center at screen

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

Player Movement:

    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:

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() ```
1 Like

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

Use separate functions to check if different moves are valid?