Sign in to follow this  
Sckuz

Hit detection problem

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
[ 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[i]-sin(wallRot[i]),
wallY[i]-cos(wallRot[i]),
wallX[i]+sin(wallRot[i]),
wallY[i]+cos(wallRot[i])))

{
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

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