This project is a simple snake game developed using Python and Pygame. The game features a start menu, a score system, and different graphical representations of the snake's body.
-
Install Python: Ensure you have Python installed on your machine. You can download it from python.org.
-
Install Pygame: Install the Pygame library using pip:
pip install pygame
-
Clone the Repository: Clone this repository or download the code.
-
Assets: Ensure the following image assets are placed in an
./asset/
directory:apple.png
head_up.png
head_down.png
head_right.png
head_left.png
tail_up.png
tail_down.png
tail_right.png
tail_left.png
body_vertical.png
body_horizontal.png
body_topright.png
body_topleft.png
body_bottomright.png
body_bottomleft.png
-
Navigate to the Project Directory: Open your terminal and navigate to the directory where the script is located.
-
Run the Game:
python snake_game.py
-
Start Menu:
- The game starts with a menu where you can choose to
Play
orQuit
.
- The game starts with a menu where you can choose to
-
Snake Movement:
- The snake moves automatically in the direction it is facing.
- You can control the snake's direction using the arrow keys:
Up Arrow
to move upRight Arrow
to move rightDown Arrow
to move downLeft Arrow
to move left
-
Fruit Collection:
- The snake grows in length when it eats the fruit (represented by an apple).
-
Collision Detection:
- The game ends when the snake collides with the walls or itself.
-
Score Display:
- The current score (based on the length of the snake) is displayed in the bottom-right corner.
-
Game Over Screen:
- When the game ends, a "GAME OVER" message and the final score are displayed.
-
SNAKE:
- Handles the snake's properties and behavior, including movement, growth, and graphical representation.
-
FRUIT:
- Manages the fruit's position and rendering.
-
MAIN:
- Coordinates the game's core logic, such as updating game state, checking for collisions, and drawing game elements.
-
Button:
- Manages the interactive buttons in the start menu.
-
STARTMENU:
- Controls the start menu display and user interaction.
- Event Handling: Processes user inputs and game events.
- Game State Management: Controls transitions between the start menu, game play, and game over states.
- Rendering: Updates the display with the current state of the game.
This project is open-source and can be freely used and modified.