function health(class)
if class == 'wizard' then
return 80
elseif class == 'warrior' then
return 100
end
end
function mana(class)
if class == 'wizard' then
return 100
elseif class == 'warrior' then
return 80
end
end
function healthPool(class)
if class == 'wizard' then
return 80
elseif class == 'warrior' then
return 100
end
end
function manaPool(class)
if class == 'wizard' then
return 100
elseif class == 'warrior' then
return 80
end
end
return function(class)
speed = 100,
x = 50,
y = 50,
health = health(class),
mana = mana(class),
health_pool = healthPool(class),
mana_pool = manaPool(class)
}
end
Basically health, mana, health_pool, and mana_pool are attributes dependent on the class type (ie. wizard or warrior)
local defs = require('game.defs')
-- note: no stats/values hard-coded below
local function createCharacter(classname, x,y)
local t = { x=x, y=y }
for k,v in pairs(defs[classname]) do
t[k] = v
end
return t
end
Like Raiho said, the next step might be to introduce inheritance (possibly using metatables).