3 Commits

Author SHA1 Message Date
2596f8aa6c I can't spell 2025-06-21 15:13:07 -07:00
ef40c245f8 multi-step shot prototype
nothing reaches this new logic yet, and multiple steps aren't drawn
2025-06-21 15:12:40 -07:00
6d6e13cf3b special case strip(call_move) to stripmove()
this gets called so much the extra function overhead actually seems bad
2025-06-21 14:55:20 -07:00

View File

@ -107,6 +107,22 @@ function linked_list:strip(f)
self.tail = p self.tail = p
end 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 - -- optimized special case -
-- could be done with strip but -- could be done with strip but
-- this avoids extra function -- this avoids extra function
@ -185,14 +201,6 @@ function _update60()
mode:update() mode:update()
end end
function call_f(x)
return x:f()
end
function call_move(x)
return x:move()
end
function ones(n) function ones(n)
local ret = 0 local ret = 0
while n != 0 do while n != 0 do
@ -233,9 +241,8 @@ function updategame()
current_wave:load(0, 0, min(ones(waves_complete)\2, 4)) current_wave:load(0, 0, min(ones(waves_complete)\2, 4))
end end
events:vore(new_events) events:vore(new_events)
events:strip(call_move) for _, lst in ipairs{events, intangibles_bg, eships} do
for _, lst in ipairs{intangibles_bg, eships} do lst:stripmove()
lst:strip(call_move)
end end
-- eship collider will be used -- eship collider will be used
@ -250,25 +257,33 @@ function updategame()
if(es:hitship(ps)) eship_collider:yoink(es) if(es:hitship(ps)) eship_collider:yoink(es)
end end
ebullets:strip(function(eb) ebullets:strip(function(eb)
-- loopify this when split moves implemented local disposition
if (eb:move()) return true repeat
if (not collides(pbox, hurtbox(eb))) return disposition=eb:step()
ps:hitbullet(eb) if collides(pbox, hurtbox(eb)) then
return eb:hitship(ps) ps:hitbullet(eb)
if (eb:hitship(ps)) return true
end
until disposition
return disposition == "dead"
end) end)
else else
ebullets:strip(call_move) ebullets:strip(function(eb) repeat until eb:step() end)
end end
pbullets:strip(function(pb) pbullets:strip(function(pb)
if (pb:move()) return true local disposition
for es in eship_collider:iterate_collisions(hurtbox(pb)) do repeat
if (es:hitbullet(pb)) eship_collider:yoink(es) disposition=pb:step()
if (pb:hitship(es)) return true for es in eship_collider:iterate_collisions(hurtbox(pb)) do
end if (es:hitbullet(pb)) eship_collider:yoink(es)
if (pb:hitship(es)) return true
end
until disposition
return disposition == "dead"
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 if waves_complete == 32767 and not eships.next and not ebullets.next and not events.next then
game_state = win game_state = win
@ -685,9 +700,10 @@ end
-- default: die, return true. -- default: die, return true.
-- returns whether to delete -- returns whether to delete
-- the bullet -- the bullet
-- die -- on-removal event, bullet_base = mknew{
-- default no-op steps=1,
bullet_base = mknew{ } current_step=0
}
gun_base = mknew{ gun_base = mknew{
shoot_ready = -32768, shoot_ready = -32768,
@ -813,11 +829,13 @@ function bullet_base:hitship(_)
return true return true
end end
function bullet_base:move() function bullet_base:step()
self.current_step=(self.current_step+1)%self.steps
self.x += self.dx self.x += self.dx
self.y += self.dy self.y += self.dy
if (self.f) self.f -= 1 if (self.f) self.f -= 1
return (self.y > 130) or (self.y < -self.height*8) or (self.f and self.f < 0) or (self.x > 128) or (self.x < -self.width*8) if ((self.y > 130) or (self.y < -self.height*8) or (self.f and self.f < 0) or (self.x > 128) or (self.x < -self.width*8)) return "dead"
if (self.current_step == 0) return "stop"
end end
function bullet_base:draw() function bullet_base:draw()