It is a Pong game with Raspbbery Pi support originally made within just 2 days using Pygame. For those who don't know what Pong is, it is basically this 1970's arcade game where you have to score the ball on the opponent player.
- Install Python 3 from https://www.python.org/downloads/
- Clone the repository either by using Git or by clicking the green button saying "Code" (after downloading, don't forget to unzip the file)
cdto the repo directory- Type
pip3 install -r requirements.txtfor Windows orpython3 -m pip install -r requirements.txtfor Linux. If you are installing this on a Raspberry Pi and wanna use the GPIO to play the game, type ``python3 -m pip install -r requirements.txt -r rpi-requirements.txt` - Create a new empty directory named "logs"
- To run the game, run
main.pyfor Windows orpython3 main.pyfor Linux. If you wanna use the GPIO, typepython3 main.py --rpi-gpio. Remote GPIO is also supported. - On Linux, if
pygameraises an exception when runningpygame.font.init(), open the terminal, typesudo apt update, thensudo apt install libsdl2-ttf-2.0-0and re-runmain.py
Just connect four pull-up buttons to BCM GPIO's 22, 23, 24 and 27. When pushing the button at Pin 27, the right paddle will go up, on Pin 23 down, on Pin 22 the left paddle will go up and on Pin 24 down.
The schematic is shown below:
This circuit, when constructed on a breadboard, looks somewhat like this:
Simply, create a file named .env. The values of variables LEFT_UP, LEFT_DOWN, RIGHT_UP and RIGHT_DOWN will be the pin numbers of each button that triggers the corresponding action (for example, a .env file with the contents
LEFT_UP: "4"
RIGHT_DOWN: "BOARD5"
would change the pin for moving the left paddle up to GPIO 4 and for movng the right paddle down to Board pin 5 (the GPIO 3 pin))
- Make ball disappear when touched left or right border
- Add score counter
- Embed
loggingmodule - Make window resizable
- Make the GPIO numbers easily configurable
