Created
November 3, 2012 03:04
-
-
Save NimbusBP1729/4005662 to your computer and use it in GitHub Desktop.
mace is a subclass of weapon
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
----------------------------------------------- | |
-- 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 |
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
--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 |
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
----------------------------------------------- | |
-- 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