A rhythm-based dodging game created with Pygame where the player controls a spaceship to avoid obstacles. The spaceship can be controlled either by the keyboard or an external potentiometer connected to an Arduino Nano. The potentiometer setup is read via serial communication using the pyserial library.
The Arduino Nano reads the position of the potentiometer, and the game receives these values through the serial port. This allows the player to control the spaceship by adjusting the potentiometer. Falling spheres appear at regular intervals. The player must avoid these spheres by moving the spaceship horizontally.
Python 3.7+ Pygame: Install with pip install pygame. Pyserial: Install with pip install pyserial. Arduino: Code uploaded to an Arduino Nano to read potentiometer values.
-
Clone the Repository:
git clone <repository-url>
-
Install Required Packages:
pip install -r requirements.txt
-
Arduino Setup:
arduino = serial.Serial('COM7', 9600, timeout=1)
If you have any doubts, you can see which port is in use on your computer by running this command in your terminal :
python -m serial.tools.list_ports
Go in the ./src directory and run :
python ./main.py
When starting, the game scans for an arduino (with the right code uploaded on it) connected to the specified COM port. If connection is made, the game is then controlled by the MCU potentiometer. Whoever is the connection cannot be established, an error message will appear in the terminal. The game will still be playable but only using the arrow keys.
The statistics directory contains a script to help visualize the player data stored in the csv file. When executed, it plots two graphs : the scores of all players by sorted by their highscore and the highscore compared to the number of games played.
To start this script use :
python .\stats.py
In the statistics directory.
Alternatively, a jupyter notebook is also available to visualize every graphics individually.