Simple collision in Allegro

Okay so I'm a beginner to allegro and I this it real quick to try to figure out how to make a platformer. I'm having trouble with collision. I know how to detect a collision with a bounding box but can't figure out how to do something with it. sx is the box I'm trying to collide with. I tried a lot of different things but can't figure out how to do it. Colliding with the left and right side work fine, but colliding with the top and bottom of the box is what I'm having trouble with. Also, player.x and player.y are the center of the player. sx and sy are the top right corner of the other box.

1
2
3
4
5
6
7
8
9
10
11
12
if (player.x + player.boundX > sx &&
	player.x - player.boundX < sx + 20 &&
	player.y + player.boundY > sy &&
	player.y - player.boundX < sy + 20) {
		if (player.x + player.boundX > sx + 10)
			player.x = sx + 20 + player.boundX;
		else if (player.x - player.boundX < sx + 10)
			player.y = sy + 20 + player.boundY;
		else if (player.y + player.boundY > sy)
			player.y = sy - player.boundY;
}
}
Topic archived. No new replies allowed.