From 06ac50db0f813a2954651600760f6ff30c6fd5d1 Mon Sep 17 00:00:00 2001 From: André Fabian Silva Delgado Date: Wed, 23 Nov 2016 23:03:47 -0300 Subject: Modularize bola animation (bolaAnimation) in scripts/bola/animation.lua --- .../main.lua | 27 +++----------------- .../scripts/bola/animation.lua | 29 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/animation.lua (limited to 'src') diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua index e47c5dd..9da062d 100644 --- a/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua @@ -26,7 +26,8 @@ function love.load() bola = require 'scripts.bola.bola' } - bolaMotion= require 'scripts.bola.motion' + bolaAnimation = require 'scripts.bola.animation' + bolaMotion = require 'scripts.bola.motion' end function love.keypressed(key) @@ -38,29 +39,7 @@ end function love.update(dt) nextTime = nextTime + (1 / fps) - character.bola.stand.start = character.bola.stand.start + (dt * character.bola.stand.fps) - character.bola.walk.start = character.bola.walk.start + (dt * character.bola.walk.fps) - - frames = { - bola = require 'scripts.bola.frames' - } - - game = { - animation = function(start, frames) - if math.floor(start) > frames then - start = 1 - end - return start - end - } - - character.bola.stand.start = game.animation(character.bola.stand.start, frames.bola.stand) - character.bola.walk.start = game.animation(character.bola.walk.start, frames.bola.walk) - - transform = { - bola = require 'scripts.bola.transform' - } - + bolaAnimation.animation(dt) bolaMotion.motion(dt) end diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/animation.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/animation.lua new file mode 100644 index 0000000..bd1e8de --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/animation.lua @@ -0,0 +1,29 @@ +local animationModule = {} + +function animationModule.animation(dt) + character.bola.stand.start = character.bola.stand.start + (dt * character.bola.stand.fps) + character.bola.walk.start = character.bola.walk.start + (dt * character.bola.walk.fps) + + frames = { + bola = require 'scripts.bola.frames' + } + + game = { + animation = function(start, frames) + if math.floor(start) > frames then + start = 1 + end + return start + end + } + + character.bola.stand.start = game.animation(character.bola.stand.start, frames.bola.stand) + character.bola.walk.start = game.animation(character.bola.walk.start, frames.bola.walk) + + transform = { + bola = require 'scripts.bola.transform' + } + +end + +return animationModule -- cgit v1.2.3-54-g00ecf