Original Post
Hello I've been wondering for about a day now how to do Collision checking in SDL I tried lazy foo tutorial but got an idea of it but I still don't understand how to make it work so if anyone could give me coding hand here is my code tell me if I'm doing something wrong here
This should work I would have thought but it doesn't move the MarioRect image anywhere it just carrys on its original movement : (
any tips or helps would be nice thanks
//Check Collision Function
bool Check_Collision(SDL_Rect A, SDL_Rect B)
{
//the sides of the rectangle
int leftA, leftB;
int rightA, rightB;
int topA, topB;
int bottomA, bottomB;
//calculate the sides of rect a
leftA = A.x;
rightA = A.x + A.w;
topA = A.y;
bottomA = A.y +A.h;
//Calculate the sides of Rect b
leftB = B.x;
rightB = B.x + B.w;
topB = B.y;
bottomB = B.y + B.h;
if( bottomA <= topB)
{
return false;
}
if( topA >= bottomB)
{
return false;
}
if( rightA <= leftB)
{
return false;
}
if(leftA >= rightB)
{
return false;
}
return true;
}
while(Check_Collision(MarioRect,GroundOneRect))
{
MarioRect.y -= 7;
}
This should work I would have thought but it doesn't move the MarioRect image anywhere it just carrys on its original movement : (
any tips or helps would be nice thanks
|
