Collision Detection: Difference between revisions

From LD Smith Games Workshop
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Below is the algorithm that I used for collision detection in the Legend of Tux.  It may not be perfect, but it seems to get the job done.  Cases 2, 5, 7, and 8 are needed because not all objects are the same size.  Originally, I didn't have cases 7 and 8 coded, and it was possible for the player to walk horizontally through an enemy, when the top and bottom of the player's bounding box were above and below (respectively) the bounding box of the enemy.
I have updated the collision detection code, after looking at the example code from this site: http://gpwiki.org/index.php/C:Collision_Detection_between_2_SDL_Surfaces
 
 
 
Below is the algorithm that I used for collision detection in the Legend of Tux.  It may not be perfect, but it seems to get the job done.  Cases 2, 5, 7, and 8 are needed because not all objects are the same size.  Originally, I didn't have cases 7 and 8 coded, and it was possible for the player to walk horizontally through an enemy without getting hit, when the top and bottom of the player's bounding box were above and below (respectively) the bounding box of the enemy.


[[File:Lotux collision01.jpg]]
[[File:Lotux collision01.jpg]]

Latest revision as of 07:48, 4 February 2010

I have updated the collision detection code, after looking at the example code from this site: http://gpwiki.org/index.php/C:Collision_Detection_between_2_SDL_Surfaces


Below is the algorithm that I used for collision detection in the Legend of Tux. It may not be perfect, but it seems to get the job done. Cases 2, 5, 7, and 8 are needed because not all objects are the same size. Originally, I didn't have cases 7 and 8 coded, and it was possible for the player to walk horizontally through an enemy without getting hit, when the top and bottom of the player's bounding box were above and below (respectively) the bounding box of the enemy.

Lotux collision01.jpg

Lotux collision02.jpg

Lotux collision03.jpg

Lotux collision04.jpg

Lotux collision05.jpg