https://www.youtube.com/watch?v=V0AXprDRsUU
This is a version of Pong that synchronizes the bounces with a song. You are free to use this code for any purpose, I only ask that you link back to this repo.
-
Install the required dependencies:
pip install pygame numpy cvxpy midoAlternatively, you can use
uvto install the dependencies:pip install uv -
Run the game with a MIDI file:
curl -o example_midi.mid https://bitmidi.com/uploads/72257.mid # download a MIDI file python pong.py example_midi.midOr using
uv run:uv run pong.py example_midi.mid -
For non-MIDI audio files, you need to provide a JSON file with note timings:
python pong.py path/to/your/audio_file.mp3 --times_file path/to/your/times.jsonOr using
uv run:uv run pong.py path/to/your/audio_file.mp3 --times_file path/to/your/times.jsonThe JSON file should contain a list of times (in seconds) when the ball should hit a paddle.