This project is a simple implementation of the classic Snake game using Python and Pygame.
- The snake grows in length every time it eats food.
- The speed of the snake increases every time it eats food.
- The game ends when the snake collides with itself.
The main game loop is in the gameLoop function. Here's a brief overview of what the code does:
- The snake's position is stored in the
snake_Listlist, with the head of the snake being the last element. - If the length of
snake_Listis greater thanLength_of_snake, the first element (the tail) is removed. - If the head of the snake collides with any part of its body, the game ends.
- The
our_snakefunction is called to draw the snake on the screen. - The
scorefunction is called to display the current score. - The screen is updated with
pygame.display.update(). - If the snake's head is at the same position as the food, new food is generated at a random position, the length of the snake is increased by 1, and the speed of the snake is increased.
- The game speed is controlled by the
clock.tick(snake_speed)line.
To run the game, you need to have Python and Pygame installed. Once they are installed, you can run the game with the following command:
python main.py