Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- main.lua
- -- Configurações iniciais
- local ball = {
- x = 400,
- y = 300,
- radius = 20,
- speed = 200,
- dx = 0,
- dy = 0
- }
- -- Função para mover a bola
- function moveBall(dt)
- ball.x = ball.x + ball.dx * dt
- ball.y = ball.y + ball.dy * dt
- -- Limite da tela (campo)
- if ball.x - ball.radius < 0 then
- ball.x = ball.radius
- elseif ball.x + ball.radius > love.graphics.getWidth() then
- ball.x = love.graphics.getWidth() - ball.radius
- end
- if ball.y - ball.radius < 0 then
- ball.y = ball.radius
- elseif ball.y + ball.radius > love.graphics.getHeight() then
- ball.y = love.graphics.getHeight() - ball.radius
- end
- end
- -- Função Love2D chamada a cada quadro (frame)
- function love.update(dt)
- -- Controlando a bola com as teclas de seta ou WASD
- if love.keyboard.isDown("right") then
- ball.dx = ball.speed
- elseif love.keyboard.isDown("left") then
- ball.dx = -ball.speed
- else
- ball.dx = 0
- end
- if love.keyboard.isDown("down") then
- ball.dy = ball.speed
- elseif love.keyboard.isDown("up") then
- ball.dy = -ball.speed
- else
- ball.dy = 0
- end
- -- Atualizando a posição da bola
- moveBall(dt)
- end
- -- Função Love2D para desenhar os objetos na tela
- function love.draw()
- love.graphics.setColor(1, 0, 0) -- Cor vermelha para a bola
- love.graphics.circle("fill", ball.x, ball.y, ball.radius)
- end
- -- Função Love2D chamada no início do jogo
- function love.load()
- love.window.setTitle("Blade Ball")
- love.window.setMode(800, 600) -- Tamanho da janela do jogo
- end
Advertisement
Add Comment
Please, Sign In to add comment