
Code: Select all
local npcList = {650, 1, 2, 3, 4}
local blockManager = require("blockmanager")
local Routine = require("routine")
local blockIDs = {1, 115, 188}
local freezeTimer = 0
function handleFallingNPCs()
for _,v in ipairs(NPC.get(npcList)) do
if v:mem(0x12C, FIELD_WORD) <= 0 and not v.friendly then
if v.speedY > 0 then
for _,p in ipairs(Player.get()) do
if math.abs((v.x + v.width/2) - (p.x + p.width/2)) < (v.width/2 + p.width/2) then
local npcBottom = v.y + v.height
local playerTop = p.y
local dist = npcBottom - playerTop
if dist >= 0 and dist <= 8 then
if not p:mem(0x13E, FIELD_BOOL) then
if p.powerup > 1 then
p.powerup = 1
p:mem(0x140, FIELD_WORD, 50)
else
p:kill()
end
end
end
end
end
end
end
end
end
function handleFallingBlocks()
local player = Player(1)
for _,b in ipairs(Block.getIntersecting(player.x, player.y - 2, player.x + player.width, player.y)) do
if table.contains(blockIDs, b.id) and not b.isHidden and not b:mem(0x5A, FIELD_BOOL) then
local bconfig = blockManager.getBlockSettings(b.id)
local layer = b.layerObj
if layer and layer.speedY > 0 then
if not player:mem(0x13E, FIELD_BOOL) and freezeTimer <= 0 then
if player.powerup > 1 then
player.powerup = 1
player:mem(0x140, FIELD_WORD, 50)
else
player:kill()
end
Defines.levelFreeze = true
freezeTimer = 20
end
end
end
end
end
function onTick()
handleFallingNPCs()
handleFallingBlocks()
if freezeTimer > 0 then
freezeTimer = freezeTimer - 1
if freezeTimer == 0 then
Defines.levelFreeze = false
end
end
end
function table.contains(tbl, val)
for _,v in ipairs(tbl) do
if v == val then return true end
end
return false
end