Code: Select all
if springCooldown > 0 then -- Prevents 1000s of springs from spawning every time a springBox is hit.
springCooldown = springCooldown - 1
elseif springCooldown == 0 then
if springs then
for k,v in pairs(springs) do
v:kill()
end
end
for k,v in pairs(springBox) do
if (colliders.collide(player, v)) then
NPC.spawn(26, v.x, v.y, player.section)
springs = NPC.getIntersecting(v.x, v.y, v.x + 32, v.y + 32)
springCooldown = 15
end
end
endThis code is supposed to spawn a spring NPC whenever a springBox collider is touched by the player and then kill that NPC after 15 frames. The springCooldown variable is defined in an earlier place, and the code is running in onLoop(). I have the latest available LunaLua installed.




