sonic-radiance/sonic-radiance.love/scenes/overworld/actors/parent.lua

90 lines
2.4 KiB
Lua
Raw Normal View History

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
2021-03-20 16:35:38 +01:00
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
2021-03-21 19:21:51 +01:00
self.cantTurn = false
self.isTurning = false
self.isFast = false
2021-04-10 14:26:38 +02:00
self.largeAnim = false
2021-04-10 18:28:52 +02:00
self.alwaysWalk = false
self.scissorSprite = false
self.groundHeight = 0
end
function Parent:setCharset(charset, charId, cantWalk)
self.charset = charset
self.charId = charId
self.cantWalk = (cantWalk == true)
end
function Parent:drawCharset(charset, charId)
2021-03-22 17:08:03 +01:00
local x, y = utils.math.floorCoord(self.x, self.y)
y = y - 2
local z = math.floor(self.z)
2021-03-22 17:08:03 +01:00
love.graphics.setColor(1,1,1,0.5)
if (self.groundHeight == 0) then
self.assets.images["shadow"]:draw(x + 1, y + 11)
end
2021-03-22 17:08:03 +01:00
utils.graphics.resetColor()
if (self.scissorSprite) then
local _, camy = self.world.cameras:getViewCoordinate(1)
local viewy = math.floor((self.y + self.h - self.groundHeight) - camy)
love.graphics.setScissor(0, 0, 424, viewy)
end
2021-04-10 14:26:38 +02:00
if (self.largeAnim) then
self.charsetManager:drawLargeAnim(self.charset, self.charId, self.charDir, x, y - z, self.isFast)
else
if (not self.isTurning) then
2021-04-10 18:28:52 +02:00
if ((self:isMoving() and (not self.cantWalk)) or self.alwaysWalk) then
2021-04-10 14:26:38 +02:00
self.charsetManager:drawMoving(self.charset, self.charId, self.charDir, x, y - z, self.isFast)
else
self.charsetManager:drawStanding(self.charset, self.charId, self.charDir, x, y - z)
2021-04-10 14:26:38 +02:00
end
else
2021-04-10 14:26:38 +02:00
self.charsetManager:drawTurning(self.charset, self.charId, x, y - z, self.isFast)
end
end
if (self.scissorSprite) then
love.graphics.setScissor()
end
end
function Parent:draw()
if (self.drawDebugBox) then
love.graphics.rectangle("line", math.floor(self.x), math.floor(self.y), self.w, self.h)
end
if (self.charset ~= nil) then
self:drawCharset()
end
end
return Parent