- [WIP] Implementant a Nemesio
This commit is contained in:
35
data/modules/ia/nemesio.lua
Normal file
35
data/modules/ia/nemesio.lua
Normal 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
|
||||
Reference in New Issue
Block a user