From 581d69b76cf4b17e9fc77bbbe9ec0274b4de26d2 Mon Sep 17 00:00:00 2001 From: Jorge Lopez Seijas Date: Sun, 18 Dec 2016 23:55:14 +0100 Subject: Add jump and fall meta sprites, fix some issues, comment update.motion code and add prints for debugging --- src/gnu_and_bola_brawlers/keypressed/default.lua | 10 ---- src/gnu_and_bola_brawlers/main.lua | 5 +- .../meta_sprites/bola/fall.lua | 9 +++- .../meta_sprites/bola/jump.lua | 7 ++- src/gnu_and_bola_brawlers/update/default.lua | 60 +++++++++++++++++----- 5 files changed, 64 insertions(+), 27 deletions(-) diff --git a/src/gnu_and_bola_brawlers/keypressed/default.lua b/src/gnu_and_bola_brawlers/keypressed/default.lua index b650a5c..c2a779c 100644 --- a/src/gnu_and_bola_brawlers/keypressed/default.lua +++ b/src/gnu_and_bola_brawlers/keypressed/default.lua @@ -9,32 +9,22 @@ keypressed.trigger = function(character, images, metaSprite, controller, key, sc character.actionA = true character.actionDown = false character.actionUp = false - character.jump.currentFrame = 1 - character.jump.fps = 1 end if scancode == controller.left then character.actionLeft = true - character.walk.currentFrame = 1 - character.walk.fps = 9 end if scancode == controller.right then character.actionRight = true - character.walk.currentFrame = 1 - character.walk.fps = 9 end if scancode == controller.up and character.jump.isJumping == false then character.actionUp = true - character.walk.currentFrame = 1 - character.walk.fps = 9 end if scancode == controller.down and character.jump.isJumping == false then character.actionDown = true - character.walk.currentFrame = 1 - character.walk.fps = 9 end return metaSprite diff --git a/src/gnu_and_bola_brawlers/main.lua b/src/gnu_and_bola_brawlers/main.lua index 40299a5..ed70047 100644 --- a/src/gnu_and_bola_brawlers/main.lua +++ b/src/gnu_and_bola_brawlers/main.lua @@ -1,6 +1,9 @@ function love.load() local load = require 'load/default' load.initialize() + + update = require 'update/default' + draw = require 'draw/default' end function love.keypressed(key, scancode) @@ -14,7 +17,6 @@ function love.keyreleased(key, scancode) end function love.update(dt) - local update = require 'update/default' update.time(dt) update.animation(metaSprite.bola, images.bola, dt) metaSprite.bola = update.motion(character.bola, images.bola, metaSprite.bola, dt) @@ -23,7 +25,6 @@ function love.update(dt) end function love.draw() - local draw = require 'draw/default' draw.refresh() draw.object(images.bola, character.bola) end diff --git a/src/gnu_and_bola_brawlers/meta_sprites/bola/fall.lua b/src/gnu_and_bola_brawlers/meta_sprites/bola/fall.lua index fae18b0..da1e404 100644 --- a/src/gnu_and_bola_brawlers/meta_sprites/bola/fall.lua +++ b/src/gnu_and_bola_brawlers/meta_sprites/bola/fall.lua @@ -1,8 +1,15 @@ +--[[ Collection of sprites and parameters to perform the fall movement ]]-- + return { + love.graphics.newQuad(images.bola.x * 6, images.bola.y * 2, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), + love.graphics.newQuad(images.bola.x * 7, images.bola.y * 2, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), + love.graphics.newQuad(images.bola.x * 8, images.bola.y * 2, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), love.graphics.newQuad(images.bola.x * 9, images.bola.y * 2, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), + love.graphics.newQuad(images.bola.x * 5, images.bola.y * 3, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), + love.graphics.newQuad(images.bola.x * 6, images.bola.y * 3, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), currentFrame = 1, elapsedTime = 0, - fps = 1, + fps = 9, height = -250, velocity = 0, ground = windowProfile.mode.height / 2, diff --git a/src/gnu_and_bola_brawlers/meta_sprites/bola/jump.lua b/src/gnu_and_bola_brawlers/meta_sprites/bola/jump.lua index fd7e8d0..efa1962 100644 --- a/src/gnu_and_bola_brawlers/meta_sprites/bola/jump.lua +++ b/src/gnu_and_bola_brawlers/meta_sprites/bola/jump.lua @@ -1,10 +1,15 @@ --[[ Collection of sprites and parameters to perform the jump movement ]]-- return { + love.graphics.newQuad(images.bola.x * 5, images.bola.y * 1, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), + love.graphics.newQuad(images.bola.x * 6, images.bola.y * 1, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), + love.graphics.newQuad(images.bola.x * 7, images.bola.y * 1, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), + love.graphics.newQuad(images.bola.x * 8, images.bola.y * 1, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), + love.graphics.newQuad(images.bola.x * 9, images.bola.y * 1, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), love.graphics.newQuad(images.bola.x * 5, images.bola.y * 2, images.bola.x, images.bola.y, images.bola[1]:getDimensions()), currentFrame = 1, elapsedTime = 0, - fps = 1, + fps = 9, height = -250, velocity = 0, ground = windowProfile.mode.height / 2, diff --git a/src/gnu_and_bola_brawlers/update/default.lua b/src/gnu_and_bola_brawlers/update/default.lua index 8f37f6c..b14349b 100644 --- a/src/gnu_and_bola_brawlers/update/default.lua +++ b/src/gnu_and_bola_brawlers/update/default.lua @@ -23,48 +23,82 @@ update.animation = function(metaSprite, images, dt) end update.motion = function(character, images, metaSprite, dt) - if character.actionUp == true and character.actionDown == true then - metaSprite = character.stand - elseif character.actionLeft == true and character.actionRight == true then - metaSprite = character.stand - elseif character.actionLeft == false and character.actionRight == false and character.actionUp == false and character.actionDown == false and character.actionA == false then - metaSprite = character.stand + -- Check if press button up/down, left/right at same time, no button press and character is not jumping then metaSprite is stand + if ((character.actionUp == true and character.actionDown == true) or (character.actionLeft == true and character.actionRight == true) or (character.actionLeft == false and character.actionRight == false and character.actionUp == false and character.actionDown == false)) and character.actionA == false and character.jump.isJumping == false then + if metaSprite ~= character.stand then + print("(update.motion) -> load stand meta sprite") + metaSprite = character.stand + metaSprite.currentFrame = 1 + metaSprite.fps = 9 + end end + -- Check if it is jumping or falling if character.jump.higher > 0 and character.actionUp == false and character.actionDown == false and character.actionA == true then - metaSprite = character.jump + if metaSprite ~= character.jump then + print("(update.motion) -> load jump meta sprite") + metaSprite = character.jump + metaSprite.currentFrame = 1 + metaSprite.fps = 6 + end + if character.jump.limitButtonJump == false then character.jump.higher = character.jump.higher - dt character.jump.velocity = character.jump.velocity + character.jump.height * (dt / character.jump.higherMax) end - elseif character.jump.higher < 0 and character.actionUp == false and character.actionDown == false and character.actionA == false then - metaSprite = character.fall + elseif (character.jump.velocity > 0 and character.actionUp == false and character.actionDown == false) then + if metaSprite ~= character.fall then + print("(update.motion) -> load fall meta sprite") + metaSprite = character.fall + metaSprite.currentFrame = 1 + metaSprite.fps = 6 + end end + --Check if left button has been pressed if character.actionLeft == true and character.actionRight == false then - if character.jump.higher > 0 and character.actionA == false then + if character.jump.higher > 0 and character.actionA == false and character.jump.isJumping == false and metaSprite ~= character.walk then + print("(update.motion) -> load walk meta sprite") metaSprite = character.walk + metaSprite.currentFrame = 1 + metaSprite.fps = 9 end character.position.x = character.position.x - (character.velocity * dt) character.scale.x = -1 end + --Check if right button has been pressed if character.actionRight == true and character.actionLeft == false then - if character.jump.higher > 0 and character.actionA == false then + if character.jump.higher > 0 and character.actionA == false and character.jump.isJumping == false and metaSprite ~= character.walk then + print("(update.motion) -> load walk meta sprite") metaSprite = character.walk + metaSprite.currentFrame = 1 + metaSprite.fps = 9 end character.position.x = character.position.x + (character.velocity * dt) character.scale.x = 1 end + --Check if up button has been pressed if character.actionUp == true and character.actionDown == false then - metaSprite = character.walk + if metaSprite ~= character.walk then + print("(update.motion) -> load walk meta sprite") + metaSprite = character.walk + metaSprite.currentFrame = 1 + metaSprite.fps = 9 + end character.position.y = character.position.y - (character.velocity * dt) character.jump.ground = character.position.y end + --Check if down button has been pressed if character.actionDown == true and character.actionUp == false then - metaSprite = character.walk + if metaSprite ~= character.walk then + print("(update.motion) -> load walk meta sprite") + metaSprite = character.walk + metaSprite.currentFrame = 1 + metaSprite.fps = 9 + end character.position.y = character.position.y + (character.velocity * dt) character.jump.ground = character.position.y end -- cgit v1.2.3-54-g00ecf