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

27 lines
811 B
Lua

function ia.update_coin(spr)
if spr.state == templates.ALIVE then
local x1,y1,w1,h1 = util.aabb(spr)
local x2,y2,w2,h2 = util.aabb(sprites.hero)
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
local tx, ty = (spr.pos.x)>>3, (spr.pos.y)>>3
map.surf(rooms.surf_items)
map.tile(tx,ty,0)
spr.state = templates.DYING
sprites.set_animation(spr, "coin_picked")
spr.pos.y=spr.pos.y-16
spr.pos.x=spr.pos.x-4
spr.timer = 0
score.inc(10)
return
end
elseif spr.state == templates.DYING then
spr.pos.y = spr.pos.y - 0.5
spr.timer = spr.timer + 1
if spr.timer == 32 then
sprites.remove(spr)
end
end
end