From dbad54ad228df4b70f56bf6be1380b6ae3064ac3 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Fri, 22 Sep 2017 22:09:26 +0200 Subject: First shot at range indicators. --- client/elm/battlemap/src/Battlemap/Location.elm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'client/elm/battlemap/src/Battlemap/Location.elm') diff --git a/client/elm/battlemap/src/Battlemap/Location.elm b/client/elm/battlemap/src/Battlemap/Location.elm index 4f70e49..36f0c4d 100644 --- a/client/elm/battlemap/src/Battlemap/Location.elm +++ b/client/elm/battlemap/src/Battlemap/Location.elm @@ -22,3 +22,23 @@ neighbor loc dir = get_ref : Type -> Ref get_ref l = (l.x, l.y) + +from_ref : Ref -> Type +from_ref (x, y) = + {x = x, y = y} + +dist : Type -> Type -> Int +dist loc_a loc_b = + if (loc_a.x > loc_b.x) + then + if (loc_a.y > loc_b.y) + then + ((loc_a.x - loc_b.x) + (loc_a.y - loc_b.y)) + else + ((loc_a.x - loc_b.x) + (loc_b.y - loc_a.y)) + else + if (loc_a.y > loc_b.y) + then + ((loc_b.x - loc_a.x) + (loc_a.y - loc_b.y)) + else + ((loc_b.x - loc_a.x) + (loc_b.y - loc_a.y)) -- cgit v1.2.3-70-g09d2