Well, I wrote this for Gleeok, but I'm sure other people might want to make lasers or tripwires or something too, so I thought I'd post it here.
Code:
int DistancePointToLine(int x1,int y1,int x2,int y2,int distx,int disty){
int dx = x2-x1;
if(dx != 0){
int m = (y2-y1)/dx;
int c = y1 - m*x1;
return (Abs(-m*distx + disty - c))/Sqrt(m*m + 1);
}
else return Abs(distx-x1);
}
Pretty self explanitory, the inputs go:
(LineXcoord1,LineYcoord1)(LineXcoord2,LineYcoord2) (PointtomeausretoX,PointtomeasuretoY)
In that order.
Might not look so interesting, but don't be fooled!
Coupled with Screen->Line, it's actually quite fun =P
Code:
ffc script laser{
void run(){
int i;
int x1 = 128; int y1 = 0;
int x2 = 160; int y2 = 168;
while(true){
while(i<256){
Screen->Line(4,x1,y1,i,y2,Rand(120)+1,1,0,0,0,128);
if(DistancePointToLine(x1,y1,i,y2,Link->X+8, Link->Y+8) < 2) Game->PlaySound(36);
i+=2;
Waitframe();
}
while(i>0){
Screen->Line(4,x1,y1,i,y2,Rand(120)+1,1,0,0,0,128);
if(DistancePointToLine(x1,y1,i,y2,Link->X+8, Link->Y+8) < 2) Game->PlaySound(36);
i-=2;
Waitframe();
}
}
}
}
Here's a little example of how you might use it.
At the moment, it only plays a sound effect if Link gets hit.
But imagine what it could do!