aboutsummaryrefslogtreecommitdiff
path: root/go/game/range.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-02 00:13:30 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:46:38 +0200
commite8f44219976edf8cf57cbd9e964f66fe9d145a9c (patch)
tree8618f3b22d94ff443227d7ebbc84014e2a786fae /go/game/range.go
parente64e268155c4398a82245626cf36bc39f3bea6a8 (diff)
downloadmuhqs-game-e8f44219976edf8cf57cbd9e964f66fe9d145a9c.tar.gz
muhqs-game-e8f44219976edf8cf57cbd9e964f66fe9d145a9c.zip
change unit attack representation and implement sword
Diffstat (limited to 'go/game/range.go')
-rw-r--r--go/game/range.go18
1 files changed, 18 insertions, 0 deletions
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)