34 lines
977 B
Lua
34 lines
977 B
Lua
--- @class Graphics
|
|
--- @field owner Character
|
|
--- @field animation Animation
|
|
local graphics = {}
|
|
graphics.__index = graphics
|
|
|
|
--- @param id Id
|
|
--- @param spriteDir table
|
|
local function new(id, spriteDir)
|
|
return setmetatable({
|
|
id = id,
|
|
animation = (require 'lib.character.animation').new(id, spriteDir)
|
|
}, graphics)
|
|
end
|
|
|
|
function graphics:update(dt)
|
|
self.animation.animationTable[self.owner:getState()]:update(dt)
|
|
end
|
|
|
|
function graphics:draw()
|
|
local ppm = Tree.level.camera.pixelsPerMeter
|
|
local position = self.owner.logic.mapLogic.displayedPosition
|
|
local state = self.owner:getState()
|
|
|
|
if Tree.level.selector.id == self.owner.id then love.graphics.setColor(0.5, 1, 0.5) end
|
|
|
|
self.animation.animationTable[state]:draw(Tree.assets.files.sprites.character[state],
|
|
position.x + 0.5,
|
|
position.y + 0.5, nil, 1 / ppm * self.animation.side, 1 / ppm, 38, 47)
|
|
love.graphics.setColor(1, 1, 1)
|
|
end
|
|
|
|
return { new = new }
|