From c40d8c52960539cd14ba33e68810fbc6a16e7fd4 Mon Sep 17 00:00:00 2001 From: Jorge Lopez Seijas Date: Thu, 15 Dec 2016 20:37:56 +0100 Subject: Keep the code KISS 2 --- src/gnu_and_bola_brawlers/draw/default.lua | 33 ++++++++++++++++++++ src/gnu_and_bola_brawlers/draw/draw.lua | 33 ++++++++++++++++++++ src/gnu_and_bola_brawlers/keypressed/default.lua | 32 ++++++++++++++++++++ src/gnu_and_bola_brawlers/keypressed/trigger.lua | 32 -------------------- src/gnu_and_bola_brawlers/keyreleased/default.lua | 37 +++++++++++++++++++++++ src/gnu_and_bola_brawlers/keyreleased/trigger.lua | 37 ----------------------- src/gnu_and_bola_brawlers/load/default.lua | 25 +++++++++++++++ src/gnu_and_bola_brawlers/load/initialize.lua | 25 --------------- src/gnu_and_bola_brawlers/main.lua | 34 ++++----------------- 9 files changed, 166 insertions(+), 122 deletions(-) create mode 100644 src/gnu_and_bola_brawlers/draw/default.lua create mode 100644 src/gnu_and_bola_brawlers/draw/draw.lua create mode 100644 src/gnu_and_bola_brawlers/keypressed/default.lua delete mode 100644 src/gnu_and_bola_brawlers/keypressed/trigger.lua create mode 100644 src/gnu_and_bola_brawlers/keyreleased/default.lua delete mode 100644 src/gnu_and_bola_brawlers/keyreleased/trigger.lua create mode 100644 src/gnu_and_bola_brawlers/load/default.lua delete mode 100644 src/gnu_and_bola_brawlers/load/initialize.lua (limited to 'src') diff --git a/src/gnu_and_bola_brawlers/draw/default.lua b/src/gnu_and_bola_brawlers/draw/default.lua new file mode 100644 index 0000000..a497604 --- /dev/null +++ b/src/gnu_and_bola_brawlers/draw/default.lua @@ -0,0 +1,33 @@ +local draw = {} + +--Get current time and update several parameters (time, fps print...) +draw.refresh = 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) +end + +--Draw an object using base image and character data to position, scale, etc... +draw.object = function(images, character) + love.graphics.draw( + images[1], + images.quad, + character.position.x, + character.position.y, + character.orientation, + character.scale.x, + character.scale.y, + character.origin.x, + character.origin.y + ) +end + +return draw diff --git a/src/gnu_and_bola_brawlers/draw/draw.lua b/src/gnu_and_bola_brawlers/draw/draw.lua new file mode 100644 index 0000000..b2163ca --- /dev/null +++ b/src/gnu_and_bola_brawlers/draw/draw.lua @@ -0,0 +1,33 @@ +local draw = {} + +--Get current time and update several parameters (time, fps print...) +draw.refresh = 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) +end + +--Draw an object using base image and character data in order to position, scale, etc... +draw.object = function(images, character) + love.graphics.draw( + images[1], + images.quad, + character.position.x, + character.position.y, + character.orientation, + character.scale.x, + character.scale.y, + character.origin.x, + character.origin.y + ) +end + +return draw diff --git a/src/gnu_and_bola_brawlers/keypressed/default.lua b/src/gnu_and_bola_brawlers/keypressed/default.lua new file mode 100644 index 0000000..abba1cc --- /dev/null +++ b/src/gnu_and_bola_brawlers/keypressed/default.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/keypressed/trigger.lua b/src/gnu_and_bola_brawlers/keypressed/trigger.lua deleted file mode 100644 index abba1cc..0000000 --- a/src/gnu_and_bola_brawlers/keypressed/trigger.lua +++ /dev/null @@ -1,32 +0,0 @@ -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/default.lua b/src/gnu_and_bola_brawlers/keyreleased/default.lua new file mode 100644 index 0000000..7295131 --- /dev/null +++ b/src/gnu_and_bola_brawlers/keyreleased/default.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/keyreleased/trigger.lua b/src/gnu_and_bola_brawlers/keyreleased/trigger.lua deleted file mode 100644 index 7295131..0000000 --- a/src/gnu_and_bola_brawlers/keyreleased/trigger.lua +++ /dev/null @@ -1,37 +0,0 @@ -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/default.lua b/src/gnu_and_bola_brawlers/load/default.lua new file mode 100644 index 0000000..bbf5c02 --- /dev/null +++ b/src/gnu_and_bola_brawlers/load/default.lua @@ -0,0 +1,25 @@ +local load = {} + +load.initialize = function() + fps = 30 + upTime = love.timer.getTime() + nextTime = upTime + + windowProfile = require 'load/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) + + controller = require 'load/player_controller_configuration' + images = require 'load/images' + character = require 'load/character' + + metaSprite = { + bola = require 'stand', + } +end + +return load diff --git a/src/gnu_and_bola_brawlers/load/initialize.lua b/src/gnu_and_bola_brawlers/load/initialize.lua deleted file mode 100644 index bbf5c02..0000000 --- a/src/gnu_and_bola_brawlers/load/initialize.lua +++ /dev/null @@ -1,25 +0,0 @@ -local load = {} - -load.initialize = function() - fps = 30 - upTime = love.timer.getTime() - nextTime = upTime - - windowProfile = require 'load/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) - - controller = require 'load/player_controller_configuration' - images = require 'load/images' - character = require 'load/character' - - metaSprite = { - bola = require 'stand', - } -end - -return load diff --git a/src/gnu_and_bola_brawlers/main.lua b/src/gnu_and_bola_brawlers/main.lua index c0acbc3..af3952c 100644 --- a/src/gnu_and_bola_brawlers/main.lua +++ b/src/gnu_and_bola_brawlers/main.lua @@ -1,15 +1,15 @@ function love.load() - load = require 'load/initialize' + local load = require 'load/default' load.initialize() end function love.keypressed(key, scancode) - keypressed = require 'keypressed/trigger' + local keypressed = require 'keypressed/default' keypressed.trigger(character.bola, images.bola, metaSprite.bola, controller.player1, key, scancode) end function love.keyreleased(key, scancode) - keyreleased = require 'keyreleased/trigger' + local keyreleased = require 'keyreleased/default' keyreleased.trigger(character.bola, key, controller.player1, scancode) end @@ -120,29 +120,7 @@ function love.update(dt) end function love.draw() - 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 = function(images, character) - love.graphics.draw( - images[1], - images.quad, - character.position.x, - character.position.y, - character.orientation, - character.scale.x, - character.scale.y, - character.origin.x, - character.origin.y - ) - end - draw(images.bola, character.bola) + local draw = require 'draw/default' + draw.refresh() + draw.object(images.bola, character.bola) end -- cgit v1.2.3-54-g00ecf