function love.load() load = require 'load/initialize' load.initialize() end function love.keypressed(key, scancode) keypressed = function(character, metaSprites, sprite, 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 sprite = 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, metaSprites.bola, sprite.bola, playerController.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) end function love.update(dt) nextTime = nextTime + (1 / fps) animation = function(sprite, metaSprites, dt) --Increase actual elapsed time with new dt sprite.elapsedTime = sprite.elapsedTime + dt --AnimationStart --In order to know if it is necessary to change the frame if sprite.elapsedTime >= (1 / sprite.fps) then sprite.elapsedTime = sprite.elapsedTime - (1 / sprite.fps) if sprite.currentFrame == # sprite then --If current frame is equal to long sprite list sprite.currentFrame = 1 -- Return to first frame else sprite.currentFrame = sprite.currentFrame + 1 --Next frame end end metaSprites.quad = sprite[sprite.currentFrame] --Update with new fame end animation(sprite.bola, metaSprites.bola, dt) motion = function(character, metaSprites, sprite, 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 sprite = require 'walk' character.position.x = character.position.x - (character.velocity * dt) character.scale.x = -1 end if character.actionRight == true and character.actionLeft == false then sprite = require 'walk' character.position.x = character.position.x + (character.velocity * dt) character.scale.x = 1 end if character.actionUp == true and character.actionDown == false then sprite = require '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 sprite = require '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 sprite = require 'stand' elseif character.actionLeft == true and character.actionRight == true then sprite = require 'stand' elseif character.actionLeft == false and character.actionRight == false and character.actionUp == false and character.actionDown == false then sprite = require 'stand' end return sprite end sprite.bola = motion(character.bola, metaSprites.bola, sprite.bola, dt) 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(playerController.player1.up) then character.actionUp = true elseif love.keyboard.isScancodeDown(playerController.player1.down) then character.actionDown = true end end end gravity(character.bola, dt) 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 limit(character.bola, 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(metaSprites, character) love.graphics.draw( metaSprites.image, metaSprites.quad, character.position.x, character.position.y, character.orientation, character.scale.x, character.scale.y, character.origin.x, character.origin.y ) end draw(metaSprites.bola, character.bola) end