I'm writing a top down 2d XNA game. Since its my first I'm trying to write the physics and collision stuff myself to learn it.
Whenever my player sprite character attempts to move into a position where its bounds intersect with the edge of a wall, I figure out a bounce angle (angle of incidence = angle of reflection) and I make the player bounce off the wall and avoid the collision.
I'm having trouble figuring out how to deal with the situation of my sprite intersecting with two wall edges simultaneously though e.g. it hits a corner.
My code currently tells me that two wall edges have been intersected but not which edge it would have hit first and therefore which edge to bounce off.
What is the mathematical test to pick which edge to bounce off? It's plain to see when looking at it but I'm struggling to figure out the math test for it.