From ef5bce4721d1307200b1335565303a7832f77535 Mon Sep 17 00:00:00 2001 From: "coadde [Márcio Alexandre Silva Delgado]" Date: Sat, 3 Dec 2016 18:39:56 -0300 Subject: Keep the code more KISS - part 2 --- .../scripts/bola/gravity.lua | 31 --------- .../scripts/bola/limit.lua | 16 ----- .../scripts/bola/motion.lua | 80 ---------------------- .../scripts/draw/default.lua | 28 ++++++++ .../scripts/game/animation.lua | 34 --------- .../scripts/keypressed/default.lua | 29 ++++++++ .../scripts/keyreleased/default.lua | 33 +++++++++ .../scripts/load/default.lua | 18 +++++ .../scripts/update/animation.lua | 30 ++++++++ .../scripts/update/default.lua | 15 ++++ .../scripts/update/fps.lua | 3 + .../scripts/update/gravity.lua | 27 ++++++++ .../scripts/update/limit.lua | 12 ++++ .../scripts/update/motion.lua | 76 ++++++++++++++++++++ 14 files changed, 271 insertions(+), 161 deletions(-) delete mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/gravity.lua delete mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/limit.lua delete mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/motion.lua create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/draw/default.lua delete mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/game/animation.lua create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/keypressed/default.lua create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/keyreleased/default.lua create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/load/default.lua create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/animation.lua create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/default.lua create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/fps.lua create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/gravity.lua create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/limit.lua create mode 100644 src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/motion.lua (limited to 'src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts') diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/gravity.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/gravity.lua deleted file mode 100644 index a8c927a..0000000 --- a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/gravity.lua +++ /dev/null @@ -1,31 +0,0 @@ -local gravityModule = {} - -function gravityModule.motion(dt) - gravity(dt) -end - -function gravity(dt) - if character.bola.jump.velocity ~= 0 then - character.bola.jump.isJumping = true - character.bola.position.y = character.bola.position.y + (character.bola.jump.velocity * dt) - character.bola.jump.velocity = character.bola.jump.velocity - (character.bola.gravity * dt) - end - - if character.bola.position.y > character.bola.jump.ground then - character.bola.jump.velocity = 0 - character.bola.position.y = character.bola.jump.ground - character.bola.jump.higher = character.bola.jump.higherMax - - character.bola.jump.limitButtonJump = false - character.bola.jump.isJumping = false - character.bola.actionA = false - - if love.keyboard.isScancodeDown(button.up) then - character.bola.actionUp = true - elseif love.keyboard.isScancodeDown(button.down) then - character.bola.actionDown = true - end - end -end - -return gravityModule diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/limit.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/limit.lua deleted file mode 100644 index 5bc2f2f..0000000 --- a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/limit.lua +++ /dev/null @@ -1,16 +0,0 @@ -local limitModule = {} - -function limitModule.motion(dt) - if character.bola.position.x <= character.bola.origin.x then - character.bola.position.x = character.bola.origin.x - elseif character.bola.position.x >= windowProfile.mode.width - character.bola.origin.x then - character.bola.position.x = windowProfile.mode.width - character.bola.origin.x - end - if character.bola.position.y <= character.bola.origin.y then - character.bola.position.y = character.bola.origin.y - elseif character.bola.position.y >= windowProfile.mode.height - character.bola.origin.y then - character.bola.position.y = windowProfile.mode.height - character.bola.origin.y - end -end - -return limitModule 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 deleted file mode 100644 index c681ae2..0000000 --- a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/bola/motion.lua +++ /dev/null @@ -1,80 +0,0 @@ -local motionModule = {} - -function motionModule.motion(dt) - game.animation(character.bola.stand) - quad = {} - quad.bola = character.bola.stand[character.bola.stand.currentFrame] - - if character.bola.jump.higher > 0 and character.bola.actionA == true then - jump(dt) - end - - if character.bola.actionLeft == true and character.bola.actionRight == false then - walkLeft(dt) - end - - if character.bola.actionRight == true and character.bola.actionLeft == false then - walkRight(dt) - end - - if character.bola.actionLeft == true and character.bola.actionRight == true then - stand(dt) - end - - if character.bola.actionUp == true and character.bola.actionDown == false then - walkUp(dt) - end - - if character.bola.actionDown == true and character.bola.actionUp == false then - walkDown(dt) - end - - if character.bola.actionUp == true and character.bola.actionDown == true then - stand(dt) - end -end - -function jump(dt) - if character.bola.jump.limitButtonJump == false then - character.bola.jump.higher = character.bola.jump.higher - dt - character.bola.jump.velocity = character.bola.jump.velocity + character.bola.jump.height * (dt / character.bola.jump.higherMax) - - -- game.animation(character.bola.jump) - -- quad.bola = character.bola.jump[character.bola.jump.currentFrame] - end -end - -function stand(dt) - game.animation(character.bola.stand) - quad.bola = character.bola.stand[character.bola.stand.currentFrame] -end - -function walkLeft(dt) - character.bola.position.x = character.bola.position.x - (character.bola.velocity * dt) - game.animation(character.bola.walk) - quad.bola = character.bola.walk[character.bola.walk.currentFrame] - character.bola.scale.x = -1 -end - -function walkRight(dt) - character.bola.position.x = character.bola.position.x + (character.bola.velocity * dt) - game.animation(character.bola.walk) - quad.bola = character.bola.walk[character.bola.walk.currentFrame] - character.bola.scale.x = 1 -end - -function walkUp(dt) - character.bola.position.y = character.bola.position.y - (character.bola.velocity * dt) - character.bola.jump.ground = character.bola.position.y - game.animation(character.bola.walk) - quad.bola = character.bola.walk[character.bola.walk.currentFrame] -end - -function walkDown(dt) - character.bola.position.y = character.bola.position.y + (character.bola.velocity * dt) - character.bola.jump.ground = character.bola.position.y - game.animation(character.bola.walk) - quad.bola = character.bola.walk[character.bola.walk.currentFrame] -end - -return motionModule diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/draw/default.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/draw/default.lua new file mode 100644 index 0000000..a13244a --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/draw/default.lua @@ -0,0 +1,28 @@ +main.draw = function() + local currentTime = love.timer.getTime() + if nextTime <= currentTime then + nextTime = currentTime + return + end + love.timer.sleep(nextTime - currentTime) + + love.graphics.scale(windowProfile.scale.x, windowProfile.scale.y) + + love.graphics.print('FPS: ' .. love.timer.getFPS(), 0, 0) + + draw = { + bola = love.graphics.draw( + metaSprites.bola.image, + quad.bola, + character.bola.position.x, + character.bola.position.y, + character.bola.orientation, + character.bola.scale.x, + character.bola.scale.y, + character.bola.origin.x, + character.bola.origin.y + ) + } +-- bolaDraw.motion() +-- game.draw(metaSprites.bola, quad.bola, character.bola) +end 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 deleted file mode 100644 index 4f6688f..0000000 --- a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/game/animation.lua +++ /dev/null @@ -1,34 +0,0 @@ -local animationModule = {} - -function animationModule.animation(dt) - game = {} - game.animation = function(metaSprites) - metaSprites.elapsedTime = metaSprites.elapsedTime + dt - if metaSprites.elapsedTime > (1 / metaSprites.fps) then ---[[ if metaSprites.loop > 0 then - if loopCounter == nil then - metaSprites.currentFrame = 1 - loopCounter = 1 - elseif loopCounter < loop then - metaSprites.currentFrame = 1 - loopCounter = loopCounter + 1 - else - metaSprites.currentFrame = # metaSprites - end - elseif metaSprites.loop == 0 or metaSprites.loop == false then - metaSprites.currentFrame = # metaSprites - elseif metaSprites.loop == -1 or metaSprites.loop == true then - metaSprites.currentFrame = 1 - end -]] - if metaSprites.currentFrame < # metaSprites then - metaSprites.currentFrame = metaSprites.currentFrame + 1 - else - metaSprites.currentFrame = 1 - end - metaSprites.elapsedTime = 0 - end - end -end - -return animationModule diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/keypressed/default.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/keypressed/default.lua new file mode 100644 index 0000000..ccf4d3b --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/keypressed/default.lua @@ -0,0 +1,29 @@ +main.keypressed = function(key, scancode, isrepeat) + isrepeat = true + + if scancode == button.quit then + love.event.quit() + end + + if scancode == button.a then + character.bola.actionA = true + character.bola.actionDown = false + character.bola.actionUp = false + end + + if scancode == button.left then + character.bola.actionLeft = true + end + + if scancode == button.right then + character.bola.actionRight = true + end + + if scancode == button.up and character.bola.jump.isJumping == false then + character.bola.actionUp = true + end + + if scancode == button.down and character.bola.jump.isJumping == false then + character.bola.actionDown = true + end +end diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/keyreleased/default.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/keyreleased/default.lua new file mode 100644 index 0000000..fa3bf6a --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/keyreleased/default.lua @@ -0,0 +1,33 @@ +main.keyreleased = function(key, scancode) + if scancode == button.a then + character.bola.actionA = false + end + + if scancode == button.left then + character.bola.actionLeft = false + end + + if scancode == button.right then + character.bola.actionRight = false + end + + if scancode == button.up then + character.bola.actionUp = false + end + + if scancode == button.down then + character.bola.actionDown = false + end + + if scancode == button.b then + character.bola.actionB = false + end + + if scancode == button.a then + character.bola.actionA = false + + if character.bola.jump.velocity ~= 0 then + character.bola.jump.limitButtonJump = true + end + end +end diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/load/default.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/load/default.lua new file mode 100644 index 0000000..31b8f9b --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/load/default.lua @@ -0,0 +1,18 @@ +main.load = function() + fps = 30 + upTime = love.timer.getTime() + nextTime = upTime + windowProfile = require 'scripts.window.profile' + + love.graphics.setBackgroundColor(0, 232, 216) + love.graphics.setDefaultFilter('nearest', 'nearest') + love.window.setMode(windowProfile.mode.width * windowProfile.scale.x, windowProfile.mode.height * windowProfile.scale.y) + love.window.setTitle(windowProfile.title) + + button = require 'scripts.player.1.button' + metaSprites = require 'scripts.meta_sprites' + + character = { + bola = require 'scripts.bola.default' + } +end diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/animation.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/animation.lua new file mode 100644 index 0000000..bcb32d1 --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/animation.lua @@ -0,0 +1,30 @@ +update.animation = function(dt) + game = {} + game.animation = function(metaSprites) + metaSprites.elapsedTime = metaSprites.elapsedTime + dt + if metaSprites.elapsedTime > (1 / metaSprites.fps) then +--[[ if metaSprites.loop > 0 then + if loopCounter == nil then + metaSprites.currentFrame = 1 + loopCounter = 1 + elseif loopCounter < loop then + metaSprites.currentFrame = 1 + loopCounter = loopCounter + 1 + else + metaSprites.currentFrame = # metaSprites + end + elseif metaSprites.loop == 0 or metaSprites.loop == false then + metaSprites.currentFrame = # metaSprites + elseif metaSprites.loop == -1 or metaSprites.loop == true then + metaSprites.currentFrame = 1 + end +]] + if metaSprites.currentFrame < # metaSprites then + metaSprites.currentFrame = metaSprites.currentFrame + 1 + else + metaSprites.currentFrame = 1 + end + metaSprites.elapsedTime = 0 + end + end +end diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/default.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/default.lua new file mode 100644 index 0000000..186ef03 --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/default.lua @@ -0,0 +1,15 @@ +update = {} + +require 'scripts.update.fps' +require 'scripts.update.animation' +require 'scripts.update.motion' +require 'scripts.update.gravity' +require 'scripts.update.limit' + +main.update = function(dt) + update.fps() + update.animation(dt) + update.motion(dt) + update.gravity(dt) + update.limit(dt) +end diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/fps.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/fps.lua new file mode 100644 index 0000000..f446902 --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/fps.lua @@ -0,0 +1,3 @@ +update.fps = function() + nextTime = nextTime + (1 / fps) +end diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/gravity.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/gravity.lua new file mode 100644 index 0000000..5242f90 --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/gravity.lua @@ -0,0 +1,27 @@ +update.gravity = function(dt) + gravity(dt) +end + +function gravity(dt) + if character.bola.jump.velocity ~= 0 then + character.bola.jump.isJumping = true + character.bola.position.y = character.bola.position.y + (character.bola.jump.velocity * dt) + character.bola.jump.velocity = character.bola.jump.velocity - (character.bola.gravity * dt) + end + + if character.bola.position.y > character.bola.jump.ground then + character.bola.jump.velocity = 0 + character.bola.position.y = character.bola.jump.ground + character.bola.jump.higher = character.bola.jump.higherMax + + character.bola.jump.limitButtonJump = false + character.bola.jump.isJumping = false + character.bola.actionA = false + + if love.keyboard.isScancodeDown(button.up) then + character.bola.actionUp = true + elseif love.keyboard.isScancodeDown(button.down) then + character.bola.actionDown = true + end + end +end diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/limit.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/limit.lua new file mode 100644 index 0000000..9df7079 --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/limit.lua @@ -0,0 +1,12 @@ +update.limit = function(dt) + if character.bola.position.x <= character.bola.origin.x then + character.bola.position.x = character.bola.origin.x + elseif character.bola.position.x >= windowProfile.mode.width - character.bola.origin.x then + character.bola.position.x = windowProfile.mode.width - character.bola.origin.x + end + if character.bola.position.y <= character.bola.origin.y then + character.bola.position.y = character.bola.origin.y + elseif character.bola.position.y >= windowProfile.mode.height - character.bola.origin.y then + character.bola.position.y = windowProfile.mode.height - character.bola.origin.y + end +end diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/motion.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/motion.lua new file mode 100644 index 0000000..80e5b50 --- /dev/null +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/motion.lua @@ -0,0 +1,76 @@ +update.motion = function(dt) + game.animation(character.bola.stand) + quad = {} + quad.bola = character.bola.stand[character.bola.stand.currentFrame] + + if character.bola.jump.higher > 0 and character.bola.actionA == true then + jump(dt) + end + + if character.bola.actionLeft == true and character.bola.actionRight == false then + walkLeft(dt) + end + + if character.bola.actionRight == true and character.bola.actionLeft == false then + walkRight(dt) + end + + if character.bola.actionLeft == true and character.bola.actionRight == true then + stand(dt) + end + + if character.bola.actionUp == true and character.bola.actionDown == false then + walkUp(dt) + end + + if character.bola.actionDown == true and character.bola.actionUp == false then + walkDown(dt) + end + + if character.bola.actionUp == true and character.bola.actionDown == true then + stand(dt) + end +end + +function jump(dt) + if character.bola.jump.limitButtonJump == false then + character.bola.jump.higher = character.bola.jump.higher - dt + character.bola.jump.velocity = character.bola.jump.velocity + character.bola.jump.height * (dt / character.bola.jump.higherMax) + + -- game.animation(character.bola.jump) + -- quad.bola = character.bola.jump[character.bola.jump.currentFrame] + end +end + +function stand(dt) + game.animation(character.bola.stand) + quad.bola = character.bola.stand[character.bola.stand.currentFrame] +end + +function walkLeft(dt) + character.bola.position.x = character.bola.position.x - (character.bola.velocity * dt) + game.animation(character.bola.walk) + quad.bola = character.bola.walk[character.bola.walk.currentFrame] + character.bola.scale.x = -1 +end + +function walkRight(dt) + character.bola.position.x = character.bola.position.x + (character.bola.velocity * dt) + game.animation(character.bola.walk) + quad.bola = character.bola.walk[character.bola.walk.currentFrame] + character.bola.scale.x = 1 +end + +function walkUp(dt) + character.bola.position.y = character.bola.position.y - (character.bola.velocity * dt) + character.bola.jump.ground = character.bola.position.y + game.animation(character.bola.walk) + quad.bola = character.bola.walk[character.bola.walk.currentFrame] +end + +function walkDown(dt) + character.bola.position.y = character.bola.position.y + (character.bola.velocity * dt) + character.bola.jump.ground = character.bola.position.y + game.animation(character.bola.walk) + quad.bola = character.bola.walk[character.bola.walk.currentFrame] +end -- cgit v1.2.3-54-g00ecf