feat: add a fast frame system for characterset
This commit is contained in:
parent
7b5ec06509
commit
582008da7d
1 changed files with 17 additions and 6 deletions
|
@ -6,6 +6,7 @@ local directionList = {"down", "right", "up", "left"}
|
||||||
|
|
||||||
local CHARWIDTH = 38
|
local CHARWIDTH = 38
|
||||||
local CHARHEIGHT = 48
|
local CHARHEIGHT = 48
|
||||||
|
local FAST_BOOST = 2.5
|
||||||
|
|
||||||
function Charset:new(scene)
|
function Charset:new(scene)
|
||||||
self.char = {}
|
self.char = {}
|
||||||
|
@ -18,11 +19,13 @@ function Charset:new(scene)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.currentFrame = 0
|
self.currentFrame = 0
|
||||||
|
self.fastFrame = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function Charset:update(dt)
|
function Charset:update(dt)
|
||||||
if (core.screen:isActive()) then
|
if (core.screen:isActive()) then
|
||||||
self.currentFrame = ((self.currentFrame + (dt*5)) % 4)
|
self.currentFrame = ((self.currentFrame + (dt*5)) % 4)
|
||||||
|
self.fastFrame = ((self.fastFrame + (dt*5*FAST_BOOST)) % 4)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,10 +57,14 @@ function Charset:addTexture(charsetName)
|
||||||
self.list[charsetName] = love.graphics.newImage(folder .. charsetName .. ".png")
|
self.list[charsetName] = love.graphics.newImage(folder .. charsetName .. ".png")
|
||||||
end
|
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 char = self.char[charID]
|
||||||
local animatedDirection = char[direction]
|
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]
|
local trueFrame = animation[fakeFrame]
|
||||||
return animatedDirection[trueFrame]
|
return animatedDirection[trueFrame]
|
||||||
end
|
end
|
||||||
|
@ -68,9 +75,9 @@ function Charset:getStandingFrame(charID, direction)
|
||||||
return animatedDirection[2]
|
return animatedDirection[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
function Charset:draw(charsetName, charID, direction, x, y)
|
function Charset:draw(charsetName, charID, direction, x, y, isFast)
|
||||||
local drawable = self:getTexture(charsetName)
|
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)
|
love.graphics.draw(drawable, quad, math.floor(x), math.floor(y), 0, 1, 1, 11, 32)
|
||||||
end
|
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)
|
love.graphics.draw(drawable, quad, math.floor(x), math.floor(y), 0, 1, 1, 11, 32)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Charset:drawTurning(charsetName, charID, x, y)
|
function Charset:drawTurning(charsetName, charID, x, y, isFast)
|
||||||
local dir = math.min(math.floor(self.currentFrame) + 1, 4)
|
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)
|
return self:drawStanding(charsetName, charID, directionList[dir], x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue