Hit detection problem

Started by
2 comments, last by Zakwayda 13 years, 6 months ago
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)
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?
[ 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;
}
}

}
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.

This topic is closed to new replies.

Advertisement