A beautiful, feature-rich Snake game built with Python and Pygame, complete with background music, power-ups, mini-games, high score tracking, modern UI, and Docker support!
- ?? Classic Snake gameplay with smooth controls
- ?? Background Music - Looping background music during gameplay
- ?? High Score System - Persistent score tracking (saves top 10 scores)
- ?? Latest Score Display - Shows your most recent score
- ?? New High Score Detection - Highlights when you beat your record
- ?? Modern UI Design - Animated gradient backgrounds, rounded corners, smooth animations
- ? Particle Effects - Visual feedback when eating food and collecting items
- ?? Enhanced Graphics - Snake with eyes, glowing effects, animated backgrounds
- ?? Sidebar - Real-time score, speed, power-ups, and controls display
- ?? Progressive Speed - Game speeds up as you score more points
- ? Special Food - Golden food gives bonus points (25 instead of 10)
- ?? Coins - Collect coins to trigger mini-games!
- ?? Time Slow (Press 1) - Slow down time for easier navigation
- ?? Zoom (Press 2) - Zoom in to see better
- ? Speed Boost (Press 3) - Temporarily increase speed
- ??? Shield (Press 4) - Protect against one collision
- ?? Speed Challenge - Collect coins to trigger mini-games with bonus scoring!
- Arrow Keys: Move the snake (Up, Down, Left, Right)
- SPACE: Start game (from menu) or return to menu (from game over)
- R: Reset the game (during gameplay)
- 1-4: Activate collected power-ups (Time Slow, Zoom, Speed, Shield)
- ESC: Quit game or return to menu
- Python 3.11+
- pygame 2.5.2
Note: Use python3 instead of python on Linux/WSL.
- Install dependencies:
pip install -r requirements.txt
# or
pip install pygame- Run the game:
python3 snake_game.pyWSL2 Audio Note: WSL2 doesn't have audio support by default. To hear music:
- Option A: Run on Windows directly (not in WSL)
- Option B: Set up audio passthrough in WSL2 (complex setup)
- Option C: Use Docker (game works but no audio)
Note: Make sure Now It Rains.mp3 or Dreamin'.mp3 is in the same directory as snake_game.py for background music.
- Build the Docker image:
docker build -t snake-game .Note: If you get an error about Dreamin'.mp3 not found during build, you can comment out the COPY line for the music file in the Dockerfile. The game will work without music.
- Run the container (requires X11 forwarding for GUI):
# For WSL/Linux with X11
xhost +local:docker
docker run -it --rm \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
snake-gameNote:
- Audio/Music: Docker containers don't have audio devices by default. Music will only play when running locally (not in Docker).
- For WSL2 with Windows, you may need to:
- Install an X server (like VcXsrv or X410)
- Set
DISPLAY=localhost:0.0or configure X11 forwarding
docker-compose up --build- Start Screen: Press SPACE to begin
- Gameplay: Use arrow keys to control the snake
- Eat Food:
- Red food = 10 points
- Golden food = 25 points (special bonus!)
- Collect Coins: Purple coins ($) trigger mini-games!
- Collect Power-Ups: Pick up glowing power-ups and press 1-4 to activate
- Avoid: Walls and your own tail
- Speed: Game gets faster as your score increases
- High Scores: Your scores are automatically saved
- Regular Food: 10 points each
- Special Food (Golden): 25 points each
- Mini-Game Bonus: Double points during mini-games!
- Mini-Game Completion: +50 bonus points
- Speed Bonus: Game speed increases every 50 points
- High Scores: Top 10 scores are saved to
high_scores.json - Latest Score: Your most recent score is displayed on the menu
- New Record: When you beat your high score, it's highlighted!
- Power-ups spawn randomly on the field
- Collect them by moving your snake over them
- Collected power-ups appear in the sidebar
- 1: Time Slow - Slows down game speed (5 seconds)
- 2: Zoom - Zooms in for better visibility (5 seconds)
- 3: Speed Boost - Increases movement speed (5 seconds)
- 4: Shield - Protects against one collision (5 seconds)
- ?? Orange: Time Slow
- ?? Purple: Zoom
- ?? Green: Speed Boost
- ?? Blue: Shield
- Trigger: Collect purple coins ($) scattered around the field
- Duration: ~3 seconds
- Reward: Double points for all food collected during mini-game + 50 bonus points
- Goal: Collect as much food as possible during the mini-game!
- Animated Backgrounds: Dynamic gradient backgrounds that shift over time
- Rounded Corners: Smooth, polished visuals on all elements
- Sidebar: Real-time game stats, power-up status, and controls
- Particle Effects: Visual feedback when eating food and collecting items
- Animations: Smooth transitions, pulsing effects, and glowing elements
- Color Coding: Different colors for different game elements
- Snake Eyes: Snake head shows eyes facing movement direction
- Shield Effect: Visual shield circle when shield power-up is active
snake_game.py- Main game fileDreamin'.mp3- Background music filehigh_scores.json- Saved high scores (auto-generated)requirements.txt- Python dependenciesDockerfile- Docker configurationdocker-compose.yml- Docker Compose setup.gitignore- Git ignore file
Local (WSL2/Linux):
- WSL2 doesn't have audio support by default - this is expected
- To hear music, run the game on Windows directly (not in WSL)
- Or set up PulseAudio/WSLg for audio passthrough (advanced)
- Ensure music files are in the same directory:
Now It Rains.mp3orDreamin'.mp3 - Check that pygame.mixer is properly initialized
- Game will run without music if audio is unavailable
Docker:
- Docker containers don't have audio devices by default - this is expected
- Music will only play when running locally (outside Docker)
- See "Docker Audio Issues" section below
- Docker containers don't have audio devices by default - This is expected behavior
- Music will only play when running locally (outside Docker):
python snake_game.py - In Docker, you'll see: "Warning: Audio not available. Game will run without music."
- This is normal - the game functions perfectly without audio
- To hear music, run the game locally instead of in Docker
If pygame doesn't display in Docker, run locally:
pip install -r requirements.txt
python snake_game.pySet DISPLAY variable:
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0Make sure the game has write permissions in the directory. Scores are saved to high_scores.json in the same directory as the game.
- Special Food: Look for golden food - it's worth more points!
- Coins: Collect purple coins to trigger mini-games for bonus points
- Power-Ups: Save power-ups for difficult situations
- Shield: Use shield when you're about to hit a wall or yourself
- Time Slow: Perfect for navigating tight spaces
- Mini-Games: Try to collect as much food as possible during mini-games
- Speed Management: As the game speeds up, plan your moves ahead
- Pattern Recognition: Learn to predict where food will spawn
- Corner Strategy: Be careful in corners - they're collision hotspots
The game includes background music (Dreamin'.mp3) that loops during gameplay. The music adds atmosphere and enhances the gaming experience!
Enjoy the game! ?????