summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Fabian Silva Delgado <emulatorman@parabola.nu>2016-12-15 02:56:00 -0300
committerAndré Fabian Silva Delgado <emulatorman@parabola.nu>2016-12-15 02:56:35 -0300
commit9150595ca9f7380a2cd0f3333ac5d978e0cb63ef (patch)
tree856403c9033858a6506cdffed14d9265a36d9af4
parented12f36695b2c30bf2f9fd77c71fcdcbc402e324 (diff)
Keep the code KISS
-rw-r--r--src/gnu_and_bola_brawlers/keypressed/trigger.lua32
-rw-r--r--src/gnu_and_bola_brawlers/keyreleased/trigger.lua37
-rw-r--r--src/gnu_and_bola_brawlers/load/initialize.lua3
-rw-r--r--src/gnu_and_bola_brawlers/main.lua71
4 files changed, 76 insertions, 67 deletions
diff --git a/src/gnu_and_bola_brawlers/keypressed/trigger.lua b/src/gnu_and_bola_brawlers/keypressed/trigger.lua
new file mode 100644
index 0000000..abba1cc
--- /dev/null
+++ b/src/gnu_and_bola_brawlers/keypressed/trigger.lua
@@ -0,0 +1,32 @@
+local keypressed = {}
+
+keypressed.trigger = function(character, images, metaSprite, controller, key, scancode)
+ if scancode == controller.quit then
+ love.event.quit()
+ end
+
+ if scancode == controller.a then
+ character.actionA = true
+ character.actionDown = false
+ character.actionUp = false
+ metaSprite = require 'jump'
+ end
+
+ if scancode == controller.left then
+ character.actionLeft = true
+ end
+
+ if scancode == controller.right then
+ character.actionRight = true
+ end
+
+ if scancode == controller.up and character.jump.isJumping == false then
+ character.actionUp = true
+ end
+
+ if scancode == controller.down and character.jump.isJumping == false then
+ character.actionDown = true
+ end
+end
+
+return keypressed
diff --git a/src/gnu_and_bola_brawlers/keyreleased/trigger.lua b/src/gnu_and_bola_brawlers/keyreleased/trigger.lua
new file mode 100644
index 0000000..7295131
--- /dev/null
+++ b/src/gnu_and_bola_brawlers/keyreleased/trigger.lua
@@ -0,0 +1,37 @@
+local keyreleased = {}
+
+keyreleased.trigger = function(character, key, controller, scancode)
+ if scancode == controller.a then
+ character.actionA = false
+ end
+
+ if scancode == controller.left then
+ character.actionLeft = false
+ end
+
+ if scancode == controller.right then
+ character.actionRight = false
+ end
+
+ if scancode == controller.up then
+ character.actionUp = false
+ end
+
+ if scancode == controller.down then
+ character.actionDown = false
+ end
+
+ if scancode == controller.b then
+ character.actionB = false
+ end
+
+ if scancode == controller.a then
+ character.actionA = false
+
+ if character.jump.velocity ~= 0 then
+ character.jump.limitButtonJump = true
+ end
+ end
+end
+
+return keyreleased
diff --git a/src/gnu_and_bola_brawlers/load/initialize.lua b/src/gnu_and_bola_brawlers/load/initialize.lua
index 49582b1..bbf5c02 100644
--- a/src/gnu_and_bola_brawlers/load/initialize.lua
+++ b/src/gnu_and_bola_brawlers/load/initialize.lua
@@ -1,4 +1,3 @@
-
local load = {}
load.initialize = function()
@@ -14,7 +13,7 @@ load.initialize = function()
love.window.setMode(windowProfile.mode.width * windowProfile.scale.x, windowProfile.mode.height * windowProfile.scale.y)
love.window.setTitle(windowProfile.title)
- playerController = require 'load/player_controller_configuration'
+ controller = require 'load/player_controller_configuration'
images = require 'load/images'
character = require 'load/character'
diff --git a/src/gnu_and_bola_brawlers/main.lua b/src/gnu_and_bola_brawlers/main.lua
index a0e406f..c0acbc3 100644
--- a/src/gnu_and_bola_brawlers/main.lua
+++ b/src/gnu_and_bola_brawlers/main.lua
@@ -4,72 +4,13 @@ function love.load()
end
function love.keypressed(key, scancode)
- keypressed = function(character, images, metaSprite, controller, key, scancode)
- if scancode == playerController.quit then
- love.event.quit()
- end
-
- if scancode == controller.a then
- character.actionA = true
- character.actionDown = false
- character.actionUp = false
- metaSprite = require 'jump'
- end
-
- if scancode == controller.left then
- character.actionLeft = true
- end
-
- if scancode == controller.right then
- character.actionRight = true
- end
-
- if scancode == controller.up and character.jump.isJumping == false then
- character.actionUp = true
- end
-
- if scancode == controller.down and character.jump.isJumping == false then
- character.actionDown = true
- end
- end
- keypressed(character.bola, images.bola, metaSprite.bola, playerController.player1, key, scancode)
+ keypressed = require 'keypressed/trigger'
+ keypressed.trigger(character.bola, images.bola, metaSprite.bola, controller.player1, key, scancode)
end
function love.keyreleased(key, scancode)
- keyreleased = function(character, key, controller, scancode)
- if scancode == controller.a then
- character.actionA = false
- end
-
- if scancode == controller.left then
- character.actionLeft = false
- end
-
- if scancode == controller.right then
- character.actionRight = false
- end
-
- if scancode == controller.up then
- character.actionUp = false
- end
-
- if scancode == controller.down then
- character.actionDown = false
- end
-
- if scancode == controller.b then
- character.actionB = false
- end
-
- if scancode == controller.a then
- character.actionA = false
-
- if character.jump.velocity ~= 0 then
- character.jump.limitButtonJump = true
- end
- end
- end
- keyreleased(character.bola, key, playerController.player1, scancode)
+ keyreleased = require 'keyreleased/trigger'
+ keyreleased.trigger(character.bola, key, controller.player1, scancode)
end
function love.update(dt)
@@ -153,9 +94,9 @@ function love.update(dt)
character.jump.isJumping = false
character.actionA = false
- if love.keyboard.isScancodeDown(playerController.player1.up) then
+ if love.keyboard.isScancodeDown(controller.player1.up) then
character.actionUp = true
- elseif love.keyboard.isScancodeDown(playerController.player1.down) then
+ elseif love.keyboard.isScancodeDown(controller.player1.down) then
character.actionDown = true
end
end