sprite collision detection

Started by
4 comments, last by phil67rpg 13 years, 6 months ago
I am trying to use the following code for sprite based collision detection.
//bounding  box collision detectionint Collision(SPRITE sprite1, SPRITE sprite2){    RECT rect1;    rect1.left = sprite1.x;    rect1.top = sprite1.y;	rect1.right = sprite1.x + sprite1.width;	rect1.bottom = sprite1.y + sprite1.height;    RECT rect2;    rect2.left = sprite2.x;    rect2.top = sprite2.y;	rect2.right = sprite2.x + sprite2.width;	rect2.bottom = sprite2.y + sprite2.height;    RECT dest;    return IntersectRect(&dest, &rect1, &rect2);}

what does "SPRITE sprite1" refer to , a struct??
Advertisement
That would be the logical thing to assume, the function takes two objects "sprite1" and "sprite2" of the class or struct type SPRITE.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
my next question is how would I use this code.
Paste that function somewhere in your code, I like to use header files, but you could just put it right above int main(). (If using C++)

Then, call it using Collision(Sprite 1, Sprite 2).

Its gonna returns some info, not exactly sure what, since you didn't post the IntersectRect() function.
well here is some code for collision detection using two rectangles as bounding boxes.
sorry here is the code
if(rect1.right>=rect2.left||rect1.left<=rect2.right)
//collision
else if (rect1.bottom>=rect2.top||rect2.bottom>=rect1.top)
//collsion

This topic is closed to new replies.

Advertisement