58 lines
2.0 KiB
Lua
58 lines
2.0 KiB
Lua
|
|
function ia.update_gota(spr)
|
|
if spr.timer > 0 then
|
|
spr.timer = spr.timer-1
|
|
return
|
|
else
|
|
spr.invisible = nil;
|
|
if spr.current_frame==2 then
|
|
local gota = templates.create("gota_caiguent", {pos={x=spr.pos.x, y=spr.pos.y}, flipped=spr.flipped})
|
|
table.insert(sprites.list, gota)
|
|
--spr.animation_finished = nil
|
|
--spr.current_frame = 1
|
|
--spr.current_wait = 1
|
|
end
|
|
end
|
|
end
|
|
|
|
function gota_esguita(spr)
|
|
sprites.remove(spr)
|
|
table.insert(sprites.list, templates.create("gota_esguit", {pos={x=spr.pos.x, y=spr.pos.y}, dir={x= 1,y= math.random(3,5)}, flipped=spr.flipped}))
|
|
table.insert(sprites.list, templates.create("gota_esguit", {pos={x=spr.pos.x, y=spr.pos.y}, dir={x=-1,y= math.random(3,5)}, flipped=spr.flipped}))
|
|
table.insert(sprites.list, templates.create("gota_esguit", {pos={x=spr.pos.x, y=spr.pos.y}, dir={x=-1,y=-math.random(3,5)}, flipped=spr.flipped}))
|
|
table.insert(sprites.list, templates.create("gota_esguit", {pos={x=spr.pos.x, y=spr.pos.y}, dir={x= 1,y=-math.random(3,5)}, flipped=spr.flipped}))
|
|
end
|
|
|
|
function ia.update_gota_caiguent(spr)
|
|
local tx, ty = (spr.pos.x+4)>>3, (spr.pos.y+4)>>3
|
|
|
|
if rooms.is_outside(tx,ty) then sprites.remove(spr) return end
|
|
|
|
if map.tile(tx,ty) >= 16 then
|
|
gota_esguita(spr)
|
|
end
|
|
|
|
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()
|
|
gota_esguita(spr)
|
|
end
|
|
end
|
|
|
|
spr.pos.y = spr.pos.y + 1
|
|
end
|
|
|
|
function ia.update_gota_esguit(spr)
|
|
local tx, ty = (spr.pos.x+4)>>3, (spr.pos.y+4)>>3
|
|
|
|
if rooms.is_outside(tx,ty) then sprites.remove(spr) return end
|
|
|
|
spr.dir.y = spr.dir.y + 1;
|
|
spr.pos.y = spr.pos.y + spr.dir.y
|
|
spr.pos.x = spr.pos.x + spr.dir.x
|
|
end
|
|
|