I've been trying to write some collision detection code in C, below is the function i have at the moment, its called every frame however for some reason when the 2 sprites overlap the collision doesn't work
short int Collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
{
int left1, left2;
int right1, right2;
int top1, top2;
int bottom1, bottom2;
left1 = x1;
left2 = x2;
right1 = x1 + w1;
right2 = x2 + w2;
top1 = y1;
top2 = y2;
bottom1 = y1 + h1;
bottom2 = y2 + h2;
if ((bottom1 < top2)||(top1 > bottom2)||(right1 < left2)||(left1 > right2))
{
return(1);
}
else
{
return(0);
}
};
if (Collision ==1)
{
//code for collision here
}
Any pointers in the right direction would be greatly appreciated