Skip to content

Instantly share code, notes, and snippets.

@NimbusBP1729
Created November 3, 2012 03:04
Show Gist options
  • Save NimbusBP1729/4005662 to your computer and use it in GitHub Desktop.
Save NimbusBP1729/4005662 to your computer and use it in GitHub Desktop.
mace is a subclass of weapon
-----------------------------------------------
-- mace.lua
-- Represents a mace that a player can wield or pick up
-- Created by NimbusBP1729
-----------------------------------------------
local Weapon = require 'nodes/weapon'
local utils = require 'utils'
local Mace = {}
Mace.__index = Mace
Mace.isMace = true
-- Creates a new mace object
-- @return the battle mace object created
function Mace.new(node, collider, plyr, maceItem)
local mace = {}
setmetatable(mace, Mace)
--subclass Weapon methods and set defaults if not populated
mace = inherits(mace,Weapon)
--other code
return mace
end
--overrides Weapon:funcAlpha
function Mace:funcAlpha()
--doSomething
end
--inherits Weapon:funcBeta because it's omitted
--a function only for the mace
function Mace:funcGamma()
--do something else
end
return Mace
--child inherits the members of parent if child doesn't
-- have a member by the same name
function inherits(child,parent)
for k,v in pairs(parent) do
if not child[k] then
child[k] = v
end
end
for k,v in pairs(parent["__index"]) do
if not child[k] then
child[k] = v
end
end
return child
end
-----------------------------------------------
-- weapon.lua
-- Represents a generic weapon a player can wield or pick up
-- Created by NimbusBP1729
-----------------------------------------------
--all weapons inherit the following functions
-- and variables unless they're overridden
local Weapon = {}
Weapon.__index = Weapon
Weapon.isWeapon = true
Weapon.prime = 47
function Weapon:funcAlpha()
-- i do something
end
function Weapon:funcBeta()
-- i do something else
end
return Weapon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment