From 582008da7dda5ce3ca99482a9d6dae7273a6b3f8 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 10 Apr 2021 11:59:32 +0200 Subject: [PATCH] feat: add a fast frame system for characterset --- .../scenes/overworld/charsetmanager.lua | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/sonic-radiance.love/scenes/overworld/charsetmanager.lua b/sonic-radiance.love/scenes/overworld/charsetmanager.lua index 71d975e..1a532d6 100644 --- a/sonic-radiance.love/scenes/overworld/charsetmanager.lua +++ b/sonic-radiance.love/scenes/overworld/charsetmanager.lua @@ -6,6 +6,7 @@ local directionList = {"down", "right", "up", "left"} local CHARWIDTH = 38 local CHARHEIGHT = 48 +local FAST_BOOST = 2.5 function Charset:new(scene) self.char = {} @@ -18,11 +19,13 @@ function Charset:new(scene) end end self.currentFrame = 0 + self.fastFrame = 0 end function Charset:update(dt) if (core.screen:isActive()) then self.currentFrame = ((self.currentFrame + (dt*5)) % 4) + self.fastFrame = ((self.fastFrame + (dt*5*FAST_BOOST)) % 4) end end @@ -54,10 +57,14 @@ function Charset:addTexture(charsetName) self.list[charsetName] = love.graphics.newImage(folder .. charsetName .. ".png") end -function Charset:getRunningFrame(charID, direction) +function Charset:getRunningFrame(charID, direction, isFast) + local frame = self.currentFrame + if (isFast == true) then + frame = self.fastFrame + end local char = self.char[charID] local animatedDirection = char[direction] - local fakeFrame = math.min(math.floor(self.currentFrame) + 1, 4) + local fakeFrame = math.min(math.floor(frame) + 1, 4) local trueFrame = animation[fakeFrame] return animatedDirection[trueFrame] end @@ -68,9 +75,9 @@ function Charset:getStandingFrame(charID, direction) return animatedDirection[2] end -function Charset:draw(charsetName, charID, direction, x, y) +function Charset:draw(charsetName, charID, direction, x, y, isFast) local drawable = self:getTexture(charsetName) - local quad = self:getRunningFrame(charID, direction) + local quad = self:getRunningFrame(charID, direction, isFast) love.graphics.draw(drawable, quad, math.floor(x), math.floor(y), 0, 1, 1, 11, 32) end @@ -80,8 +87,12 @@ function Charset:drawStanding(charsetName, charID, direction, x, y) love.graphics.draw(drawable, quad, math.floor(x), math.floor(y), 0, 1, 1, 11, 32) end -function Charset:drawTurning(charsetName, charID, x, y) - local dir = math.min(math.floor(self.currentFrame) + 1, 4) +function Charset:drawTurning(charsetName, charID, x, y, isFast) + local frame = self.currentFrame + if (isFast == true) then + frame = self.fastFrame + end + local dir = math.min(math.floor(frame) + 1, 4) return self:drawStanding(charsetName, charID, directionList[dir], x, y) end