-
-
Save jhoff/3907978 to your computer and use it in GitHub Desktop.
weapon parent/child hierarchy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--This is a snippet of a Mallet file | |
local Weapon = require 'weapon' | |
function Mallet.new(node, collider) | |
local mallet = Weapon.new(node, collider) | |
setmetatable(mallet, Mallet) | |
-- setup your mallet specific code | |
return mallet | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local Weapon = {} | |
-- Creates a new weapon object | |
-- @return the weapon object created | |
function Weapon.new(node, collider) | |
local weapon = {} | |
setmetatable(weapon, Weapon) | |
-- setup height, width, collider stuff, etc. here | |
return weapon | |
end | |
--an example function that will be common to all Weapons | |
-- Called when the weapon begins colliding with another node | |
-- @return nil | |
function Weapon:collide(node, dt, mtv_x, mtv_y) | |
if node.character then return end | |
if not node then return end | |
if node.die then | |
node:die(self.damage) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment