Trying to figure out a way to allow my image to move in opposite direction when colliding with object
<p>A bit long, but I am not looking for a copy and paste answer. I just want to know a good way on how to approach this. Code pasted for visual preference.</p>

<p>In better terms. My image is colliding with another image, this object is representing the tile (floor/roof/wall/etc).</p>

<p>I place these tiles in different locations throughout my screen. I store these positions using rect objects and storing them into a list known as <code>terrain</code>.
So I iterate through my list and when I encounter a collision with my hero and some terrain object, stop movement.</p>

<p>I now realize that this is a problem. When this happens and I do collide, I can no longer move my object, it is stuck.</p>

<p>So how can I get my object to still move around, BUT when it has collided with some object. It is not allowed to continue to move further in that same direction.</p>

<p>Here are is the main piece for movement controlling:</p>

<p>The <code>moveDown</code> statement is the part where I try to implement it.<br>
<code>floorCollusion</code> is a list of 5 False booleans.</p>

<pre><code>#0 represents - no collision
#1 "       "  - top face has collided
#2 "       "  - right face has collided
#3 "       "  - bottom face has collided
#4 "       "  - left face has collided
</code></pre>

<p>I see I have binary operations. Either I move or I don't. I just can't figure another way to implement this.</p>

<p>You don't need to add on to the code. A basic idea on how to see this would be appreciated.</p>

<pre><code>moveDown  = False
moveUp    = False
moveLeft  = False
moveRight = False
#when key down either move the hero or quit game
        elif event.type == KEYDOWN:
            if event.key in (K_UP, K_w):
                moveDown = False
                moveUp = True
        playerObj['jumping'] = True #@@@@@@

    elif event.key in (K_DOWN,K_s):
       moveUp = False
       moveDown = True

            elif event.key in (K_LEFT, K_a):
                moveRight = False
                moveLeft = True

        #if the image is not facing left, display the left img
        if (playerObj['facing']) != LEFT:
        playerObj['surface'] = L_HERO_IMG
        playerObj['facing'] = LEFT

    elif event.key in (K_RIGHT, K_d):
        moveLeft = False
        moveRight = True

        #if the image is not facing right, display the right img
        if (playerObj['facing']) != RIGHT:
        playerObj['surface'] = R_HERO_IMG
        playerObj['facing'] = RIGHT

            elif event.key == K_ESCAPE:
                terminate()

    #testing hit point system
    elif event.key == K_SPACE:
        playerObj['health'] -= 3

        if playerObj['health'] &lt;= 0:
        gameOver = True

    #when key is lifted stop movement
    elif event.type == KEYUP:
    if event.key in (K_UP, K_w):
       moveUp = False

    elif event.key in (K_DOWN, K_s):
       moveDown = False

    elif event.key in (K_LEFT,K_a):
       moveLeft = False

    elif event.key in (K_RIGHT,K_d):
       moveRight = False

#moving the hero
if not gameOver:

        if moveLeft:
    playerObj['x'] -= MOVERATE

        if moveRight:
    playerObj['x'] += MOVERATE

    #if the player pressed key up or 'w' and hero isn't jump
    #the hero will seems to have a jumping affect
        if moveUp:
    playerObj['y'] -= MOVERATE
        if moveDown:
    playerObj['y'] += MOVERATE
    for i in range(len(terrain)):
        tile = terrain[i]
        if playerObj['rect'].colliderect(tile):
           floorCollusion[2] = True
           break
        else:
           floorCollusion[2] = False
    if floorCollusion[2]:
        playerObj['x'] -= MOVERATE
</code></pre>
