Bounding box collision detection
Code:
bool CCollisionDetection::DetectBoundingBox(const CSprite &spriteOne, const CSprite &spriteTwo)
{
//
//Grab the bounds of the sprites
//
const BoundingBox &boundOne = spriteOne.Bounds();
const BoundingBox &boundTwo = spriteTwo.Bounds();
//if the left is greater than the right no collison
if(boundOne.left > boundTwo.right){
return false;
}//if
//if the right is less than the left no collision
if(boundOne.right < boundTwo.left){
return false;
}//if
//if the bottom is less than the top no collision
if(boundOne.bottom < boundTwo.top){
return false;
}//if
//if the top is greater than the bottom no collision
if(boundOne.top > boundTwo.bottom){
return false;
}//if
//if all the checks failed that means they are colliding
return true;
}
BoundingBox is just a simple struct defined as:
Code:
struct BoundingBox
{
int top;
int bottom;
int left;
int right;
};