From 0abc0b9b7928cd72b1c92b3af9f30674397013d1 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 13 Feb 2023 01:18:57 +0000 Subject: add collisions and sliding for player movement --- common/coords.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'common') 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 -- cgit v1.2.3