diff options
author | Jorge Lopez Seijas <jorginho@riseup.net> | 2016-11-23 21:41:51 +0100 |
---|---|---|
committer | Jorge Lopez Seijas <jorginho@riseup.net> | 2016-11-23 21:44:39 +0100 |
commit | 582cc62b4a314ebdb223cab08c032fbdd546ee1c (patch) | |
tree | 3a3f17296085bd14fc5e575f9a1e38d3873ec1b8 | |
parent | 5d0bd6f795f87641696bf84c7183404958cf45b4 (diff) |
Modularize bola motion (bolaMotion) in scripts/bola/motion.lua
-rw-r--r-- | src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua | 33 | ||||
-rw-r--r-- | src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/motion.lua | 52 |
2 files changed, 55 insertions, 30 deletions
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 cab3b73..74b873f 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 @@ -25,6 +25,8 @@ function love.load() character = { bola = require 'scripts.bola.bola' } + + bolaMotion= require 'scripts.bola.motion' end function love.keypressed(key) @@ -63,36 +65,7 @@ function love.update(dt) } } - if love.keyboard.isDown(button.left) then - character.bola.acceleration = character.bola.acceleration + dt - if character.bola.position.x >= character.bola.origin.x then - if character.bola.acceleration < 3 then - character.bola.position.x = character.bola.position.x - (character.bola.speed * dt) - character.bola.acceleration - else - character.bola.position.x = character.bola.position.x - (character.bola.speed * dt) - 3 - end - end - quad = character.bola.walk[math.floor(character.bola.walk.start)] - character.bola.scale.x = -1 - elseif love.keyboard.isDown(button.right) then - character.bola.acceleration = character.bola.acceleration + dt - if character.bola.position.x <= windowProfile.mode.width - character.bola.origin.x then - if character.bola.acceleration < 3 then - character.bola.position.x = character.bola.position.x + (character.bola.speed * dt) + character.bola.acceleration - else - character.bola.position.x = character.bola.position.x + (character.bola.speed * dt) + 3 - end - end - quad = character.bola.walk[math.floor(character.bola.walk.start)] - character.bola.scale.x = 1 - elseif love.keyboard.isDown(button.down) then - character.bola.acceleration = 0 - transform.bola.origin.y = character.bola.origin.y - character.bola.origin.y - quad = character.bola.crouch[1] - else - character.bola.acceleration = 0 - quad = character.bola.stand[math.floor(character.bola.stand.start)] - end + bolaMotion.motion(dt) end function love.draw() diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/motion.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/motion.lua new file mode 100644 index 0000000..caf602b --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/motion.lua @@ -0,0 +1,52 @@ +local motionModule = {} + +function motionModule.motion(dt) + if love.keyboard.isDown(button.left) then + left(dt) + elseif love.keyboard.isDown(button.right) then + right(dt) + elseif love.keyboard.isDown(button.down) then + down(dt) + else + stand(dt) + end +end + +function left(dt) + character.bola.acceleration = character.bola.acceleration + dt + if character.bola.position.x >= character.bola.origin.x then + if character.bola.acceleration < 3 then + character.bola.position.x = character.bola.position.x - (character.bola.speed * dt) - character.bola.acceleration + else + character.bola.position.x = character.bola.position.x - (character.bola.speed * dt) - 3 + end + end + quad = character.bola.walk[math.floor(character.bola.walk.start)] + character.bola.scale.x = -1 +end + +function right(dt) + character.bola.acceleration = character.bola.acceleration + dt + if character.bola.position.x <= windowProfile.mode.width - character.bola.origin.x then + if character.bola.acceleration < 3 then + character.bola.position.x = character.bola.position.x + (character.bola.speed * dt) + character.bola.acceleration + else + character.bola.position.x = character.bola.position.x + (character.bola.speed * dt) + 3 + end + end + quad = character.bola.walk[math.floor(character.bola.walk.start)] + character.bola.scale.x = 1 +end + +function down(dt) + character.bola.acceleration = 0 + transform.bola.origin.y = character.bola.origin.y - character.bola.origin.y + quad = character.bola.crouch[1] +end + +function stand(dt) + character.bola.acceleration = 0 + quad = character.bola.stand[math.floor(character.bola.stand.start)] +end + +return motionModule |