A touchless take on the classic Fruit Ninja experience that turns any webcam into a slicing arena. MediaPipe tracks your index finger in real time, OpenCV renders transparent PNG sprites over the camera feed, and a lightweight physics loop powers the fruit throws, gravity, bombs, and combo system.
- Hand tracking: MediaPipe Hands follows your index finger tip with sub-pixel smoothing.
- Arcade physics: Fruit fire out of the bottom of the frame, peak near the top, then crash back down with gravity and dynamic spawn speeds.
- High-fidelity sprites: Procedurally shaded watermelons, bananas, apples, oranges, pineapples, hearts, splashes, and bombs regenerated automatically whenever art updates ship.
- Stylized HUD + trail: Wood-tone HUD blocks, glowing combo popups, and a golden blade trail mimic the original Fruit Ninja presentation.
- Combos + bombs: Chaining slices inside the combo window ramps multipliers while nicking a bomb ends the round immediately.
- Quick controls:
Qquits,Rrestarts after a game over.
- Create a virtual environment (recommended).
py -3 -m venv .venv .venv\Scripts\activate
- Install dependencies.
pip install -r requirements.txt - Run the game. Use module mode so the relative imports resolve:
python -m src.main
Want to customize the slicer? Fork the project under your own account and sync it locally:
- Fork on GitHub. Visit the original repo, click Fork, and keep the default options. This clones the code under your GitHub username.
- Clone your fork.
git clone https://github.com/<your-username>/ninja-fruit.git cd ninja-fruit
- Add the upstream remote so you can pull future updates from the source.
git remote add upstream https://github.com/tubakhxn/ninja-fruit.git
- Install deps & run using the commands from the Getting Started section.
- Open in VS Code.
code .launches the workspace; use the Run/Debug panel if you prefer.
To contribute back, push a branch to your fork and open a pull request targeting tubakhxn/ninja-fruit.
- Keep the camera steady with good frontal lighting so MediaPipe sees your hand.
- Slice with fast, decisive motions. Slow drags will not cross the speed threshold.
- Bombs end the run when cut, so weave around their trajectories.
- Missed fruit chips away at the three-life pool. Staying in combo territory (≈1 second between slices) keeps the multiplier high.
.
├── assets/ # Auto-generated PNG sprites (created on first run)
├── requirements.txt
├── README.md
└── src/
├── asset_utils.py # Ensures sprites exist and loads them with alpha
├── config.py # Tunable gameplay constants
├── game_objects.py # Dataclasses + spawn helpers
├── hand_tracker.py # MediaPipe wrapper for index-finger detection
├── ui_overlay.py # HUD drawing helpers
└── main.py # Game loop, physics, UI, gesture detection
- Webcam not found: adjust
CAMERA_INDEXinsidesrc/config.py. - Sluggish frame rate: drop
CAMERA_WIDTH/HEIGHTor lowerTARGET_FPS. - Hand not detected: make sure the full hand stays inside the frame; reduce detection thresholds in
HandTrackerif needed. - Old sprites showing: delete the
assets/folder or bumpASSET_VERSIONinsrc/asset_utils.py; the generator will redraw every PNG on the next launch.
Built with ❤️ by tubakhxn. Feel free to credit or tag the dev when you show off your webcam slicing skills.