A gamepad usage example
Go to file
kaqu d1dad535dd Pad responsiveness improved 2020-12-27 15:24:20 +01:00
.vscode Bot improved, ball kept in game longer now 2020-12-16 18:08:04 +01:00
game_objects Pad responsiveness improved 2020-12-27 15:24:20 +01:00
pictures Bot improved, ball kept in game longer now 2020-12-16 18:08:04 +01:00
sounds Streamlined, sound files etc. 2020-11-25 19:24:10 +01:00
utilities USB event queue detection improved 2020-12-08 20:16:27 +01:00
.gitignore ignore pythons venv/ folder 2020-12-06 15:32:54 +01:00
README.md Bot improved, ball kept in game longer now 2020-12-16 18:08:04 +01:00
pandemic_pong.py Bot improved, ball kept in game longer now 2020-12-16 18:08:04 +01:00
pp.sh Local mode (empty queue) bugs fixed 2020-12-27 14:12:23 +01:00
pp_player1.sh Some network & other fixes 2020-12-08 12:59:24 +01:00
pp_player1_bot.sh Bot improved, ball kept in game longer now 2020-12-16 18:08:04 +01:00
pp_player2.sh Some network & other fixes 2020-12-08 12:59:24 +01:00
pp_player2_bot.sh Bot improved, ball kept in game longer now 2020-12-16 18:08:04 +01:00
pp_server.sh README fixed, shell scripts renamed 2020-12-06 12:10:06 +01:00
pp_viewer.sh Some network & other fixes 2020-12-08 12:59:24 +01:00
requirements.txt Add gobject and PyGObject in requirements.txt to avoid 'No module named 'gi'' import error 2020-12-08 20:14:56 +01:00



Pandemic Pong, a gamepad usage example

I recently obtained Nico's old (chinese) SNES gamepad clones for USB. To bring them to life, I decided to program yet another pong clone.

1. Python libs

As warmup, I chose python and scanned a couple of library documents to decide which one might be a suitable choice.

I selected libevdev, the reference pages are quite convincing ...

Also, we will have to play some game typical sounds. I chose the playsound library as the enabler.

Almost forgot: You'll have to have pyqt5 installed

(see also the following passage on virtual environments for 'automatic' installation).

Virtual environment setup

If you want to keep libraries separate from your other python stuff, a 'virtual environment' comes in handy. First make sure, you have python3-venv installed! (sudo apt install python3-venv on debian/ubuntu based systems).

Now let's create a new virtual environment:

    python3 -m venv venv

You should now see a new folder called venv/.

Activate the virtual environment with:

    source venv/bin/activate

Your shell prompt should now include a hint: (venv)

To install the dependencies within this virtual environment:

    pip install -r requirements.txt

After you're finished and want to exit the virtual environment call:


And to reactive the virtual environment later just calling

    source venv/bin/activate

is sufficient.

Finally, the playsound library requires some other libraries installed. For the virtual environment, the installation is as follows:

    pip install vext
    pip install vext.gi

which will allow the use of the system gi.repository (Gtk3) from a virtualenv.

With these installed we're prep'ed & ready!

2. Game usage & capabilities

There are two options to run the game:


2.1 Local gameplay

Run the game fullscreen locally like:

    python3 pandemic_pong.py

or have a sizeable window (locally) with:

    python3 pandemic_pong.py --sizeable

or simply use


instead (for convenience, shell scripts have been provided for different parameter sets).

The game tries to identify the event inputs for two gamepads automatically (otherwise see troubleshooting section below!).

2.2 Client/Server gameplay

Have all shell files (*.sh) executable!

Then to run a headless game server instance use


On a gameserver: Make sure, inbound TCP & UDP traffic to port 5050 is not blocked by your firewall or router!

  • To connect a player successfully, make sure the server is up & ready (past splash screen ...).
  • Also, don't start players simultaneously (either one may fail to connect - try again ... ;).

To connect player #1, use

    ./pp_player1.sh <remote_host_ip_or_name>

where <remote_host_ip_or_name> may be "" or localhost or any other internet host.

To connect player #2, use

    ./pp_player2.sh <remote_host_ip_or_name>

If you want to access a remote game server, edit the IP address within the pp_player1.sh and pp_player2.sh file respectively.

Also, you may want to play a client in fullscreen. To achieve this, substitute --sizeable by --fullscreen in both files.

It is possible to have bots as players! Use

    ./pp_player1_bot.sh <remote_host_ip_or_name>

for (left) player #1 and/or

    ./pp_player2_bot.sh <remote_host_ip_or_name>

for right player #2 respectively.

Finally, you may also connect one pure view client as

    ./pp_viewer.sh <remote_host_ip_or_name>

2.3 Scoring

A game is won by the player who first reaches 10 points.

A match is won by the player who first wins 3 games.

2.4 Additional features

The game features two additional capabilites beyond the original pong game (& may lack others ;).


  1. The player movement permits advancing towards the 'net', i.e. is not limited to vertical movement.

  2. It is possible to 'infect' the ball (hence the name!) by pressing one of the colour buttons. Infectiousness diminishes over time. Within the infection time, the player itself changes to the 'infection' colour. If the player contacts the ball during 'infection' time, it will contract the 'virus' (lifetime: next point!). To make things a little bit more complicated, the ball does not hint it's 'infection' by colour. If a tainted ball approaches a player, he has to vaccinate himself w/ the same colour (press corresponding button!). Yet, the vaccine diminishes over time as well ... If the player chooses the wrong colour or no vaccine at all, the ball passes right through the player. The point is counted as a miss, the opponent gains a point.

2.5 Exiting

The [Select] button to terminate the program is always available ...

Note, that a single player exiting with the [Select] button terminates ALL game instances (server, clients) ...

For sizeable windows, use the GUI button ;)

3. Troubleshooting

3.1 Gamepad identification

In case you have other (differing) USB gamepads, you may need to identify button usage & other gamepad specifics. For convenience, I copied the sample script (folder 'utilities').

Source adjustments will have to take place within 'pong_player.py'. Recommended approach: Map events here to their original correspondents.

3.2 Client/Server problems

You may experience initial delays due to fill up of streamed input queue. After some 2-5s this effect will disappear. Currently, there is no clean initial synchronization ...

On a gameserver: Make sure, inbound TCP & UDP traffic to port 5050 is not blocked by your firewall or router!

4. Outlook

  • Maybe HTTP streaming shall be moved to raw TCP streaming ...

  • Game mechanics: Maybe introduce an incubation time?

  • Write a better ('invincible'?) attacking - horizontal movement - bot ...