Mail Archives: djgpp/1998/12/26/18:16:45
Mad Cow wrote:
>
> humm..I'm a novice djgpp'er, and need some help on somethin'
>
> i want to make a StarMap, uh, like so--
>
> 1 2 3 4 5 6 7 8 9 0
> A * * * * * * * * * *
> B * * * * * * * * * *
> C * * # * * * * * * *
> D * * * * * * * * * *
> E * * * * * * * * * *
> F * * * * * * * * * *
> G * * * * * * * * * *
> H * * * * * * # * * *
> I * * * * * * * * * *
> J * * * * * * * * * *
>
> This is a game i want to make, i want to have it so that ppl can
> move a ship from
> say C3 to H7 but, how do i make a thing to calculate distance, and
> maybe even a path?
> say the distance would be 5, and the path would be C3-D4-E5-F6-G7-H7, so,
> please help
> on this one..all help is deeply apreciated..
The distance between two points in a plane is `sqrt(x^2+y^2)', so
#define SQ(x) ((x) * (x))
double distance(double x1, double y1, double x2, double y2)
{
return sqrt(SQ(x1-x2) + SQ(y1-y2));
}
and round to int as appropriate.
To determine the path, you want a line drawing algorithm. Breshenham's
algorithm (sp?) is the best known; search for it. You could also look
at the sources of a graphics library like Allegro and see how it's
done. You just have grid squares instead of pixels.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -