diff options
author | ubq323 <ubq323@ubq323.website> | 2023-02-13 01:18:57 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-02-13 01:18:57 +0000 |
commit | 0abc0b9b7928cd72b1c92b3af9f30674397013d1 (patch) | |
tree | eda521067eb30240aa17a8cac6dfe74a361ea671 /common | |
parent | 24b06ededb117588adab64af1c60a0c53e2a8feb (diff) |
add collisions and sliding for player movement
Diffstat (limited to 'common')
-rw-r--r-- | common/coords.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/common/coords.lua b/common/coords.lua index 49c2bf2..420b287 100644 --- a/common/coords.lua +++ b/common/coords.lua @@ -75,6 +75,16 @@ function Hex.offset_in_chunk(self) local cp,offs = self:chunk_and_offset() return offs end +function Hex.iter_neighbours(self,radius) + assert(radius > 0,"radius must be at least 1") + return coroutine.wrap(function() + for q = -radius,radius do + for r = math.max(-radius,-q-radius), math.min(radius,-q+radius) do + coroutine.yield(self+Hex:make(q,r)) + end + end + end) +end function Hex.__add(self,other) return Hex:make(self.q+other.q, self.r+other.r, self.s+other.s) end function Hex.__sub(self,other) return Hex:make(self.q-other.q, self.r-other.r, self.s-other.s) end function Hex.__tostring(self) return string.format("H(%.2f,%.2f)",self.q,self.r) end |