Files
paku/data/modules/ia/mummy.lua

50 lines
1.8 KiB
Lua

function ia.update_mummy(spr)
map.surf(rooms.surf_foreground)
if spr.state == templates.ALIVE then
if sprites.hero.state == templates.ALIVE then
local x1,y1,w1,h1 = util.aabb(spr) -- El meu aabb
local x2,y2,w2,h2 = util.aabb(sprites.hero) -- el aabb del heroi
-- Si toca al heroi...
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
sprites.hero.hit()
end
end
if spr.flipped then
local tx, ty = (spr.pos.x+3)>>3, (spr.pos.y+15)>>3
if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 and map.tile(tx,ty+1) > 0 then
spr.pos.x = spr.pos.x - 1
else
spr.flipped = not spr.flipped
end
else
local tx, ty = (spr.pos.x+12)>>3, (spr.pos.y+15)>>3
if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 and map.tile(tx,ty+1) > 0 then
spr.pos.x = spr.pos.x + 1
else
spr.flipped = not spr.flipped
end
end
elseif spr.state == templates.DYING then
if spr.animation ~= "mummy_dying" then
sprites.set_animation(spr, "mummy_dying")
else
if spr.current_frame == 8 then
sprites.set_animation(spr, "mummy_dead")
spr.state = templates.DEAD
end
end
elseif spr.state == templates.DEAD then
if spr.current_wait == 1 then
sprites.set_animation(spr, "mummy_undying")
spr.state = templates.RESURRECTING
end
elseif spr.state == templates.RESURRECTING then
if spr.current_frame == 13 then
sprites.set_animation(spr, "mummy_walk")
spr.state = templates.ALIVE
end
end
end