š Fruit Ninja ā Web Edition
A browser-based Fruit Ninja game with real-time webcam hand tracking using MediaPipe. Slice fruits by moving your index finger in front of your camera!
⨠Features
- Real-time hand tracking via MediaPipe Tasks Vision (runs 100% in your browser)
- 3 difficulty levels ā Easy, Medium, Hard with different speeds, lives, and bomb rates
- Special fruits ā Golden (3Ć points), Ice (freeze), Bombs (avoid!)
- Combo system ā chain slices for multipliers up to 5Ć
- Bonus lives ā earn extra lives every 100 points
- Glowing trail that follows your finger
- Juice particles on every slice
- 60 FPS smooth gameplay on HTML5 Canvas
- Level select by hovering your finger over a card for 1.5 seconds
š® How to Play
- Allow camera access when prompted
- Hold up your index finger in front of the camera
- On the level select screen, hover your finger over a card for 1.5 s ā or press 1, 2, or 3 on the keyboard
- Swipe your index finger through fruits to slice them
- Avoid bombs (red glow) ā slicing one costs a life
- Slice the cyan āļø ICE fruit to freeze everything for 3.5 seconds
- Slice golden fruits (cyan ring) for 3Ć points
- Press R to return to level select after a game
š Local Development
# 1. Install dependencies
npm install
# 2. Start dev server
npm run dev
# 3. Open http://localhost:5173 in your browser
Note: The game requires HTTPS or localhost for webcam access. The Vite dev server handles this automatically.
āļø Deploy to Vercel
Option A ā Vercel CLI (recommended)
# 1. Install Vercel CLI
npm i -g vercel
# 2. Build and deploy
vercel
# Follow the prompts:
# - Set up and deploy? ā Y
# - Which scope? ā your account
# - Link to existing project? ā N
# - Project name ā fruit-ninja-web (or anything)
# - In which directory is your code? ā ./
# - Override build command? ā N
# - Override output directory? ā N
Your game will be live at https://your-project.vercel.app š
Option B ā Vercel Dashboard (drag & drop)
# 1. Build the project locally
npm run build
# 2. Go to https://vercel.com/new
# 3. Drag and drop the `dist/` folder
Option C ā GitHub Integration
- Push this repo to GitHub
- Go to https://vercel.com/new
- Import your GitHub repository
- Vercel auto-detects Vite ā click Deploy
Important: The
vercel.jsonin this repo sets required CORS headers (Cross-Origin-Embedder-PolicyandCross-Origin-Opener-Policy) needed by MediaPipe's WASM runtime. These are already configured.
š Project Structure
fruit-ninja-web/
āāā public/
ā āāā assets/ # Fruit PNG sprites (from original Python project)
āāā src/
ā āāā components/
ā ā āāā GameCanvas.jsx # Main canvas + game loop orchestrator
ā ā āāā StartScreen.jsx # Loading screen while MediaPipe initialises
ā āāā game/
ā ā āāā GameEngine.js # State machine, physics, slice detection
ā ā āāā Renderer.js # All canvas drawing (HUD, fruits, trail, etc.)
ā ā āāā Fruit.js # Fruit entity + spawn logic + segment distance
ā ā āāā WebcamTracker.js # MediaPipe hand landmarker wrapper
ā āāā utils/
ā ā āāā constants.js # Level configs, fruit catalog (ported from config.py)
ā āāā App.jsx
ā āāā main.jsx
āāā index.html
āāā vite.config.js
āāā vercel.json
āāā package.json
š Webcam & Privacy
- All hand tracking runs locally in your browser using WebAssembly
- No video data is sent to any server
- The MediaPipe model is downloaded from Google's CDN on first load (~8 MB, cached after)
š Tech Stack
| Layer | Technology |
|---|---|
| Framework | React 18 + Vite |
| Rendering | HTML5 Canvas 2D |
| Hand tracking | MediaPipe Tasks Vision (@mediapipe/tasks-vision) |
| Camera | Browser getUserMedia API |
| Deployment | Vercel |
šÆ Level Reference
| Level | Target | Lives | Bomb % | Speed |
|---|---|---|---|---|
| 1 EASY | 120 pts | 5 | 6% | Slow |
| 2 MEDIUM | 180 pts | 4 | 11% | Medium |
| 3 HARD | 250 pts | 3 | 17% | Fast |
ā” Performance Tips
- Use Chrome or Edge for best GPU-accelerated hand tracking
- Good lighting helps MediaPipe detect your hand reliably
- Keep your index finger extended and other fingers curled
- Fast, decisive swipes slice better than slow drags #ļæ½ ļæ½wļæ½eļæ½bļæ½ ļæ½ ļæ½
Log in or sign up for Devpost to join the conversation.