From c4da64aa1f4114a59a2974c583501d15827f542f Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 13 Mar 2026 13:16:11 +0100 Subject: [PATCH] - [WIP] Implementant a Nemesio --- data/gfx/nemesio.gif | Bin 0 -> 187 bytes data/maps/rooms_background.gif | Bin 1322 -> 1322 bytes data/maps/rooms_items.gif | Bin 1060 -> 1057 bytes data/modules/animations.lua | 7 +++++++ data/modules/ia/nemesio.lua | 35 +++++++++++++++++++++++++++++++++ data/modules/items.lua | 1 + data/modules/templates.lua | 17 ++++++++++++++++ data/utils/util.lua | 7 +++++++ 8 files changed, 67 insertions(+) create mode 100644 data/gfx/nemesio.gif create mode 100644 data/modules/ia/nemesio.lua diff --git a/data/gfx/nemesio.gif b/data/gfx/nemesio.gif new file mode 100644 index 0000000000000000000000000000000000000000..b7e2eca05c5b73b8ee365b0667e649ad1fdf0d27 GIT binary patch literal 187 zcmZ?wbh9u|6krfwIKlu036{eC+A3Pgp0ySZM#1sL$>IMQ7@DFDyHc$e)dn8SiLTz{ z_xr5W%(l`Q?d3-&hMb*O@M321hrQ*F4GT)v?%ub1)A0@Se&3&c?9k!=KcD>j57Z3> zia%L6xqxgP5FcbG1FMCC0$Yk_*NcpGD|gLW+j-{m%xNVJH_Rhn?~&sTyulj9aL1sd c%5b*dlJ3?kl8GB-OvR@9&A%|ogoVKx0J4usegFUf literal 0 HcmV?d00001 diff --git a/data/maps/rooms_background.gif b/data/maps/rooms_background.gif index 3f2282dbcffd670743d02fd7be3f28e6893ceed6..4165345ba2a2c47d0c21ac195152983e9b47caf9 100644 GIT binary patch delta 14 VcmZ3*wTf#47c*o1W^QJACIBFb1Bd_s delta 14 VcmZ3*wTf#47c(QnW^QJACIB6e0|@{C diff --git a/data/maps/rooms_items.gif b/data/maps/rooms_items.gif index 6af960eb92b8e6aaa3463b9fb602b159bd25891a..4149f4a9563efa7c0fd2a2e21b33edd61a51faf0 100644 GIT binary patch delta 120 zcmV-;0Ehpi2%!kDu>)|60~97c%(yX52#zC5jw)dCM#GLPTi(pMv*)auKT{0tcrn2P z5iyHi&APSgovH=KeoebJfZ4Vi;?6ygbYS1SgIC;*6Ekq($dfCd8Ym(0<0EGXc2&4$Gu>*65j1CS^xcIPRi4Pu2o=o|!fXW*UOTLV`v**vCvvLkiakS*d z1P?^iOuDt}*RXf87C1Y$?b`rq<8G*X_dwHuf%_g_u{Tc5!ig(i&U|X1gvOgopYArf d^ydk&dyX#9I`!}1!;=YKAili$^GgE)06X_4KSBTi diff --git a/data/modules/animations.lua b/data/modules/animations.lua index c68c2e4..5f81ee7 100644 --- a/data/modules/animations.lua +++ b/data/modules/animations.lua @@ -187,4 +187,11 @@ animations = { { 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 } + } + }, } \ No newline at end of file diff --git a/data/modules/ia/nemesio.lua b/data/modules/ia/nemesio.lua new file mode 100644 index 0000000..56113f6 --- /dev/null +++ b/data/modules/ia/nemesio.lua @@ -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 diff --git a/data/modules/items.lua b/data/modules/items.lua index a6c12d6..4be19a1 100644 --- a/data/modules/items.lua +++ b/data/modules/items.lua @@ -14,4 +14,5 @@ items = { { 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 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} }, } diff --git a/data/modules/templates.lua b/data/modules/templates.lua index af3e671..0e8d610 100644 --- a/data/modules/templates.lua +++ b/data/modules/templates.lua @@ -158,6 +158,23 @@ function me.create(type, options) ay = 1, 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 error("Template not recognized") end diff --git a/data/utils/util.lua b/data/utils/util.lua index 7274fc5..e270ef9 100644 --- a/data/utils/util.lua +++ b/data/utils/util.lua @@ -27,3 +27,10 @@ function util.luminance(r, g, b) return (0.2126*r + 0.7152*g + 0.0722*b)/255 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