Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --NPCManager is required for setting basic NPC properties
- local npcManager = require("npcManager")
- --Create the library table
- local Axe = {}
- --NPC_ID is dynamic based on the name of the library file
- local npcID = 751
- local ax = Graphics.loadImage("AXE.png");
- --Defines NPC config for our NPC. You can remove superfluous definitions.
- local AxeSettings = {
- id = npcID,
- --Sprite size
- gfxheight = 62,
- gfxwidth = 32,
- --Hitbox size. Bottom-center-bound to sprite size.
- width = 32,
- height = 60,
- --Sprite offset from hitbox for adjusting hitbox anchor on sprite.
- gfxoffsetx = 0,
- gfxoffsety = 0,
- --Frameloop-related
- frames = 1,
- framestyle = 0,
- framespeed = 8, --# frames between frame change
- --Movement speed. Only affects speedX by default.
- --speed = 0,
- --Collision-related
- npcblock = false,
- npcblocktop = false, --Misnomer, affects whether thrown NPCs bounce off the NPC.
- playerblock = false,
- playerblocktop = false, --Also handles other NPCs walking atop this NPC.
- --nohurt=false,
- nogravity = true,
- noblockcollision = true,
- nofireball = true,
- noiceball = true,
- noyoshi= true,
- nowaterphysics = true,
- --Various interactions
- jumphurt = false, --If true, spiny-like
- spinjumpsafe = true, --If true, prevents player hurt when spinjumping
- harmlessgrab = true, --Held NPC hurts other NPCs if false
- harmlessthrown = true, --Thrown NPC hurts other NPCs if false
- --Identity-related flags. Apply various vanilla AI based on the flag:
- --iswalker = false,
- --isbot = false,
- --isvegetable = false,
- --isshoe = false,
- --isyoshi = false,
- --isinteractable = false,
- --iscoin = false,
- --isvine = false,
- --iscollectablegoal = false,
- --isflying = false,
- --iswaternpc = false,
- --isshell = false,
- --Emits light if the Darkness feature is active:
- --lightradius = 100,
- --lightbrightness = 1,
- --lightoffsetx = 0,
- --lightoffsety = 0,
- --lightcolor = Color.white,
- --Define custom properties below
- }
- --Applies NPC settings
- npcManager.setNpcSettings(AxeSettings)
- --Registers the category of the NPC. Options include HITTABLE, UNHITTABLE, POWERUP, COLLECTIBLE, SHELL. For more options, check expandedDefines.lua
- npcManager.registerDefines(npcID, {NPC.UNHITTABLE})
- --Register the vulnerable harm types for this NPC. The first table defines the harm types the NPC should be affected by, while the second maps an effect to each, if desired.
- 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]=10,
- --[HARM_TYPE_NPC]=10,
- --[HARM_TYPE_PROJECTILE_USED]=10,
- --[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5},
- --[HARM_TYPE_HELD]=10,
- --[HARM_TYPE_TAIL]=10,
- --[HARM_TYPE_SPINJUMP]=10,
- --[HARM_TYPE_OFFSCREEN]=10,
- --[HARM_TYPE_SWORD]=10,
- }
- );
- --Custom local definitions below
- --Register events
- function Axe.onInitAPI()
- npcManager.registerEvent(npcID, Axe, "onTickNPC")
- --npcManager.registerEvent(npcID, Axe, "onTickEndNPC")
- npcManager.registerEvent(npcID, Axe, "onDrawNPC")
- --registerEvent(Axe, "onNPCKill")
- end
- function Axe.onTickNPC(v)
- --Don't act during time freeze
- if Defines.levelFreeze then return end
- local data = v.data
- for _,npc in pairs(NPC.getIntersecting(v.x, v.y, v.x + v.width, v.y + v.height)) do
- npc:harm(HARM_TYPE_NPC)
- end
- data.img = nil
- --If despawned
- if v:mem(0x12A, FIELD_WORD) <= 0 then
- --Reset our properties, if necessary
- data.initialized = false
- return
- end
- --Initialize
- if not data.initialized then
- --Initialize necessary data.
- v.speedY = -14
- data.t = 0
- data.initialized = true
- end
- local t = data.t
- v.speedY = v.speedY + 0.4;
- Text.print(v.speedY, 200, 200)
- Text.print(t, 100, 100)
- if v.speedY > 8 then
- data.t = data.t + 0.4
- v.y = v.y + t
- end
- --Depending on the NPC, these checks must be handled differently
- if v:mem(0x12C, FIELD_WORD) > 0 --Grabbed
- or v:mem(0x136, FIELD_BOOL) --Thrown
- or v:mem(0x138, FIELD_WORD) > 0 --Contained within
- then
- --Handling
- end
- --Execute main AI. This template just jumps when it touches the ground.
- if v.collidesBlockBottom then
- end
- end
- function Axe.onDrawNPC(v)
- if v.data.img == nil then
- local image = Sprite.box{x = v.x + v.width * 0.5, y = v.y + v.height * 0.5, width = 32, height = 62, pivot = Sprite.align.CENTRE, frames = 1, texture = ax}
- v.data.img = image
- end
- v.data.img:draw{sceneCoords=true}
- v.data.img:rotate(1)
- end
- --Gotta return the library table!
- return Axe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement