Hello,
I am Brian Washechek, a 28 year old student at Casper College. Please look at this game! It's Force Disruptor 2, a sequel to a game i wrote a long, long time ago (i'm thinking like 7 years). I'll keep on attempting to write code for this if you would take a look at it! Basicly 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 a long time ago. Seriously, Thank you for the help
Code:
bool intersectionOfLines(double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4,
double *x,
double *y)
{
double Ax,Bx,Cx,Ay,By,Cy,d,e,f,num,offset;
short x1lo,x1hi,y1lo,y1hi;
Ax = x2-x1;
Bx = x3-x4;
if(Ax<0) {
x1lo=(short)x2; x1hi=(short)x1;
} else {
x1hi=(short)x2; x1lo=(short)x1;
}
if(Bx>0) {
if(x1hi < (short)x4 || (short)x3 < x1lo) return false;
} else {
if(x1hi < (short)x3 || (short)x4 < x1lo) return false;
}
Ay = y2-y1;
By = y3-y4;
if(Ay<0) {
y1lo=(short)y2; y1hi=(short)y1;
} else {
y1hi=(short)y2; y1lo=(short)y1;
}
if(By>0) {
if(y1hi < (short)y4 || (short)y3 < y1lo) return false;
} else {
if(y1hi < (short)y3 || (short)y4 < y1lo) return false;
}
Cx = x1-x3;
Cy = y1-y3;
d = By*Cx - Bx*Cy;
f = Ay*Bx - Ax*By;
if(f>0) {
if(d<0 || d>f) return false;
} else {
if(d>0 || d<f) return false;
}
e = Ax*Cy - Ay*Cx;
if(f>0) {
if(e<0 || e>f) return false;
} else {
if(e>0 || e<f) return false;
}
//compute intersection coordinates
if(f==0) return false;
num = d*Ax;
offset = SAME_SIGNS(num,f) ? f/2 : -f/2;
*x = x1 + (num+offset) / f;
num = d*Ay;
offset = SAME_SIGNS(num,f) ? f/2 : -f/2;
*y = y1 + (num+offset) / f;
return true;
}
//....................later in the c++ file...................................
if (intersectionOfLines(
FDX-cos(FDA)+0,
FDY-sin(FDA)+9,
FDX+cos(FDA)+1,
FDY+sin(FDA)+.8,
wallX[i]-cos(wallRot[i])*wallRot[i],
wallY[i]-sin(wallRot[i])*wallRot[i],
wallX[i]-cos(wallRot[i])*wallRot[i],
wallY[i]-sin(wallRot[i])*wallRot[i],
&FDX,&FDY))
{
bigX = true;
// A collision occured, but for now it gets a BIG X...
}