dosember-jam-2025/game/unit.lua

50 lines
1.1 KiB
Lua

BaseUnit = {}
BaseUnit.__index = BaseUnit
function BaseUnit:new(tilemap, x, y, size)
local this = {}
this.tilemap = tilemap
this.x = x
this.y = y
this.size = size or 16
this.sizeHalf = math.floor(this.size / 2) -- TODO: replace with Lua 5.3's integer thingies
return setmetatable(this, BaseUnit)
end
function BaseUnit:middlePoint()
return self.x + self.sizeHalf, self.y + self.sizeHalf
end
function BaseUnit:command(x, y, entity)
-- NOOP
end
function BaseUnit:draw()
-- NOOP
end
function BaseUnit:drawLimited(quad)
-- NOOP
end
function BaseUnit:__tostring()
return "BaseUnit(x=" .. self.x .. ", y=" .. self.y .. ")"
end
----------------------
SomeUnit = setmetatable({}, { __index = BaseUnit })
SomeUnit.__index = SomeUnit
local unitTexture = love.graphics.newImage("res/unit.png")
function SomeUnit:new(tilemap, x, y)
local this = BaseUnit:new(tilemap, x, y, 16)
return setmetatable(this, SomeUnit)
end
function SomeUnit:draw()
love.graphics.draw(unitTexture, self.x - self.tilemap.offsetX, self.y - self.tilemap.offsetY)
end