diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-02-02 00:13:30 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-02-02 00:13:30 +0100 |
| commit | 562538479916452a89fdda0bb77aa68a676b7f47 (patch) | |
| tree | 3d728812431f8875697f098b5283bc98ad8e97ad /go/game/range.go | |
| parent | be9251c159c1679fa6e6ebb4914b5ace2237d491 (diff) | |
| download | muhqs-game-562538479916452a89fdda0bb77aa68a676b7f47.tar.gz muhqs-game-562538479916452a89fdda0bb77aa68a676b7f47.zip | |
change unit attack representation and implement sword
Diffstat (limited to 'go/game/range.go')
| -rw-r--r-- | go/game/range.go | 18 |
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) |
