diff --git a/vacuum_gambit.p8 b/vacuum_gambit.p8 index 4e7c806..a661d66 100644 --- a/vacuum_gambit.p8 +++ b/vacuum_gambit.p8 @@ -107,6 +107,22 @@ function linked_list:strip(f) self.tail = p end +-- stripmove calls x:move() for +-- each node, removing each node +-- for which x:move() is true. +function linked_list:stripmove() + local p, n = self, self.next + while n do + if n:move() then + p.next = n.next + else + p = n + end + n = n.next + end + self.tail = p +end + -- optimized special case - -- could be done with strip but -- this avoids extra function @@ -185,14 +201,6 @@ function _update60() mode:update() end -function call_f(x) - return x:f() -end - -function call_move(x) - return x:move() -end - function ones(n) local ret = 0 while n != 0 do @@ -233,9 +241,8 @@ function updategame() current_wave:load(0, 0, min(ones(waves_complete)\2, 4)) end events:vore(new_events) - events:strip(call_move) - for _, lst in ipairs{intangibles_bg, eships} do - lst:strip(call_move) + for _, lst in ipairs{events, intangibles_bg, eships} do + lst:stripmove() end -- eship collider will be used @@ -257,7 +264,7 @@ function updategame() return eb:hitship(ps) end) else - ebullets:strip(call_move) + ebullets:stripmove() end pbullets:strip(function(pb) @@ -268,7 +275,7 @@ function updategame() end end) - intangibles_fg:strip(call_move) + intangibles_fg:stripmove() if waves_complete == 32767 and not eships.next and not ebullets.next and not events.next then game_state = win