diff options
Diffstat (limited to 'src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua')
-rw-r--r-- | src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua | 286 |
1 files changed, 273 insertions, 13 deletions
diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua index fc8fc51..4e9512b 100644 --- a/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua +++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua @@ -1,26 +1,286 @@ -require 'scripts.tables' -require 'scripts.load.default' -require 'scripts.keypressed.default' -require 'scripts.keyreleased.default' -require 'scripts.update.default' -require 'scripts.draw.default' - function love.load() - main.load() + fps = 30 + upTime = love.timer.getTime() + nextTime = upTime + + windowProfile = { + mode = { + width = 256, + height = 240, + }, + scale = { + x = 2, + y = 2, + }, + title = "GNU & Bola - The libre beat'em up game", + } + + 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, + }, + } + quad = { + bola = require 'stand', + } end -function love.keypressed(key, scancode, isrepeat) - main.keypressed(key, scancode, isrepeat) +function love.keypressed(key, scancode) + keypressed = function(character, metaSprites, key, scancode) + if scancode == button.quit then + love.event.quit() + end + + if scancode == button.a then + character.actionA = true + character.actionDown = false + character.actionUp = false + quad.bola = require 'jump' + end + + if scancode == button.left then + character.actionLeft = true + end + + if scancode == button.right then + character.actionRight = true + end + + if scancode == button.up and character.jump.isJumping == false then + character.actionUp = true + end + + if scancode == button.down and character.jump.isJumping == false then + character.actionDown = true + end + end + keypressed(character.bola, metaSprites.bola, key, scancode) end function love.keyreleased(key, scancode) - main.keyreleased(key, scancode) + keyreleased = function(character, key, scancode) + if scancode == button.a then + character.actionA = false + end + + if scancode == button.left then + character.actionLeft = false + end + + if scancode == button.right then + character.actionRight = false + end + + if scancode == button.up then + character.actionUp = false + end + + if scancode == button.down then + character.actionDown = false + end + + if scancode == button.b then + character.actionB = false + end + + if scancode == button.a then + character.actionA = false + + if character.jump.velocity ~= 0 then + character.jump.limitButtonJump = true + end + end + end + keyreleased(character.bola, key, scancode) end function love.update(dt) - main.update(dt) + nextTime = nextTime + (1 / fps) + + animation = function(character, metaSprites, dt) + local frameStart = function() + character.currentFrame = 1 + end + local frameCounter = function() + character.currentFrame = character.currentFrame + 1 + end + local animationStart = function() + character.elapsedTime = character.elapsedTime + dt + end + local animationCounter = function() + if character.elapsedTime >= (1 / character.fps) then + character.elapsedTime = character.elapsedTime - (1 / character.fps) + if character.currentFrame == # character then + frameStart() + else + frameCounter() + end + end + end + + animationStart() + animationCounter() + metaSprites.quad = character[character.currentFrame] + end + animation(quad.bola, metaSprites.bola, dt) + + motion = function(character, metaSprites, 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 + quad.bola = 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 + quad.bola = 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 + quad.bola = 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 + quad.bola = 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 + quad.bola = require 'stand' + elseif character.actionLeft == true and character.actionRight == true then + quad.bola = require 'stand' + elseif character.actionLeft == false and character.actionRight == false and character.actionUp == false and character.actionDown == false then + quad.bola = require 'stand' + end + end + motion(character.bola, metaSprites.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(button.up) then + character.actionUp = true + elseif love.keyboard.isScancodeDown(button.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() - main.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 |