diff --git a/vacuum_gambit.p8 b/vacuum_gambit.p8 index 4df8742..c94b5e8 100644 --- a/vacuum_gambit.p8 +++ b/vacuum_gambit.p8 @@ -686,15 +686,28 @@ segment = mknew{ -- figure out approach/depart -- [1..n]: destinations init = function(x) - x.remain = x.limit + x.init = segment.reset + mknew(x) + if not x.mirror then + local mirrored = {mirror=x} + for i, v in ipairs(x) do + mirrored[i] = destination.new{ + anchor_frac=v.anchor_frac + accel_frac=v.accel_frac + x_off_frac=-v.x_off_frac + y_off_frac=v.y_off_frac + } + end + x.mirror = x.new(mirrored) + end end } function segment:reset() self.current_idx = 1 self.remain = self.limit - self.prev_x = nil - self.prev_y = nil + self.prev_x = false + self.prev_y = false self.was_approaching = false end @@ -745,12 +758,29 @@ end path = mknew { loop_idx = 1, - current_idx = 1, -- [1..n]: destinations + init=function(x) + if not x.mirror then + local mirrored = { + mirror = x, + loop_idx = x.loop_idx + } + for i, v in ipairs(x) do + mirrored[i]=v.mirror + end + x.mirror = path.new(mirrored) + end + x.init = function(y) + for i, v in ipairs(x) do + y[i]=v.new{} + end + y:reset() + end + mknew(x) + end, } function path:reset() - self.loop_idx = 1 self.current_idx = 1 end