Advertisement
Guest User

Untitled

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