Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualArs7c3

Posted 14 August 2012 - 07:33 PM

I actually did include that in my code... for some reason it didn't upload that way. Here is the real code i use to detect collision.
[source lang="cpp"]bool Collision(SDL_Rect A, SDL_Rect B){ //The sides of the rectangles 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 any of the sides from A are outside of B if( bottomA <= topB ) { return false; } else if( topA >= bottomB ) { return false; } else if( rightA <= leftB ) { return false; } else if( leftA >= rightB ) { return false; } //If none of the sides from A are outside B else return true;}[/source]

#1Ars7c3

Posted 14 August 2012 - 07:33 PM

I actually did include that in my code... for some reason it didn't upload that way. Here is the real code i use to detect collision.
[source lang="cpp"]bool Collision(SDL_Rect A, SDL_Rect B){ //The sides of the rectangles 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 any of the sides from A are outside of B if( bottomA <= topB ) { return false; } else if( topA >= bottomB ) { return false; } else if( rightA <= leftB ) { return false; } else if( leftA >= rightB ) { return false; } //If none of the sides from A are outside B else return true;}[/source]

PARTNERS