- [WIP] Implementant a Nemesio

This commit is contained in:
2026-03-13 13:16:11 +01:00
parent a987fb330a
commit c4da64aa1f
8 changed files with 67 additions and 0 deletions

BIN
data/gfx/nemesio.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -187,4 +187,11 @@ animations = {
{ frame={x=0,y=9,w=16,h=6}, wait=100 } { frame={x=0,y=9,w=16,h=6}, wait=100 }
} }
}, },
["nemesio"] = {
cycle = {1},
loop = false,
frames = {
{ frame={x=0,y=0,w=16,h=16}, wait=100 }
}
},
} }

View File

@@ -0,0 +1,35 @@
require ":utils.util"
function ia.update_nemesio(spr)
spr.timer = spr.timer + 1
if spr.state == templates.ALIVE then
if spr.timer==100 then
spr.timer=0
spr.state = templates.DYING
local target = {x=sprites.hero.pos.x-spr.pos.x, y=sprites.hero.pos.y-spr.pos.y}
spr.advance = util.normalize(target)
spr.fpos = {x=spr.pos.x, y=spr.pos.y}
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()
end
end
elseif spr.state == templates.DYING then
spr.fpos.x = spr.fpos.x + spr.advance.x
spr.fpos.y = spr.fpos.y + spr.advance.y
spr.pos.x = math.floor(spr.fpos.x)
spr.pos.y = math.floor(spr.fpos.y)
if spr.timer == 32 then
spr.timer = 0
spr.state = templates.ALIVE
end
end
end

View File

@@ -14,4 +14,5 @@ items = {
{ name="sucubo 25", label="sucubo25", visual={x=0, y=64, w=16, h=16} }, { name="sucubo 25", label="sucubo25", visual={x=0, y=64, w=16, h=16} },
{ name="sucubo 50", label="sucubo50", visual={x=0, y=64, w=16, h=16} }, { name="sucubo 50", label="sucubo50", visual={x=0, y=64, w=16, h=16} },
{ name="sucubo 75", label="sucubo75", visual={x=0, y=64, w=16, h=16} }, { name="sucubo 75", label="sucubo75", visual={x=0, y=64, w=16, h=16} },
{ name="nemesio", label="nemesio", visual={x=16, y=80, w=16, h=16} },
} }

View File

@@ -158,6 +158,23 @@ function me.create(type, options)
ay = 1, ay = 1,
ia = ia.update_palo ia = ia.update_palo
} }
elseif key == "nemesio" then
sprite = {
type = key,
pos = options.pos,--{ x=100, y=4*12*8+71 },
size = { w=16,h=16 },
bbo = { left=3, top=2, right=3, bottom=0 },
current_frame = 1,
current_wait = 1,
flipped = options.flipped,
surf = surf.load("gfx/nemesio.gif"),
animation = "nemesio",
state = me.ALIVE,
timer = 0,
enemy = true,
room = options.room,
ia = ia.update_nemesio
}
else else
error("Template not recognized") error("Template not recognized")
end end

View File

@@ -27,3 +27,10 @@ function util.luminance(r, g, b)
return (0.2126*r + 0.7152*g + 0.0722*b)/255 return (0.2126*r + 0.7152*g + 0.0722*b)/255
end end
function util.normalize(v)
local magnitud = math.sqrt(v.x * v.x + v.y * v.y)
if magnitud == 0 then
return {x = 0, y = 0} -- evita división por cero
end
return {x = v.x / magnitud, y = v.y / magnitud}
end