Sign in to follow this  

2d collistion detection

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Check the X value of the ball to the inner X value of the paddles, then check to see if the Y value is within the location of the paddle. Its not the prettiest method but its about the simplest i can think of

Share this post


Link to post
Share on other sites
see im having some problems witht that maybe imy just not updating the ball position correctly but that method is giving me some problems how would i store the location of the ball (in terms of the window) becuase i would need to store this in a variable to do the check

Share this post


Link to post
Share on other sites
This is how i did mine.

But like the previous poster said use a struct\class, and yeah im pretty sure this aint the best way to do it.

bool DDraw::CheckCollision(int iSprite1,int iSprite2)
{

bool foundX;

//for each X pixel of sprite 2
for (int iX=DDsprite[iSprite2].posX;iX<DDsprite[iSprite2].width;iX++)
{
//loop through all X pixels of sprite 1 and compare
for (int i=DDsprite[iSprite1].posX;i<DDsprite[iSprite1].width;i++)
{
//if match found
if (i == iX)
{
foundX = true;
}
}
}


if (foundX)
{
//for each Y pixel of sprite 2
for (int iY=DDsprite[iSprite2].posY;iY<DDsprite[iSprite2].height;iY++)
{
//loop through all Y pixels of sprite 1 for match
for (int k=DDsprite[iSprite1].posY;k<DDsprite[iSprite1].height;k++)
{
//if match found
if (k == iY)
{
//sprites have collided
return true;
}
}
}
}

return false;
}


[EDIT] i find it a bit strange for a board of this caliber that focuses mostly on code not to have a CODE block option right on the post screen.

[Edited by - jsloan on September 12, 2004 2:18:26 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by jsloan
[EDIT] i find it a bit strange for a board of this caliber that focuses mostly on code not to have a CODE block option right on the post screen.


Good point. Anyway use [source] // code to be formated goes here [/source] or [code] // short snippets go here [/code] tags to accomplish that task.

Share this post


Link to post
Share on other sites

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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