diff options
Diffstat (limited to 'src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/game/animation.lua')
-rw-r--r-- | src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/game/animation.lua | 65 |
1 files changed, 45 insertions, 20 deletions
diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/game/animation.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/game/animation.lua index ff5293d..e0e98a0 100644 --- a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/game/animation.lua +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/game/animation.lua @@ -1,28 +1,53 @@ game.animation = function(character, dt) - character.elapsedTime = character.elapsedTime + dt - if character.elapsedTime > (1 / character.fps) then ---[[ - if character.loop > 0 then - if loopCounter == nil then - character.currentFrame = 1 - loopCounter = 1 - elseif loopCounter < loop then - character.currentFrame = 1 - loopCounter = loopCounter + 1 +-- frameRestart = 0 + local frameStart = function() + character.currentFrame = 1 + end + local frameCounter = function() +--[[ if character.restart == true then + character.currentFrame = character.currentFrame + 1 - frameRestart + else]] + character.currentFrame = character.currentFrame + 1 +-- end + end + local animationStart = function() + character.elapsedTime = character.elapsedTime + dt + end + local animationCounter = function(value) + if character.elapsedTime >= (1 / character.fps) then + character.elapsedTime = character.elapsedTime - (1 / character.fps) + if character.currentFrame == # character then + frameStart() + if value == 'start' then + loopCounter = 1 + elseif value == 'counter' then + loopCounter = loopCounter + 1 + end else - character.currentFrame = # character + frameCounter() end - elseif character.loop == 0 or character.loop == false then - character.currentFrame = # character - elseif character.loop == -1 or character.loop == true then - character.currentFrame = 1 end -]] - if character.currentFrame < # character then - character.currentFrame = character.currentFrame + 1 + end + local animationEnd = function() + character.elapsedTime = 0 + end + + if type(character.loop) == 'number' and character.loop > 0 then + if loopCounter == nil then + animationStart() + animationCounter('start') + elseif loopCounter < character.loop then + animationStart() + animationCounter('counter') else - character.currentFrame = 1 + animationEnd() + frameStart() end - character.elapsedTime = 0 + elseif character.loop == 0 or character.loop == false then + animationEnd() + frameStart() + elseif character.loop == -1 or character.loop == true then + animationStart() + animationCounter() end end |