2021-05-05 08:30:32 +02:00
|
|
|
local Base = require "birb.modules.world.actors.actor2D"
|
2020-08-01 16:57:12 +02:00
|
|
|
local Parent = Base:extend()
|
|
|
|
|
|
|
|
function Parent:new(world, type, x, y, w, h, isSolid)
|
|
|
|
self.scene = world.scene
|
2021-05-07 19:23:34 +02:00
|
|
|
self.z = 0
|
2020-08-01 16:57:12 +02:00
|
|
|
Parent.super.new(self, world, type, x, y, w, h, isSolid)
|
2021-03-21 16:19:28 +01:00
|
|
|
self:initCharset()
|
|
|
|
self.drawDebugBox = false
|
2020-08-01 16:57:12 +02:00
|
|
|
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
|
|
|
|
|
2021-03-21 16:19:28 +01:00
|
|
|
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
|
2021-03-22 21:14:40 +01:00
|
|
|
self.isTurning = false
|
2021-04-10 12:01:47 +02:00
|
|
|
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
|
2021-04-18 11:03:34 +02:00
|
|
|
self.scissorSprite = false
|
|
|
|
self.groundHeight = 0
|
2021-03-21 16:19:28 +01:00
|
|
|
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)
|
2021-03-24 11:57:42 +01:00
|
|
|
y = y - 2
|
2021-04-10 12:01:47 +02:00
|
|
|
local z = math.floor(self.z)
|
2021-03-24 11:57:42 +01:00
|
|
|
|
2021-03-22 17:08:03 +01:00
|
|
|
love.graphics.setColor(1,1,1,0.5)
|
2021-04-18 11:03:34 +02:00
|
|
|
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()
|
2021-04-18 11:03:34 +02:00
|
|
|
|
|
|
|
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
|
2021-04-11 09:58:21 +02:00
|
|
|
self.charsetManager:drawStanding(self.charset, self.charId, self.charDir, x, y - z)
|
2021-04-10 14:26:38 +02:00
|
|
|
end
|
2021-03-22 21:14:40 +01:00
|
|
|
else
|
2021-04-10 14:26:38 +02:00
|
|
|
self.charsetManager:drawTurning(self.charset, self.charId, x, y - z, self.isFast)
|
2021-03-22 21:14:40 +01:00
|
|
|
end
|
2021-03-21 16:19:28 +01:00
|
|
|
end
|
2021-04-18 11:03:34 +02:00
|
|
|
|
|
|
|
if (self.scissorSprite) then
|
|
|
|
love.graphics.setScissor()
|
|
|
|
end
|
2021-03-21 16:19:28 +01:00
|
|
|
end
|
|
|
|
|
2020-08-01 16:57:12 +02:00
|
|
|
function Parent:draw()
|
2021-04-18 11:03:34 +02:00
|
|
|
if (self.drawDebugBox) then
|
|
|
|
love.graphics.rectangle("line", math.floor(self.x), math.floor(self.y), self.w, self.h)
|
|
|
|
end
|
2021-03-21 16:19:28 +01:00
|
|
|
if (self.charset ~= nil) then
|
|
|
|
self:drawCharset()
|
|
|
|
end
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return Parent
|