Dodge Punch is a webcam boxing reflex game built with Python, OpenCV, and MediaPipe.
The game tracks your head and arms so you can:
- dodge jabs and hooks
- block punches with your guard
- hit pad-work targets
Here's a Demo if you're borded of reading :) The show video is only the dodging mode
Demo.mp4
When you run the game, stand in front of your webcam so your face is clearly visible.
- Move your head out of red jab/hook danger zones.
- Yellow shapes are warnings.
- Use your forearms/hands to block incoming punches when your guard lines overlap them.
- If a live attack hits your head box, the round ends.
- A pad appears near head height.
- It grows from yellow to blue.
- Hit the live blue pad with your arm line before it expires.
- Successful hits add points.
- The game alternates between dodge and pad-work stages.
qquits the game- Click
Restartafter a knockout - Auto-restart can also be enabled in
settings.py
This project is currently set up for Python 3.10.
python3 -m venv .venvmacOS / Linux:
source .venv/bin/activateWindows PowerShell:
.venv\Scripts\Activate.ps1pip install -r requirements.txtpython main.pyThe main Python packages are:
opencv-pythonmediapipenumpy
The MediaPipe pose model file used by the game is already included in:
models/pose_landmarker_lite.task
This game should run on most modern laptops and desktops with a webcam.
- Python
3.10 - A webcam
- A machine that can run OpenCV camera capture and MediaPipe pose tracking
- 4 GB RAM or more
- macOS, Windows, or Linux
- 8 GB RAM or more
- A recent Intel, AMD, or Apple Silicon CPU
- A webcam that supports
720p - Good room lighting so face and arm detection stay stable
- A camera may support
60 FPSonly at certain resolutions or formats. - If the HUD shows
@30, your current camera mode is running at 30 FPS. - Better lighting usually improves both face tracking and arm blocking.
Most game settings live in:
Useful values you can change:
GAME_MODETARGET_FPSFULLSCREEN_WINDOW- jab/hook sizing and timing values
- pad-work timing values
- camera and face-detection tuning values
- main.py: main game loop
- settings.py: tunable variables and mode helpers
- entities.py: attack and pad classes
- combos.py: combo and spawn builders
- vision.py: webcam, face detection, pose tracking, arm blocking
- ui.py: HUD and on-screen text drawing
- game_utils.py: shared geometry and helper utilities
- Make sure no other app is using the camera
- Check that Python has camera permission in your OS settings
- Stand farther back so your upper body fits in frame
- Increase room lighting
- Make sure your face is not heavily backlit
- Lower the camera resolution in
settings.py - Reduce face/pose detection cost in
settings.py - Check the on-screen timing values for
Read,Face, andPose