From e8f44219976edf8cf57cbd9e964f66fe9d145a9c Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 2 Feb 2023 00:13:30 +0100 Subject: change unit attack representation and implement sword --- go/game/range.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'go/game/range.go') diff --git a/go/game/range.go b/go/game/range.go index ab86c44e..6e04d21f 100644 --- a/go/game/range.go +++ b/go/game/range.go @@ -4,6 +4,24 @@ import ( "math" ) +func DistanceBetweenPositions(origin, pos Position) int { + x, y := float64(pos.X-origin.X), float64(pos.Y-origin.Y) + ax, ay := math.Abs(x), math.Abs(y) + + var abs float64 + if pos.X > pos.Y { + abs = ax + math.Floor(ay/2) + } else { + abs = ay + math.Floor(ax/2) + } + + return int(abs) +} + +func DistanceBetweenPermanents(p1, p2 Permanent) int { + return DistanceBetweenPositions(p1.Tile().Position, p2.Tile().Position) +} + func IsPositionInRange(origin Position, pos Position, r int) bool { x, y := float64(pos.X-origin.X), float64(pos.Y-origin.Y) ax, ay := math.Abs(x), math.Abs(y) -- cgit v1.2.3