Hi there. I'm attempting to implement "sliding collision"--collision where, if you hold down and right while colliding with a wall to the right, you'll stop moving right, but will continue moving (or "sliding") down. This kind of collision is seen in many top-down 2D games (like A Link to the Past and other Zelda games). I'm not sure what this type of collision is actually called, but I'm going with "sliding collision" for now.

The yellow square is the player, moving down and to the right. The player then collides with a solid wall (the red square). While colliding, down and right are still being held, but collision is cancelled on the right, and movement continues downward. Finally, when the player is below the red wall, movement down and to the right resumes as expected.

Here's what I have already working with a single player and a single wall (the colors and outlines are different in the game than in the above visualization):

I made the wall variables an array. Drawing works no problem, but collision doesn't work as expected. I limited the number of walls to just 1, to test it against my earlier code, but now the player collides with a wall and just becomes "stuck"; it doesn't "slide" like I expected. What am I doing wrong?

I haven't done collision like this before, so I'm surely making mistakes, but I appreciate any and all feedback and suggestions. Thank you!

EditI figured it out. I moved the for loop within each of the if statements, and now it works: