I am making a game where you have units on a grid and can move them around. Presuming a unit is at green and they want to move to pink, how can I see that pink is only 4 tiles away? As a point of reference, 0,0 is black, and 4,4 is white. Red is the path, how can I tell they have only crossed 4 tiles? Green is 0,2 and Pink is 2,0 if you add the difference of those numbers you get 4 however, in programming if you do something like:
green - pink
you're getting
0, 2 - 2, 0
which is
-2 + 2
so 0 and this makes it seem they haven't moved, so my question is how can I get the difference between two numbers without subtraction, because this won't work here.
If you want the absolute difference, use math.abs(a-b) to get a positive number. The non-diagonal distance between two points on a grid is abs(x1-x2)+abs(y1-y2).