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