diff --git a/data/modules/ia/nemesio.lua b/data/modules/ia/nemesio.lua index 56113f6..af5cfe7 100644 --- a/data/modules/ia/nemesio.lua +++ b/data/modules/ia/nemesio.lua @@ -1,16 +1,29 @@ require ":utils.util" +nemesio = { STATIC = 1, FLOATING = 2 } + function ia.update_nemesio(spr) 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 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} + spr.substate = nemesio.FLOATING + spr.advance = {x=0,y=0} + if math.abs(target.x) > math.abs(target.y) then + spr.advance.x = math.sign(target.x) + else + spr.advance.y = math.sign(target.y) + end end if sprites.hero.state == templates.ALIVE then @@ -22,14 +35,14 @@ function ia.update_nemesio(spr) 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) + elseif spr.substate == nemesio.FLOATING then + spr.mode = draw.PATTERN + spr.pattern = 0xa5a5 + spr.pos.x = spr.pos.x + spr.advance.x + spr.pos.y = spr.pos.y + spr.advance.y if spr.timer == 32 then spr.timer = 0 - spr.state = templates.ALIVE + spr.substate = nemesio.STATIC end end end diff --git a/data/modules/sprites.lua b/data/modules/sprites.lua index 46ee096..7bb77d8 100644 --- a/data/modules/sprites.lua +++ b/data/modules/sprites.lua @@ -185,7 +185,11 @@ function sprites.draw_sprite(sprite) local reversed = frame.reversed or false if not sprite.invisible then 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.pattern(0xffff) + draw.mode(draw.NORMAL) end if cheats.showaabb then local x,y,w,h = util.aabb(sprite) diff --git a/data/modules/templates.lua b/data/modules/templates.lua index 0e8d610..9aebf06 100644 --- a/data/modules/templates.lua +++ b/data/modules/templates.lua @@ -170,6 +170,7 @@ function me.create(type, options) surf = surf.load("gfx/nemesio.gif"), animation = "nemesio", state = me.ALIVE, + substate = nemesio.STATIC, timer = 0, enemy = true, room = options.room, diff --git a/data/utils/util.lua b/data/utils/util.lua index e270ef9..5c2eaf5 100644 --- a/data/utils/util.lua +++ b/data/utils/util.lua @@ -34,3 +34,11 @@ function util.normalize(v) end return {x = v.x / magnitud, y = v.y / magnitud} end + +function math.sign(value) + if value > 0 then + return 1 + else + return -1 + end +end \ No newline at end of file