Code: Select all
local npcManager = require("npcManager")
local ruffPuffNPC = {}
local npcID = NPC_ID
local deathEffectID = npcID
-- settings
local config = {
id = npcID,
gfxoffsetx = 0,
gfxoffsety = 0,
width = 30,
height = 30,
gfxwidth = 46,
gfxheight = 38,
frames = 6,
framestyle = 1,
playerblocktop = false,
npcblocktop = false,
playerblock = false,
npcblock = false,
nofireball = true,
noiceball = false,
nohurt = true,
nogravity = true,
noblockcollision = true,
jumphurt = true,
spinjumpsafe = true,
projectile = 935,
iswalker = true
}
npcManager.setNpcSettings(config)
npcManager.registerHarmTypes(npcID,
{
--HARM_TYPE_JUMP,
--HARM_TYPE_FROMBELOW,
HARM_TYPE_NPC,
--HARM_TYPE_PROJECTILE_USED,
HARM_TYPE_LAVA,
HARM_TYPE_HELD,
--HARM_TYPE_TAIL,
--HARM_TYPE_SPINJUMP,
--HARM_TYPE_OFFSCREEN,
HARM_TYPE_SWORD
},
{
--[HARM_TYPE_JUMP]=10,
[HARM_TYPE_FROMBELOW]= deathEffectID,
[HARM_TYPE_NPC]= deathEffectID,
--[HARM_TYPE_PROJECTILE_USED]= 10,
[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5},
[HARM_TYPE_HELD]= deathEffectID,
--[HARM_TYPE_TAIL]=10,
--[HARM_TYPE_SPINJUMP]=10,
--[HARM_TYPE_OFFSCREEN]=10,
[HARM_TYPE_SWORD]= deathEffectID,
[HARM_TYPE_EXT_ICE] = 10,
}
);
local ST_IDLE = 0
local ST_WAIT = 1
local ST_SHOOT = 2
local turnTimer = 0
function ruffPuffNPC.onInitAPI()
npcManager.registerEvent(npcID, ruffPuffNPC, "onTickEndNPC")
end
function ruffPuffNPC.onTickEndNPC(v)
if Defines.levelFreeze then return end
if v.isHidden or v:mem(0x12A, FIELD_WORD) <= 0 or v:mem(0x138, FIELD_WORD) > 0 then
v.data.state = 0
v.data.timer = 0
turnTimer = 0
return
end
local data = v.data
local shootframe = NPC.config[v.id].frames - 2
if data.state == nil then
data.state = 0
data.timer = 0
turnTimer = 0
end
data.timer = data.timer + 1
turnTimer = turnTimer + 1
v.animationFrame = v.animationFrame % 4
if data.state ~= ST_SHOOT then
if turnTimer >= 128 then
v.speedX = v.speedX * -1
turnTimer = 0
end
end
if data.state == ST_IDLE then
if data.timer == 64 and not v.friendly then
data.timer = 0
data.state = ST_WAIT
end
elseif data.state == ST_WAIT then
if data.timer == 16 then
local n = NPC.spawn(NPC.config[v.id].projectile, v.x + 0.5 * v.width, v.y + 0.5 * v.height, player.section, false, true)
n.speedX = 2 * v.direction
data.timer = 0
data.state = ST_SHOOT
SFX.play("puffspit.ogg")
end
v.animationFrame = shootframe
elseif data.state == ST_SHOOT then
if data.timer == 16 then
data.timer = 0
data.state = ST_IDLE
end
v.animationFrame = shootframe + 1
end
if v.direction == 1 and NPC.config[v.id].framestyle == 1 then
v.animationFrame = v.animationFrame + NPC.config[v.id].frames
end
end
return ruffPuffNPC