Skip to content

Control a snake using hand gestures! Built with OpenCV, MediaPipe, and Streamlit, collect points within 60 seconds in this interactive game. ๐Ÿš€๐Ÿ

Notifications You must be signed in to change notification settings

Mehnaz2004/Hand-Controlled-Snake-Game-using-OpenCV

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Gesture Controlled Snake Game

๐Ÿ“Œ Introduction

Play the classic Snake game using just your hand gestures! This game uses OpenCV and MediaPipe to track hand movements via a webcam, allowing you to guide the snake and collect points.

โœจ Features

  • Hand-Controlled Snake: Move your hand to navigate the snake.
  • Smooth Movement & Trails for a better gaming experience.
  • Real-time Score & Timer displayed on the sidebar.
  • Dynamic Ball Mechanics:
    • 3 Balls Always on Screen: New balls appear when one is collected or expires.
    • Point System:
      • ๐ŸŸข Green Ball โ†’ 1 Point
      • ๐ŸŸ  Orange Ball โ†’ 2 Points
      • ๐Ÿ”ด Red Ball โ†’ 3 Points
  • Ball Collection System:
    • If the snake touches a ball, it disappears and adds points to the score.
    • If the ball is not collected in 5 seconds, it disappears and a new one appears.
  • Game Over Screen with the final score displayed and an automatic restart after timeout.
  • Sound effects when collecting balls.
  • OpenCV Game Window Embedded in Streamlit.

๐ŸŽฎ How to Play?

1๏ธโƒฃ Run the game:

streamlit run game.py

2๏ธโƒฃ Start the game by clicking "Start Game" in the sidebar.
3๏ธโƒฃ Control the Snake with Your Hand: Move your hand in front of the camera to navigate the snake.
4๏ธโƒฃ Collect the balls (๐ŸŸข๐ŸŸ ๐Ÿ”ด) to gain points.
5๏ธโƒฃ The game lasts 60 seconds, after which a Game Over screen appears with your final score.

๐Ÿ—๏ธ Technologies Used

  • Python
  • OpenCV (for real-time video processing)
  • MediaPipe (for hand tracking)
  • Streamlit (for embedding the OpenCV window in a web-based UI)

๐Ÿ› ๏ธ Setup & Installation

1๏ธโƒฃ Clone the repository:

  git clone https://github.com/MehnazAli2004/Hand-Controlled-Snake-Game-using-OpenCV.git
  cd Hand-Controlled-Snake-Game-using-OpenCV

2๏ธโƒฃ Install dependencies:

pip install -r requirements.txt

3๏ธโƒฃ Run the game:

streamlit run game.py

4๏ธโƒฃ Grant camera access when prompted and start playing!

๐Ÿš€ Future Enhancements

  • ๐ŸŸก Collision Detection (self-collision & walls)
  • ๐ŸŸก Leaderboard & High Scores
  • ๐ŸŸก Power-ups & Special Abilities
  • ๐ŸŸก Multiplayer Mode
  • ๐ŸŸก Improved Graphics & UI Enhancements

๐Ÿ“œ License

This project is open-source. Feel free to use, modify, and contribute!

About

Control a snake using hand gestures! Built with OpenCV, MediaPipe, and Streamlit, collect points within 60 seconds in this interactive game. ๐Ÿš€๐Ÿ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages