diff --git a/data/gfx/nemesio.gif b/data/gfx/nemesio.gif new file mode 100644 index 0000000..b7e2eca Binary files /dev/null and b/data/gfx/nemesio.gif differ diff --git a/data/maps/rooms_background.gif b/data/maps/rooms_background.gif index 3f2282d..4165345 100644 Binary files a/data/maps/rooms_background.gif and b/data/maps/rooms_background.gif differ diff --git a/data/maps/rooms_items.gif b/data/maps/rooms_items.gif index 6af960e..4149f4a 100644 Binary files a/data/maps/rooms_items.gif and b/data/maps/rooms_items.gif differ 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