A fun and interactive Fruit Ninja game built with pygame and MediaPipe pose estimation. Originally developed for FPT University, this version includes a gift reward system based on player performance!
This project was created for FPT University as an interactive game that combines computer vision with gamification. Players use their body movements tracked by a webcam to slice falling fruits and earn rewards based on their scores.
- Motion-Controlled Gameplay: Use your hands to slice fruits through webcam tracking
- Fruits & Obstacles:
- 🍍 Pineapple
- 🍉 Watermelon
- 🥝 Kiwi
- 🍊 Orange
- 💣 Bomb (avoid this!)
- Gift Reward System: Earn different gift tiers based on your final score
- High Score Tracking: Your best score is automatically saved
- Dual Hand Tracking: Black knife trails follow both hands
- Smart Start Menu: Raise hands to begin (prevents accidental starts)
- Full Screen Mode: Immersive gameplay experience
The game rewards players with different gifts based on their final score:
| Score Range | Gift Tier | Image |
|---|---|---|
| 80+ points | 🎁 Premium Gift | present/present_1.png |
| 60-79 points | 🎁 Good Gift | present/present_3.png |
| 30-59 points | 🎁 Basic Gift | present/present_2.png |
| Below 30 | 😢 Try Again | Random sad fruit image |
- Navigate to the
present/folder - Replace the gift images:
present_1.png- Premium gift (80+ points)present_3.png- Good gift (60-79 points)present_2.png- Basic gift (30-59 points)
- Keep the same filenames or update the paths in
scripts/fruit_ninja.py
Edit these constants in scripts/fruit_ninja.py (lines 44-46):
GIFT_1_SCORE_THRES = 80 # Premium gift threshold
GIFT_2_SCORE_THRES = 60 # Good gift threshold
GIFT_3_SCORE_THRES = 30 # Basic gift thresholdThe high score is stored in highest_score.txt. To reset it:
- Delete the file, or
- Edit
highest_score.txtand change the number to0
UV is a fast Python package installer and resolver. Install dependencies with:
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install project dependencies
uv syncpip install pygame opencv-python mediapipepip install -e .-
Clone the repository:
git clone <repository-url> cd Fruit-Ninja-VR_With_Gift
-
Install dependencies (see Installation section above)
-
Run the game:
python scripts/fruit_ninja.py
-
Gameplay:
- Stand in front of your webcam
- Raise your hands to start the game
- Move your hands to slice falling fruits
- Avoid bombs! 💣
- Try to get the highest score and earn the best gift!
-
Exit: Press the
Esckey to quit
- Hand Movement: Slice fruits
- Hands Up: Start game from menu
- Esc Key: Exit game
Edit settings in scripts/fruit_ninja.py:
FPS = 25 # Frame rate
SHOW_MINICAM = False # Show webcam preview in corner
GAME_WIDTH = 1280 # Window width (height auto-adjusts to 16:9)Change the camera device in line 136:
cap = cv2.VideoCapture('/dev/video2') # Linux
# cap = cv2.VideoCapture(0) # Default camera (Windows/Mac)For IP cameras, use:
stream_url = "rtsp://username:password@ip:port/stream"
cap = cv2.VideoCapture(stream_url, cv2.CAP_FFMPEG)- pygame >= 2.6.1 - Game framework
- opencv-python >= 4.11.0 - Computer vision and camera handling
- mediapipe >= 0.10.21 - Pose estimation and hand tracking
- Python >= 3.10
Create a standalone executable using PyInstaller:
# Install PyInstaller
pip install pyinstaller
# Build executable (adjust PYTHON_PATH to your Python installation)
pyinstaller -w --onefile \
--paths="PYTHON_PATH/Python39/Lib/site-packages/cv2" \
--collect-data mediapipe \
--add-data "PYTHON_PATH/Python39/Lib/site-packages/mediapipe;mediapipe" \
-i "images/icon.ico" \
scripts/fruit_ninja.pyThe executable will be created in the dist/ folder.
Fruit-Ninja-VR_With_Gift/
├── scripts/
│ ├── fruit_ninja.py # Main game file
│ ├── fruit.py # Fruit class
│ └── calculations.py # Helper functions
├── images/ # Game images and backgrounds
├── sounds/ # Sound effects and music
├── present/ # Gift images
│ ├── present_1.png # Premium gift
│ ├── present_2.png # Basic gift
│ └── present_3.png # Good gift
├── fonts/ # Custom fonts
├── highest_score.txt # Stores the highest score
├── pyproject.toml # Project dependencies
└── README.md # This file
- Original Project: Fruit-Ninja-VR by mmbaguette
- Enhanced for: FPT University
- Frameworks: pygame, MediaPipe, OpenCV
This project is based on the original Fruit-Ninja-VR project. Please refer to the original repository for licensing information.
Enjoy the game and aim for that premium gift! 🎁

