Files
paku/data/modules/ia/rata.lua
Raimon Zamora 7090a6134f - [NEW] Quan li peguen, Morcus pega un botet cap enrere
- [NEW] Quan peguen a l'heroi, la momia i la rata peguen la volta
2026-03-23 12:17:05 +01:00

30 lines
991 B
Lua

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()
spr.flipped = not spr.flipped
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