A classic arcade plane-fighting ("plane war") game written with pygame, made hands-free with motion control on a Raspberry Pi — steer by tilting the device, drop bombs by opening your mouth.
🎥 Demo website: https://yjiao286.github.io/Demo_Website_for_Motion_Sensing_Game/
| Action | Input |
|---|---|
| Move up / down | Tilt pitch (or GPIO 27 / 23 buttons) |
| Move left / right | Tilt roll (or GPIO 22 / 17 buttons) |
| Drop bomb | Open your mouth in front of the webcam |
- Tilt control — a BNO055 9-DOF IMU (I²C,
adafruit_bno055) reports Euler angles; the game compares them against the power-on reference to move the player plane. Four push buttons (BCM 27/23/22/17, active-low with pull-ups) provide a fallback. - Mouth control — a separate process (
detect_open_mouth.py) runs dlib's 68-point facial landmark detector on the webcam stream, computes the Mouth Aspect Ratio (MAR), and writes a flag to thebombfile whenever MAR > 0.79 (with a debounce counter). The game loop polls that file and drops a bomb.
Built with pygame sprites and pixel-perfect mask collision:
- Three enemy types — small/medium planes and a large UFO with multiple hit points
- Auto-firing bullets, limited bombs that clear the screen, and lives
- Score persistence between runs (
score.txt) - Start / pause / resume / restart menus, background music and per-event sound effects
Plane-fighting-game/
├── main.py # game loop, menus, scoring, bomb consumption
├── plane3.py # player plane: IMU + GPIO button control
├── enemy.py # enemy sprites
├── bullet.py # bullets
├── detect_open_mouth.py # webcam mouth-open detector (dlib MAR)
├── images/, music/, font/ # assets
└── score.txt # persistent high score
Hardware needed: Raspberry Pi (with camera), BNO055 IMU, and optionally the four buttons. Then, in two terminals (or two processes):
cd Plane-fighting-game
python3 detect_open_mouth.py # mouth detection (writes the `bomb` flag file)
python3 main.py # the gameThe mouth detector also expects dlib's shape_predictor_68_face_landmarks.dat in the working directory.
Dependencies: pygame, opencv-python, dlib, imutils, scipy, adafruit-circuitpython-bno055, RPi.GPIO.