However, it's not so fast to calculate, because of that square root. However, if we treat the movement as a diagonal movement of length equal to Min(Abs(DisX2 - DisX1), Abs(DisY2 - DisY1)), we can do the following (Psuedocode):
Distance(x1, y1, x2, y2) { r = 0.0; axD = Abs(x2 - x1); ayD = Abs(y2 - y1); dD = Min(axD, ayD); r += dD * 1.4142135623730950488016887242097; r += (axD - dD) + (ayD - dD); return r; }
It relies on the simple fact that, for any 2D vector, you can subtract a (0, infinity] length, 45 degree diagonal vector from it and end up with either a vertical, horizontal or zeroed vector.
This might already be known, but I've never seen it anywhere, so I'm posting it here.
Edit: ...I think my math is bad. It works well enough for A*, though.