diff options
| author | troido <troido@protonmail.com> | 2020-03-02 12:02:54 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-02 12:02:54 +0100 |
| commit | 27c0795fb70739ce5609a0f424d80491d4a8c5a1 (patch) | |
| tree | 1a6ab802edb717a42ca67a8d997cf960d7f4f5ed /src/pos.rs | |
| parent | d246537a28a7a71dfb2487d31d6fac3ccab5053d (diff) | |
added monster ai
Diffstat (limited to 'src/pos.rs')
| -rw-r--r-- | src/pos.rs | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -1,6 +1,6 @@ -use std::ops::Add; +use std::ops::{Add, Sub}; use serde_json::Value; use serde::{Serialize, Serializer, ser::SerializeTuple}; use crate::util::clamp; @@ -31,6 +31,11 @@ impl Pos { y: val.get(1)?.as_i64()? }) } + + pub fn distance_to(&self, other: Pos) -> i64 { + let d = other - *self; + d.x.abs() + d.y.abs() + } } @@ -57,3 +62,14 @@ impl Add<Pos> for Pos { } } +impl Sub<Pos> for Pos { + type Output = Pos; + + fn sub(self, other: Pos) -> Pos { + Pos { + x: self.x - other.x, + y: self.y - other.y + } + } +} + |
