function love.load() load = require 'load/initialize' load.initialize() end function love.keypressed(key, scancode) keypressed = function(character, images, metaSprite, 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 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 keypressed(character.bola, images.bola, metaSprite.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(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 animation(metaSprite.bola, images.bola, dt) 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 '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 '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 '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 '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 'stand' elseif character.actionLeft == true and character.actionRight == true then metaSprite = require 'stand' elseif character.actionLeft == false and character.actionRight == false and character.actionUp == false and character.actionDown == false then metaSprite = require 'stand' end return metaSprite end metaSprite.bola = motion(character.bola, images.bola, metaSprite.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(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) end