diff options
author | coadde [Márcio Alexandre Silva Delgado] <coadde@parabola.nu> | 2016-12-03 18:39:56 -0300 |
---|---|---|
committer | coadde [Márcio Alexandre Silva Delgado] <coadde@parabola.nu> | 2016-12-03 18:39:56 -0300 |
commit | ef5bce4721d1307200b1335565303a7832f77535 (patch) | |
tree | f1840a3e31dcf4cda066d5f377edb4ff2af31622 /src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts | |
parent | 1a9e17acb3a65a98305d19363f6b4e7185356c74 (diff) |
Keep the code more KISS - part 2
Diffstat (limited to 'src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts')
10 files changed, 130 insertions, 20 deletions
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/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/game/animation.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/animation.lua index 4f6688f..bcb32d1 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/update/animation.lua @@ -1,6 +1,4 @@ -local animationModule = {} - -function animationModule.animation(dt) +update.animation = function(dt) game = {} game.animation = function(metaSprites) metaSprites.elapsedTime = metaSprites.elapsedTime + dt @@ -30,5 +28,3 @@ function animationModule.animation(dt) end end end - -return animationModule 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/bola/gravity.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/scripts/update/gravity.lua index a8c927a..5242f90 100644 --- 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/update/gravity.lua @@ -1,6 +1,4 @@ -local gravityModule = {} - -function gravityModule.motion(dt) +update.gravity = function(dt) gravity(dt) end @@ -27,5 +25,3 @@ function gravity(dt) 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/update/limit.lua index 5bc2f2f..9df7079 100644 --- 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/update/limit.lua @@ -1,6 +1,4 @@ -local limitModule = {} - -function limitModule.motion(dt) +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 @@ -12,5 +10,3 @@ function limitModule.motion(dt) 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/update/motion.lua index c681ae2..80e5b50 100644 --- 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/update/motion.lua @@ -1,6 +1,4 @@ -local motionModule = {} - -function motionModule.motion(dt) +update.motion = function(dt) game.animation(character.bola.stand) quad = {} quad.bola = character.bola.stand[character.bola.stand.currentFrame] @@ -76,5 +74,3 @@ function walkDown(dt) game.animation(character.bola.walk) quad.bola = character.bola.walk[character.bola.walk.currentFrame] end - -return motionModule |