From 2ad018f3f77e7a0ddde9dfa3aa92bc151e9ea9a5 Mon Sep 17 00:00:00 2001 From: Jorge Lopez Seijas Date: Wed, 14 Dec 2016 23:22:19 +0100 Subject: Keep the code KISS --- src/gnu_and_bola_brawlers/load/character.lua | 29 ++++++ src/gnu_and_bola_brawlers/load/initialize.lua | 26 +++++ src/gnu_and_bola_brawlers/load/meta_sprites.lua | 7 ++ .../load/player_controller_configuration.lua | 13 +++ src/gnu_and_bola_brawlers/load/window_profile.lua | 11 ++ src/gnu_and_bola_brawlers/main.lua | 114 ++++----------------- 6 files changed, 107 insertions(+), 93 deletions(-) create mode 100644 src/gnu_and_bola_brawlers/load/character.lua create mode 100644 src/gnu_and_bola_brawlers/load/initialize.lua create mode 100644 src/gnu_and_bola_brawlers/load/meta_sprites.lua create mode 100644 src/gnu_and_bola_brawlers/load/player_controller_configuration.lua create mode 100644 src/gnu_and_bola_brawlers/load/window_profile.lua diff --git a/src/gnu_and_bola_brawlers/load/character.lua b/src/gnu_and_bola_brawlers/load/character.lua new file mode 100644 index 0000000..6ee15c7 --- /dev/null +++ b/src/gnu_and_bola_brawlers/load/character.lua @@ -0,0 +1,29 @@ +return { + bola = { + orientation = 0, + acceleration = 0, + velocity = 125, + gravity = -500, + position = { + x = windowProfile.mode.width / 2, + y = windowProfile.mode.height / 2, + }, + scale = { + x = 1, + y = 1, + }, + origin = { + x = metaSprites.bola.x / 2, + y = metaSprites.bola.y / 2, + }, + stand = require 'stand', + walk = require 'walk', + jump = require 'jump', + actionLeft = false, + actionRight = false, + actionUp = false, + actionDown = false, + actionA = false, + actionB = false, + }, +} diff --git a/src/gnu_and_bola_brawlers/load/initialize.lua b/src/gnu_and_bola_brawlers/load/initialize.lua new file mode 100644 index 0000000..c4e62ae --- /dev/null +++ b/src/gnu_and_bola_brawlers/load/initialize.lua @@ -0,0 +1,26 @@ + +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) + + playerController = require 'load/player_controller_configuration' + metaSprites = require 'load/meta_sprites' + character = require 'load/character' + + sprite = { + bola = require 'stand', + } +end + +return load diff --git a/src/gnu_and_bola_brawlers/load/meta_sprites.lua b/src/gnu_and_bola_brawlers/load/meta_sprites.lua new file mode 100644 index 0000000..e8cba17 --- /dev/null +++ b/src/gnu_and_bola_brawlers/load/meta_sprites.lua @@ -0,0 +1,7 @@ +return { + bola = { + image = love.graphics.newImage('/multimedia/ppu_rp2c0x/meta_sprites/bola/default_sheet_color0_alpha.png'), + x = 24, + y = 32, + } +} diff --git a/src/gnu_and_bola_brawlers/load/player_controller_configuration.lua b/src/gnu_and_bola_brawlers/load/player_controller_configuration.lua new file mode 100644 index 0000000..ec6c99e --- /dev/null +++ b/src/gnu_and_bola_brawlers/load/player_controller_configuration.lua @@ -0,0 +1,13 @@ +return { + player1 = { + left = 'a', + right = 'd', + up = 'w', + down = 's', + a = 'j', + b = 'k', + select = 'g', + start = 'h', + quit = 'escape', + } +} diff --git a/src/gnu_and_bola_brawlers/load/window_profile.lua b/src/gnu_and_bola_brawlers/load/window_profile.lua new file mode 100644 index 0000000..0f6d928 --- /dev/null +++ b/src/gnu_and_bola_brawlers/load/window_profile.lua @@ -0,0 +1,11 @@ +return { + mode = { + width = 256, + height = 240, + }, + scale = { + x = 2, + y = 2, + }, + title = "GNU & Bola Brawlers", +} diff --git a/src/gnu_and_bola_brawlers/main.lua b/src/gnu_and_bola_brawlers/main.lua index b9aed5e..78a4e98 100644 --- a/src/gnu_and_bola_brawlers/main.lua +++ b/src/gnu_and_bola_brawlers/main.lua @@ -1,139 +1,67 @@ function love.load() - fps = 30 - upTime = love.timer.getTime() - nextTime = upTime - - windowProfile = { - mode = { - width = 256, - height = 240, - }, - scale = { - x = 2, - y = 2, - }, - title = "GNU & Bola Brawlers", - } - - 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 = { - left = 'a', - right = 'd', - up = 'w', - down = 's', - a = 'j', - b = 'k', - select = 'g', - start = 'h', - quit = 'escape', - } - - metaSprites = { - bola = { - image = love.graphics.newImage('multimedia/ppu_rp2c0x/meta_sprites/bola/default_sheet_color0_alpha.png'), - x = 24, - y = 32, - } - } - - character = { - bola = { - orientation = 0, - acceleration = 0, - velocity = 125, - gravity = -500, - position = { - x = windowProfile.mode.width / 2, - y = windowProfile.mode.height / 2, - }, - scale = { - x = 1, - y = 1, - }, - origin = { - x = metaSprites.bola.x / 2, - y = metaSprites.bola.y / 2, - }, - stand = require 'stand', - walk = require 'walk', - jump = require 'jump', - actionLeft = false, - actionRight = false, - actionUp = false, - actionDown = false, - actionA = false, - actionB = false, - }, - } - sprite = { - bola = require 'stand', - } + load = require 'load/initialize' + load.initialize() end function love.keypressed(key, scancode) - keypressed = function(character, metaSprites, sprite, key, scancode) - if scancode == button.quit then + keypressed = function(character, metaSprites, sprite, controller, key, scancode) + if scancode == playerController.quit then love.event.quit() end - if scancode == button.a then + if scancode == controller.a then character.actionA = true character.actionDown = false character.actionUp = false sprite = require 'jump' end - if scancode == button.left then + if scancode == controller.left then character.actionLeft = true end - if scancode == button.right then + if scancode == controller.right then character.actionRight = true end - if scancode == button.up and character.jump.isJumping == false then + if scancode == controller.up and character.jump.isJumping == false then character.actionUp = true end - if scancode == button.down and character.jump.isJumping == false then + if scancode == controller.down and character.jump.isJumping == false then character.actionDown = true end end - keypressed(character.bola, metaSprites.bola, sprite.bola, key, scancode) + keypressed(character.bola, metaSprites.bola, sprite.bola, playerController.player1, key, scancode) end function love.keyreleased(key, scancode) - keyreleased = function(character, key, scancode) - if scancode == button.a then + keyreleased = function(character, key, controller, scancode) + if scancode == controller.a then character.actionA = false end - if scancode == button.left then + if scancode == controller.left then character.actionLeft = false end - if scancode == button.right then + if scancode == controller.right then character.actionRight = false end - if scancode == button.up then + if scancode == controller.up then character.actionUp = false end - if scancode == button.down then + if scancode == controller.down then character.actionDown = false end - if scancode == button.b then + if scancode == controller.b then character.actionB = false end - if scancode == button.a then + if scancode == controller.a then character.actionA = false if character.jump.velocity ~= 0 then @@ -141,7 +69,7 @@ function love.keyreleased(key, scancode) end end end - keyreleased(character.bola, key, scancode) + keyreleased(character.bola, key, playerController.player1, scancode) end function love.update(dt) @@ -225,9 +153,9 @@ function love.update(dt) character.jump.isJumping = false character.actionA = false - if love.keyboard.isScancodeDown(button.up) then + if love.keyboard.isScancodeDown(playerController.player1.up) then character.actionUp = true - elseif love.keyboard.isScancodeDown(button.down) then + elseif love.keyboard.isScancodeDown(playerController.player1.down) then character.actionDown = true end end -- cgit v1.2.3