sonic-radiance/sonic-radiance.love/scenes/overworld/actors/parent.lua
2021-03-22 17:08:03 +01:00

60 lines
1.5 KiB
Lua

local Base = require "core.modules.world.actors.actor2D"
local Parent = Base:extend()
function Parent:new(world, type, x, y, w, h, isSolid)
self.scene = world.scene
Parent.super.new(self, world, type, x, y, w, h, isSolid)
self:initCharset()
self.drawDebugBox = false
end
function Parent:update(dt)
self.depth = -self.y
Parent.super.update(self, dt)
self.depth = -self.y
end
function Parent:isMoving()
return ((math.abs(self.ysp) > 0.01) or (math.abs(self.xsp) > 0.01))
end
-- Charset / Draw functions
-- Handle the charset of an object
function Parent:initCharset()
self.charsetManager = self.world.scene.charsetManager
self.charset = nil
self.charDir = "down"
self.cantWalk = false
self.cantTurn = false
end
function Parent:setCharset(charset, charId, cantWalk)
self.charset = charset
self.charId = charId
self.cantWalk = (cantWalk == true)
end
function Parent:drawCharset(charset, charId)
local x, y = utils.math.floorCoord(self.x, self.y)
love.graphics.setColor(1,1,1,0.5)
self.assets.images["shadow"]:draw(x + 1, y + 10)
utils.graphics.resetColor()
if (self:isMoving() and (not self.cantWalk)) then
self.charsetManager:draw(self.charset, self.charId, self.charDir, x, y - 1)
else
self.charsetManager:drawStanding(self.charset, self.charId, self.charDir, x, y - 1)
end
end
function Parent:draw()
if (self.charset ~= nil) then
self:drawCharset()
else
if (self.drawDebugBox) then
love.graphics.rectangle("line", math.floor(self.x), math.floor(self.y), self.w, self.h)
end
end
end
return Parent