diff options
Diffstat (limited to 'src/gnu_and_bola_brawlers/update')
-rw-r--r-- | src/gnu_and_bola_brawlers/update/default.lua | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/gnu_and_bola_brawlers/update/default.lua b/src/gnu_and_bola_brawlers/update/default.lua new file mode 100644 index 0000000..f6fb68e --- /dev/null +++ b/src/gnu_and_bola_brawlers/update/default.lua @@ -0,0 +1,106 @@ +local update = {} + +update.time = function(dt) + nextTime = nextTime + (1 / fps) +end + + +update.animation = function(metaSprite, images, dt) + --Increase actual elapsed time with new dt + metaSprite.elapsedTime = metaSprite.elapsedTime + dt --AnimationStart + + --In order to know if it is necessary to change the frame + if metaSprite.elapsedTime >= (1 / metaSprite.fps) then + metaSprite.elapsedTime = metaSprite.elapsedTime - (1 / metaSprite.fps) + if metaSprite.currentFrame == # metaSprite then --If current frame is equal to long metaSprite list + metaSprite.currentFrame = 1 -- Return to first frame + else + metaSprite.currentFrame = metaSprite.currentFrame + 1 --Next frame + end + end + + images.quad = metaSprite[metaSprite.currentFrame] --Update with new fame +end + +update.motion = function(character, images, metaSprite, dt) + if character.jump.higher > 0 and character.actionA == true then + 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 + end + + if character.actionLeft == true and character.actionRight == false then + metaSprite = require 'meta_sprites/bola/walk' + character.position.x = character.position.x - (character.velocity * dt) + character.scale.x = -1 + end + + if character.actionRight == true and character.actionLeft == false then + metaSprite = require 'meta_sprites/bola/walk' + character.position.x = character.position.x + (character.velocity * dt) + character.scale.x = 1 + end + + if character.actionUp == true and character.actionDown == false then + metaSprite = require 'meta_sprites/bola/walk' + character.position.y = character.position.y - (character.velocity * dt) + character.jump.ground = character.position.y + end + + if character.actionDown == true and character.actionUp == false then + metaSprite = require 'meta_sprites/bola/walk' + character.position.y = character.position.y + (character.velocity * dt) + character.jump.ground = character.position.y + end + + if character.actionUp == true and character.actionDown == true then + metaSprite = require 'meta_sprites/bola/stand' + elseif character.actionLeft == true and character.actionRight == true then + metaSprite = require 'meta_sprites/bola/stand' + elseif character.actionLeft == false and character.actionRight == false and character.actionUp == false and character.actionDown == false then + metaSprite = require 'meta_sprites/bola/stand' + end + + return metaSprite +end + +update.gravity = function(character, dt) + if character.jump.velocity ~= 0 then + character.jump.isJumping = true + character.position.y = character.position.y + (character.jump.velocity * dt) + character.jump.velocity = character.jump.velocity - (character.gravity * dt) + end + + if character.position.y > character.jump.ground then + character.jump.velocity = 0 + character.position.y = character.jump.ground + character.jump.higher = character.jump.higherMax + + character.jump.limitButtonJump = false + character.jump.isJumping = false + character.actionA = false + + if love.keyboard.isScancodeDown(controller.player1.up) then + character.actionUp = true + elseif love.keyboard.isScancodeDown(controller.player1.down) then + character.actionDown = true + end + end +end + +update.limit = function(character, dt) + if character.position.x <= character.origin.x then + character.position.x = character.origin.x + elseif character.position.x >= windowProfile.mode.width - character.origin.x then + character.position.x = windowProfile.mode.width - character.origin.x + end + + if character.position.y <= character.origin.y then + character.position.y = character.origin.y + elseif character.position.y >= windowProfile.mode.height - character.origin.y then + character.position.y = windowProfile.mode.height - character.origin.y + end +end + +return update |