A classic Snake Game built using Python and Pygame, featuring a custom home screen, background music, and highscore tracking.
Grow your snake by eating apples, avoid collisions, and try to beat your highscore!
The Snake Game is a Python-based console and GUI hybrid application using Pygame. Players control a snake to collect apples, growing in size with each apple eaten. The game tracks score and highscore and includes:
- Custom home screen and game-over screen
- Background music and sound effects
- Real-time score and highscore display
- Collision detection with walls and self
- Smooth gameplay with increasing snake length
This project demonstrates Python fundamentals such as loops, conditionals, functions, file handling, and basic game logic.
- Python 3.10 or above
- Supported Operating Systems:
- Windows
- Linux
- macOS
pygamerandomossys
No external libraries beyond Pygame are required.
- Loops (
while) - Conditional Statements (
if,elif,else) - Functions
- File Handling (
Highscore.txt) - User Input Handling
- Random Module (
random.randint) - Pygame Graphics and Sound
- Game Logic and Collision Detection
- Run the game.
- The home screen appears with background music.
- Press Enter to start the game.
- Control the snake using the arrow keys:
- ⬆ Up
- ⬇ Down
- ⬅ Left
- ➡ Right
- Eat apples to grow your snake and increase your score.
- Avoid colliding with the walls or your own tail.
- When the game ends:
- Your score and highscore are displayed
- Press Enter to restart
The highscore is stored in Highscore.txt and persists across game sessions.
cd snake-game
Make sure Python 3.10+ is installed.
Run the game from the terminal or command prompt:
Alternatively, you can create an executable .exe using PyInstaller:
pyinstaller --onefile --windowed --icon snake_icon.ico
--add-data "apple.png;."
--add-data "snakehome.png;."
--add-data "snakebackground.jpg;."
--add-data "Snakeend.png;."
--add-data "02. Clair-Obscur.mp3;."
--add-data "gameover.wav;."
--add-data "Highscore.txt;."
snake_game.py
The .exe will be generated in the dist/ folder.
snakehome.png – Home screen
snakebackground.jpg – Main game background
Snakeend.png – Game-over screen
apple.png – Food for the snake
- Clair-Obscur.mp3 – Background music
gameover.wav – Game-over sound effect
Highscore.txt – Stores
Aeshan Chowdhury