🎯 Overview
Snake Game is a modern version of the classic arcade game, implemented in Python using Pygame for graphics and Pygbag for web deployment. Control the snake, eat food, and grow longer while avoiding collisions with walls and yourself.
This project demonstrates:
- Python fundamentals: control flow, data structures, and event handling
- Pygame: graphical interface, game loop, and input management
- Pygbag: packaging and running Python games in the browser
🚀 Features & Mechanics
Classic Gameplay
Control the snake to eat food and grow. Avoid walls and your own tail.
Scoring System
Earn points for each food eaten. Score is displayed in-game.
Mobile Support
Tap screen corners to control the snake on mobile devices.
Restart & Exit
Restart with R key or tap. Exit with ESC or via menu.
Responsive Design
Playable on desktop and mobile browsers.
Game Flow
- Start the game and control the snake using keyboard or touch.
- Eat food to grow and increase your score.
- Avoid collisions with walls and yourself.
- Game over when you collide. Restart or exit as desired.
🛠️ Technologies & Deployment
- Python 3.x: Main programming language
- Pygame: Graphics, event handling, and game loop
- Pygbag: Converts Python/Pygame games to run in the browser (WebAssembly)
- HTML5/CSS3: Used for web packaging and styling
Pygbag Web Deployment
- Rename your main file to
main.py (required by Pygbag)
- Install pygbag:
pip install pygbag
- Build for web:
python -m pygbag --build .
- Open
build/web/index.html in your browser
- Ready for publishing on any static web host
# Example build command
python -m pygbag --build .
🎮 How to Play
Start Game
Run main.py locally or open index.html (web build) in your browser.
Control Snake
Use arrow keys or tap screen corners to change direction.
Eat Food
Guide the snake to eat food and grow longer.
Restart
Press R or tap Game Over screen to restart.
Exit
Press ESC or use menu to exit the game.
Controls
- Keyboard: Arrow keys to move, R to restart, ESC to exit
- Mouse/Touch: Tap screen corners to move, tap Game Over to restart
🌟 Highlights & Customization
- Zero dependencies for web: Runs in browser with Pygbag, no installation needed
- Responsive design: Playable on desktop and mobile
- Customizable appearance: Easily change colors and grid size in
main.py
- Educational: Great for learning Python, Pygame, and web deployment
- Clean code structure: Well-organized and commented for easy extension
🚦 Project Status
✅ Completed
✅ Tested
✅ Responsive
✅ Web-ready
✅ Educational
All features implemented and tested. Play locally or in your browser. Clean, secure, and optimized code for learning and fun!