I don’t understand classes. Looked at the animal, dog example… umm i guess im a bit dumb
I want to make a building superclass and a bunch of subclasses like farm, house, barracks, wall and town center. Heres one of my attempts to make a barracks class, but im not knowing how to design the code so that it works or call the building class methods from the barracks class
Building = class()
function Building:makeFoundation(x,y,size,player)
end
function Building:addHP(add1,add2)
-- Call this method whenever an event should change the hit points of a building
if add2 then
local m = get_percent(hp1,hp2)
self.hp1 = self.hp1 + hp2 * m/100
self.hp2 = self.hp2 + add2
end
if add1 then
self.hp = self.hp + hp1
end
end
function Building:addArmor(a1, a2) --armor types MELEE
if a1 then
self.armor1 = self.armor1 + a1
end
if a2 then
self.armor2 = self.armor2 + a2
end
end
function Building:select()
-- select building
end
Barracks = class(Building)
local __size = 3.0
local __cost1 = 125
local __buildTime = 30
function Barracks:init(x,y,hp,player)
if hp == 1 then
self:makeFoundation(x,y,__size,player)
else
end
self.hp1 = hp --active hit points
self.hp2 = hp --max Hit Points
self.player = player
self.armor1 = 5
self.armor2 = 10
self.attack = nil
self.range = nil
self.queue = {}
end
function Barracks:addUnitToQueue()
end