A square tile collides with another square tile. The bartender says...
I have:
Assuming you have a way to detect collisions, understanding which sides collided is straight forward. You simply need to examine the x
and y
positions of each square.
Square1 : (x1, y1)
Square2 : (x2, y2)
I'll work from the assumption that the top left corner of your work area is (0,0)
and that x
values increase as you move right, and y
values increase as you move down.
With this in mind:
If (x1 < x2), the right side of square 1 collided with the left side of square 2
If (x1 > x2), the left side of square 1 collided with the right side of square 2
if (y1 < y2), the bottom side of square 1 collided with the top side of square 2
if (y1 > y2), the top side of square 1 collided with the bottom side of square 2
I suggest you draw yourself a few pictures, and it should become clear to you.