Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
rmottainfo committed Sep 17, 2023
1 parent a6d4a2d commit 9b71ece
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 29 additions & 0 deletions lua/README.md
Original file line number Diff line number Diff line change
@@ -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!
73 changes: 73 additions & 0 deletions lua/alone_pong/main.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9b71ece

Please sign in to comment.