Mail Archives: djgpp/1998/12/25/19:19:08
Ouch! My Brain Hurts!
>Hello sickness (Sorry, just a *sick* joke :)
>To calculate the distance between two points in 2D-space, you use the
>pythagorean theorem. I give you some code from X-type:
>
>int get_distance(int x1, int y1, int x2, int y2)
> {
> return(sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
> }
>
>This function returns the distance between x1,y1 and x2,y2...
>
> short int gox,goy,speed;
> float del;
>
> del=speed/sqrt((x-gx)*(x-gx)+(y-gy)*(y-gy));
> gox=-((float)((float)x-(float)gx)*del);
> goy=-((float)((float)y-(float)gy)*del);
>
> ...and this piece o' code returns the path for a bullet or something like
>that. Set the speedvariable to pixels it will move every time. Every time
>you want to move it, do x+=gox and y+=goy. Well good night as we say here
>00:12.
>
>
- Raw text -