Controller+BETADownload

Start a Python game with pygame

Star Run is a small two-to-four-player game. Scan the QR on the pygame window, move your dot to its matching star with the left stick or D-pad, and tap the bottom face button to dash. Stars add points. A dash sends a sound cue and rumble to that phone; the phone's LCD shows its score.

The game pauses with fewer than two connected phones. Leave and return to keep your seat, color and score. A normal phone refresh also keeps the seat. Press Backspace in the game to release offline seats and refresh the QR. Esc or closing the window stops the Python connection and its Node host.

Tested: Python 3.14.6, pygame-ce 2.5.8, websocket-client 1.9.2 and Node 22.22.0 on macOS 26.7 arm64. The shared library was built with AppleClang 21.0.0 and CMake 4.3.1. Two headless browser phones exercised the game with SDL dummy video/audio. Python 3.10 syntax was checked; other Python versions and Windows/Linux runtime targets are untested.

Contents

Set up

Use the unpacked SDK archive (or a source checkout after npm ci), Python 3.10+, Node 22+, CMake and a C99 compiler. Confirm that integrations/python/pyproject.toml and integrations/python/controller_plus/ exist. The SDK archive includes that package and the matching native source. From the archive's package/ folder:

export scratch="$HOME/controller-plus-pygame"
mkdir -p "$scratch/tmp" "$scratch/pip-cache"
export TMPDIR="$scratch/tmp"
export PIP_CACHE_DIR="$scratch/pip-cache"
python3 -m venv "$scratch/venv"
"$scratch/venv/bin/python" -m pip install ./integrations/python -r examples/pygame-starter/requirements.txt
cmake -S integrations/native -B "$scratch/native" -DCONTROLLER_PLUS_BUILD_SHARED=ON -DCMAKE_BUILD_TYPE=Release
cmake --build "$scratch/native" --parallel 2
export CONTROLLER_PLUS_LIBRARY="$scratch/native/libcontroller_plus.dylib"

Use libcontroller_plus.so on Linux or controller_plus.dll on Windows (possibly under Release/). Python and the shared library must have matching architectures. Use this checkout's C library with this checkout's Python bindings. No compiled Python extension or Controller+ account is needed.

Play on phones

Replace 192.168.1.20 below with this computer's LAN IP. Both phones must be able to reach it on the same network. Permit Node's incoming local-network connection in the OS firewall if asked. The example listens on all interfaces so phones can connect. It uses only public WebSocket/browser APIs and requests no camera, sensor or desktop-control permissions itself; scan using the phone's normal camera app.

"$scratch/venv/bin/python" -B examples/pygame-starter/game.py \
  --port 49230 --origin http://192.168.1.20:49230

The QR includes the chosen origin. The default origin is loopback and works only for testing on this computer. Ports are restricted to 49200–49299. Keep the game window focused; its Esc and Backspace keys belong to pygame.

Python starts host.mjs, reads the host credentials privately through a pipe, then uses the Python package over JSON WebSocket. Node serves the stock phone controller and QR; Python owns the game. websocket-client is the package's only runtime dependency; pygame-ce draws the example. requirements.txt repeats the transport constraint so setup is explicit. No relay, service account or custom Python WebSocket server is required.

The stdout readiness line contains a temporary player invitation, suitable for a local launcher. Do not save/share the host's private credential object. QR updates use the local /qr.png endpoint. Feedback receipts confirm the browser code path, not physical output. Sound or vibration may be unavailable; dot animation and score stay visible.

Two-phone test

Install Chrome locally; no browser download occurs. This starts one headless Chrome with isolated phone contexts and runs pygame with SDL's dummy video/audio drivers. It decodes the QR drawn in the game and checks phone movement/isolation, short-tap dashes, targeted feedback receipts, score persistence, leave/resume, four-seat capacity and clean game/Node shutdown. It uses loopback port 49231 by default.

export PYTHON="$scratch/venv/bin/python"
export CONTROLLER_PLUS_PYTHON_TMP="$scratch/pygame-test"
export CONTROLLER_PLUS_TEST_TMP="$scratch/chrome"
node --test --test-concurrency=1 examples/pygame-starter/test.mjs

Set PYGAME_TEST_PORT to another port in 49200–49299 if needed. Set CHROME_PATH to an installed Chrome executable when discovery cannot find it. Set KEEP_PYGAME_EVIDENCE=1 to retain game/phone screenshots and a JSON result under the test scratch directory. The test drives real browser touch targets through the SDK test driver, not game handlers. It always awaits child and Chrome cleanup. No vibration shim or audio permission grant is used.

For a pygame-only startup check:

"$scratch/venv/bin/python" -B examples/pygame-starter/game.py --headless --port 49233 --max-seconds 1

Headless checks do not prove camera QR scanning, LAN reachability, audible sound, motor vibration, real sensors or phone safe areas. Test those on physical devices before shipping.

Use it in your game

Call poll() once per frame, then read movement and consumed button presses. Keep scores by player ID. The starter starts a Node host and passes credentials through a private pipe; Python owns the game. Build the C library and bindings from the same source and for the same CPU architecture. There is no runtime ABI version query. Before release, read Ship a game.

All start pages · Search developer docs · Ship a game