Advertisement
Guest User

Untitled

a guest
May 25th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.73 KB | None | 0 0
  1. --NPCManager is required for setting basic NPC properties
  2. local npcManager = require("npcManager")
  3.  
  4. --Create the library table
  5. local Axe = {}
  6. --NPC_ID is dynamic based on the name of the library file
  7. local npcID = 751
  8. local ax = Graphics.loadImage("AXE.png");
  9. local imx = 0
  10. local imy = 0
  11.  
  12. --Defines NPC config for our NPC. You can remove superfluous definitions.
  13. local AxeSettings = {
  14.     id = npcID,
  15.     --Sprite size
  16.     gfxheight = 62,
  17.     gfxwidth = 32,
  18.     --Hitbox size. Bottom-center-bound to sprite size.
  19.     width = 32,
  20.     height = 60,
  21.     --Sprite offset from hitbox for adjusting hitbox anchor on sprite.
  22.     gfxoffsetx = 0,
  23.     gfxoffsety = 0,
  24.     --Frameloop-related
  25.     frames = 1,
  26.     framestyle = 0,
  27.     framespeed = 8, --# frames between frame change
  28.     --Movement speed. Only affects speedX by default.
  29.     --speed = 0,
  30.     --Collision-related
  31.     npcblock = false,
  32.     npcblocktop = false, --Misnomer, affects whether thrown NPCs bounce off the NPC.
  33.     playerblock = false,
  34.     playerblocktop = false, --Also handles other NPCs walking atop this NPC.
  35.  
  36.     --nohurt=false,
  37.     nogravity = true,
  38.     noblockcollision = true,
  39.     nofireball = true,
  40.     noiceball = true,
  41.     noyoshi= true,
  42.     nowaterphysics = true,
  43.     --Various interactions
  44.     jumphurt = false, --If true, spiny-like
  45.     spinjumpsafe = true, --If true, prevents player hurt when spinjumping
  46.     harmlessgrab = true, --Held NPC hurts other NPCs if false
  47.     harmlessthrown = true, --Thrown NPC hurts other NPCs if false
  48.  
  49.     --Identity-related flags. Apply various vanilla AI based on the flag:
  50.     --iswalker = false,
  51.     --isbot = false,
  52.     --isvegetable = false,
  53.     --isshoe = false,
  54.     --isyoshi = false,
  55.     --isinteractable = false,
  56.     --iscoin = false,
  57.     --isvine = false,
  58.     --iscollectablegoal = false,
  59.     --isflying = false,
  60.     --iswaternpc = false,
  61.     --isshell = false,
  62.  
  63.     --Emits light if the Darkness feature is active:
  64.     --lightradius = 100,
  65.     --lightbrightness = 1,
  66.     --lightoffsetx = 0,
  67.     --lightoffsety = 0,
  68.     --lightcolor = Color.white,
  69.  
  70.     --Define custom properties below
  71. }
  72.  
  73. --Applies NPC settings
  74. npcManager.setNpcSettings(AxeSettings)
  75.  
  76. --Registers the category of the NPC. Options include HITTABLE, UNHITTABLE, POWERUP, COLLECTIBLE, SHELL. For more options, check expandedDefines.lua
  77. npcManager.registerDefines(npcID, {NPC.UNHITTABLE})
  78.  
  79. --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.
  80. npcManager.registerHarmTypes(npcID,
  81.     {
  82.         --HARM_TYPE_JUMP,
  83.         --HARM_TYPE_FROMBELOW,
  84.         --HARM_TYPE_NPC,
  85.         --HARM_TYPE_PROJECTILE_USED,
  86.         --HARM_TYPE_LAVA,
  87.         --HARM_TYPE_HELD,
  88.         --HARM_TYPE_TAIL,
  89.         --HARM_TYPE_SPINJUMP,
  90.         --HARM_TYPE_OFFSCREEN,
  91.         --HARM_TYPE_SWORD
  92.     },
  93.     {
  94.         --[HARM_TYPE_JUMP]=10,
  95.         --[HARM_TYPE_FROMBELOW]=10,
  96.         --[HARM_TYPE_NPC]=10,
  97.         --[HARM_TYPE_PROJECTILE_USED]=10,
  98.         --[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5},
  99.         --[HARM_TYPE_HELD]=10,
  100.         --[HARM_TYPE_TAIL]=10,
  101.         --[HARM_TYPE_SPINJUMP]=10,
  102.         --[HARM_TYPE_OFFSCREEN]=10,
  103.         --[HARM_TYPE_SWORD]=10,
  104.     }
  105. );
  106.  
  107. --Custom local definitions below
  108.  
  109. --Register events
  110. function Axe.onInitAPI()
  111.     npcManager.registerEvent(npcID, Axe, "onTickNPC")
  112.     --npcManager.registerEvent(npcID, Axe, "onTickEndNPC")
  113.     npcManager.registerEvent(npcID, Axe, "onDrawNPC")
  114.     --registerEvent(Axe, "onNPCKill")
  115. end
  116.  
  117. function Axe.onTickNPC(v)
  118.     --Don't act during time freeze
  119.     if Defines.levelFreeze then return end
  120.     local data = v.data
  121.  
  122.     for _,npc in pairs(NPC.getIntersecting(v.x, v.y, v.x + v.width, v.y + v.height)) do
  123.         npc:harm(HARM_TYPE_NPC)
  124.     end
  125.  
  126.     data.img = nil
  127.  
  128.     --If despawned
  129.     if v:mem(0x12A, FIELD_WORD) <= 0 then
  130.         --Reset our properties, if necessary
  131.         data.initialized = false
  132.         return
  133.     end
  134.  
  135.     --Initialize
  136.     if not data.initialized then
  137.         --Initialize necessary data.   
  138.         v.speedY = -14
  139.         data.t = 0
  140.         data.initialized = true
  141.     end
  142.  
  143.     local t = data.t
  144.  
  145.     v.speedY = v.speedY + 0.4;
  146.     Text.print(v.speedY, 200, 200)
  147.     Text.print(t, 100, 100)
  148.  
  149.     if v.speedY > 8 then
  150.         data.t = data.t + 0.4
  151.         v.y = v.y + t
  152.     end
  153.  
  154.  
  155.     --Depending on the NPC, these checks must be handled differently
  156.     if v:mem(0x12C, FIELD_WORD) > 0    --Grabbed
  157.     or v:mem(0x136, FIELD_BOOL)        --Thrown
  158.     or v:mem(0x138, FIELD_WORD) > 0    --Contained within
  159.     then
  160.         --Handling
  161.     end
  162.  
  163.     --Execute main AI. This template just jumps when it touches the ground.
  164.     if v.collidesBlockBottom then
  165.  
  166.     end
  167. end
  168.  
  169. function Axe.onDrawNPC(v)
  170.     if v.data.img == nil then
  171.         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}
  172.         v.data.img = image
  173.         v.data.img:draw{}
  174.         v.data.img:rotate(1)
  175.     end
  176. end
  177.  
  178. --Gotta return the library table!
  179. return Axe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement