From 9b71ece8a41f8bf3648a6ba89f81513fcc42f655 Mon Sep 17 00:00:00 2001 From: rmottainfo Date: Sun, 17 Sep 2023 18:07:32 -0300 Subject: [PATCH] up --- README.md | 3 +- lua/README.md | 29 ++++++++++++++++ lua/alone_pong/main.lua | 73 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 lua/README.md create mode 100644 lua/alone_pong/main.lua diff --git a/README.md b/README.md index d9fc059..3be4711 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ Welcome to Pongtopia, a repository that hosts various implementations of the cla - [Python](/python/README.md): Implementations in Python. - [MIT Scratch](/scratch/README.md): A fun version of the game made with MIT Scratch. - [JavaScript](/javascript/README.md): Games developed in JavaScript. - +- [C++](/cpp/README.md): C++ sandbox. +- [Lua](/lua/README.md): Lua implementations. ## How to Play diff --git a/lua/README.md b/lua/README.md new file mode 100644 index 0000000..cbebd02 --- /dev/null +++ b/lua/README.md @@ -0,0 +1,29 @@ +# AlonePong in Lua + +Welcome to the Lua version of AlonePong in the Pongtopia project! In this implementation, you'll experience the classic Pong game with a unique twist: you control a single paddle that bounces the ball against the bottom and side walls. Enjoy OldSchool stress-free moments while exploring Lua for game development. + +## How to Run + +To run AlonePong in Lua, follow these steps: + +1. Clone or download this repository to your local machine. +2. Make sure you have the LÖVE framework installed. You can download it from [https://love2d.org/](https://love2d.org/). +3. Open a terminal or command prompt and navigate to the "lua/alone_pong" folder. +4. Run the game using the following command: + +```bash +love main.lua +``` + + +That's it! You can now enjoy the game and explore Lua for game development. The game logic is implemented in the "main.lua" file. + +## Technologies Used + +This implementation of AlonePong is written in Lua and uses the LÖVE framework for game development. + +## Feedback and Contributions + +If you have any feedback, ideas for improvements, or if you'd like to contribute to this project, feel free to reach out. Your input is highly appreciated! + +Thanks for playing AlonePong in Lua, and enjoy the game! diff --git a/lua/alone_pong/main.lua b/lua/alone_pong/main.lua new file mode 100644 index 0000000..2b376f8 --- /dev/null +++ b/lua/alone_pong/main.lua @@ -0,0 +1,73 @@ +-- Inicialização do Love2D +function love.load() + -- Configurações da janela do jogo + largura, altura = 600, 800 + love.window.setMode(largura, altura) + love.window.setTitle("Alone Pong") + + -- Cores + preto = {0, 0, 0} + verde = {0, 255, 0} + + -- Posições iniciais da bola e da barra (sem movimento) + bola_tamanho = 20 + bola_x = largura / 2 - bola_tamanho / 2 + bola_y = altura / 2 - bola_tamanho / 2 + + barra_largura = 100 + barra_altura = 10 + barra_x = largura / 2 - barra_largura / 2 + barra_y = altura - 30 + + -- Velocidade da bola + bola_velocidade_x = 200 + bola_velocidade_y = 200 +end + +-- Renderização do jogo +function love.draw() + -- Limpa a tela + love.graphics.setBackgroundColor(preto) + love.graphics.clear() + + -- Desenha a bola + love.graphics.setColor(verde) + love.graphics.rectangle("fill", bola_x, bola_y, bola_tamanho, bola_tamanho) + + -- Desenha a barra do jogador + love.graphics.rectangle("fill", barra_x, barra_y, barra_largura, barra_altura) +end + +-- Atualização do jogo +function love.update(dt) + -- Movimento da bola + bola_x = bola_x + bola_velocidade_x * dt + bola_y = bola_y + bola_velocidade_y * dt + + -- Controle da barra do jogador + if love.keyboard.isDown("left") and barra_x > 0 then + barra_x = barra_x - 200 * dt -- Velocidade da barra + end + if love.keyboard.isDown("right") and barra_x < largura - barra_largura then + barra_x = barra_x + 200 * dt -- Velocidade da barra + end + + -- Colisão com as paredes para a bola + if bola_x <= 0 or bola_x >= largura - bola_tamanho then + bola_velocidade_x = -bola_velocidade_x + end + + -- Colisão com a parte superior da tela para a bola + if bola_y <= 0 then + bola_velocidade_y = -bola_velocidade_y + end + + -- Colisão com a barra do jogador para a bola + if ( + bola_y + bola_tamanho >= barra_y and + bola_x + bola_tamanho >= barra_x and + bola_x <= barra_x + barra_largura + ) then + bola_velocidade_y = -bola_velocidade_y + end +end