Jump to content
  • Advertisement
Sign in to follow this  
Sckuz

Hit detection problem

This topic is 2851 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

Hello,

I am Brian Washechek, a 28 year old student at Casper College. Please look at this game! It's called Force Disruptor 2, a sequel to a game i wrote a long, long time ago (I'm thinking like 7 years). Something is "odd" about the hit detection for the walls. By "odd", i mean i can't get it to work! At all. Well, I'll keep on attempting to write code for this if you would take a look at it! basically the walls only display(no hit detection) and i can't get it right! This is a sequel to Force Disruptor (the original), that got lost along time ago. Seriously, Thank you for the help (If you'll offer it, that is)


http://paste-it.net/public/ta045a0/

Brian Gregory Washechek the second(2nd)

Share this post


Link to post
Share on other sites
Advertisement
Could you please only show us relevant code instead of a several page program?
Paste the code in [ source ] tags.

I'm assuming the game is 2D, correct?

Share this post


Link to post
Share on other sites
[ source ]
bool lineSegmentIntersection(
double x1,double y1,
double x2,double y2,
double x3,double y3,
double x4,double y4)
{
double d = (x1-x2)*(y3-y4) - (y1-y2)*(x3-x4);

if (d == 0)
return false;

double xi = ((x3-x4)*(x1*y2-y1*x2)-(x1-x2)*(x3*y4-y3*x4))/d;
double yi = ((y3-y4)*(x1*y2-y1*x2)-(y1-y2)*(x3*y4-y3*x4))/d;
if(x3==x4) {
if ( yi < min(y1,y2) || yi > max(y1,y2) )
return false; }
if (xi < min(x1,x2) || xi > max(x1,x2))
return false;
if (xi < min(x3,x4) || xi > max(x3,x4))
return false;
return true;
}

//..................................................
//................bigX puts a bigx..................
//.................on the screen....................
//..................................................
void fixCollisions()
{
bigX=false;
for (int i =0;i<wallUbound;i++)
{

if(lineSegmentIntersection(FDX,FDY+9, FDX+1,FDY+.8,
wallX-sin(wallRot),
wallY-cos(wallRot),
wallX+sin(wallRot),
wallY+cos(wallRot)))

{
bigX=true;
}
}

}

Share this post


Link to post
Share on other sites
zyrolasting added spaces to the tag because it's easier to write that way in a post. But, it should actually be [source]. Also, make sure you close the tag as well, i.e. by adding [/source] at the end of your code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!