-[NEW] Nemesio acabat

This commit is contained in:
2026-03-22 09:51:41 +01:00
parent c4da64aa1f
commit c02c086af3
4 changed files with 37 additions and 11 deletions

View File

@@ -1,16 +1,29 @@
require ":utils.util" require ":utils.util"
nemesio = { STATIC = 1, FLOATING = 2 }
function ia.update_nemesio(spr) function ia.update_nemesio(spr)
spr.timer = spr.timer + 1 spr.timer = spr.timer + 1
if spr.state == templates.ALIVE then local target = {x=sprites.hero.pos.x-spr.pos.x, y=sprites.hero.pos.y-spr.pos.y}
if target.x > 0 then
spr.flipped = false
else
spr.flipped = true
end
if spr.substate == nemesio.STATIC then
spr.mode = draw.NORMAL
if spr.timer==100 then if spr.timer==100 then
spr.timer=0 spr.timer=0
spr.state = templates.DYING spr.substate = nemesio.FLOATING
local target = {x=sprites.hero.pos.x-spr.pos.x, y=sprites.hero.pos.y-spr.pos.y} spr.advance = {x=0,y=0}
spr.advance = util.normalize(target) if math.abs(target.x) > math.abs(target.y) then
spr.fpos = {x=spr.pos.x, y=spr.pos.y} spr.advance.x = math.sign(target.x)
else
spr.advance.y = math.sign(target.y)
end
end end
if sprites.hero.state == templates.ALIVE then if sprites.hero.state == templates.ALIVE then
@@ -22,14 +35,14 @@ function ia.update_nemesio(spr)
end end
end end
elseif spr.state == templates.DYING then elseif spr.substate == nemesio.FLOATING then
spr.fpos.x = spr.fpos.x + spr.advance.x spr.mode = draw.PATTERN
spr.fpos.y = spr.fpos.y + spr.advance.y spr.pattern = 0xa5a5
spr.pos.x = math.floor(spr.fpos.x) spr.pos.x = spr.pos.x + spr.advance.x
spr.pos.y = math.floor(spr.fpos.y) spr.pos.y = spr.pos.y + spr.advance.y
if spr.timer == 32 then if spr.timer == 32 then
spr.timer = 0 spr.timer = 0
spr.state = templates.ALIVE spr.substate = nemesio.STATIC
end end
end end
end end

View File

@@ -185,7 +185,11 @@ function sprites.draw_sprite(sprite)
local reversed = frame.reversed or false local reversed = frame.reversed or false
if not sprite.invisible then if not sprite.invisible then
surf.source(sprite.surf) surf.source(sprite.surf)
if sprite.pattern then draw.pattern(sprite.pattern) end
if sprite.mode then draw.mode(sprite.mode) end
draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x+ox, sprite.pos.y+oy, frame.frame.w, frame.frame.h, (not reversed) ~= (not sprite.flipped)) draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x+ox, sprite.pos.y+oy, frame.frame.w, frame.frame.h, (not reversed) ~= (not sprite.flipped))
draw.pattern(0xffff)
draw.mode(draw.NORMAL)
end end
if cheats.showaabb then if cheats.showaabb then
local x,y,w,h = util.aabb(sprite) local x,y,w,h = util.aabb(sprite)

View File

@@ -170,6 +170,7 @@ function me.create(type, options)
surf = surf.load("gfx/nemesio.gif"), surf = surf.load("gfx/nemesio.gif"),
animation = "nemesio", animation = "nemesio",
state = me.ALIVE, state = me.ALIVE,
substate = nemesio.STATIC,
timer = 0, timer = 0,
enemy = true, enemy = true,
room = options.room, room = options.room,

View File

@@ -34,3 +34,11 @@ function util.normalize(v)
end end
return {x = v.x / magnitud, y = v.y / magnitud} return {x = v.x / magnitud, y = v.y / magnitud}
end end
function math.sign(value)
if value > 0 then
return 1
else
return -1
end
end