-[NEW] Rata acabada

This commit is contained in:
2026-03-22 10:24:13 +01:00
parent c02c086af3
commit d5c0dfddeb
8 changed files with 55 additions and 0 deletions

28
data/modules/ia/rata.lua Normal file
View File

@@ -0,0 +1,28 @@
function ia.update_rata(spr)
map.surf(rooms.surf_foreground)
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-1)>>3, (spr.pos.y+7)>>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+9)>>3, (spr.pos.y+7)>>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
end