From ee24adf8b232564d7e0c8000bbe40c1e9e31be1c Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sat, 5 Jul 2025 20:27:14 -0700 Subject: [PATCH] path prototype --- vacuum_gambit.p8 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/vacuum_gambit.p8 b/vacuum_gambit.p8 index a459dd3..e6af347 100644 --- a/vacuum_gambit.p8 +++ b/vacuum_gambit.p8 @@ -743,6 +743,32 @@ function segment:should_step(x, y) return ret end +path = mknew { + loop_idx = 1, + current_idx = 1, + -- [1..n]: destinations +} + +function path:reset() + self.loop_idx = 1 + self.current_idx = 1 +end + +function path:target_from(fx, fy) + return self[self.current_idx]:target_from(fx, fy) +end + +function path:update(x, y) + local idx = self.current_idx + if self[idx]:update(x, y) then + if idx == #self then + self.current_idx = self.loop_idx + return true + else + self.current_idx = idx+1 + end + end +end -->8 -- bullet and gun behaviors