Skip to content

Instantly share code, notes, and snippets.

@jhoff
Forked from NimbusBP1729/weaponParentChild.lua
Created October 17, 2012 20:33
Show Gist options
  • Save jhoff/3907978 to your computer and use it in GitHub Desktop.
Save jhoff/3907978 to your computer and use it in GitHub Desktop.
weapon parent/child hierarchy
--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
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