Sign in to follow this  
phil67rpg

sprite collision detection

Recommended Posts

phil67rpg    443
I am trying to use the following code for sprite based collision detection.

//bounding box collision detection
int 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??

Share this post


Link to post
Share on other sites
AdrianC    602
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this