Searching for a pre-made function in SGDK I found out (in math.c) one which seems to do what I need... distance_approx() but this method only needs two parameters... so I'm not able to underestand how this method works.

(probably this method it isn't suitable for my purpose)

Code: Select all

```
u32 distance_approx(s32 dx, s32 dy)
{
u32 min, max;
if (dx < 0) dx = -dx;
if (dy < 0) dy = -dy;
if (dx < dy )
{
min = dx;
max = dy;
}
else
{
min = dy;
max = dx;
}
// coefficients equivalent to ( 123/128 * max ) and ( 51/128 * min )
return ((max « 8) + (max « 3) - (max « 4) - (max « 1) +
(min « 7) - (min « 5) + (min « 3) - (min « 1)) » 8;
}
```