Asteroids is my second Boot.dev project!
Asteroids is a classic arcade game built using Python and the Pygame library. In this game, you control a spaceship and must shoot and avoid asteroids to survive.
While building Asteroids, I practiced several advanced Python and game development concepts:
- Object-Oriented Programming (OOP): Using classes and inheritance to organize game objects like players, asteroids, and shots.
- Pygame Library: Implementing a game loop, handling user input, and rendering graphics.
- Vector Math: Using
pygame.Vector2for movement, rotation, and calculating object trajectories. - Collision Detection: Implementing circle-based collision logic to detect hits between game objects.
- Sprite Groups: Managing multiple game objects efficiently using Pygame's
Groupcontainers. - Game State Management: Implementing logic for shooting, asteroid splitting, and game-over conditions.
- Constants & Configuration: Organizing game parameters in a dedicated configuration file for easy balancing.
This project uses uv for dependency management, but you can also use pip with the requirements.txt file.
# Create a virtual environment and install dependencies
uv sync# On macOS/Linux:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activate# Install dependencies
pip install -r requirements.txtpython3 main.py- Left/Right Arrows: Rotate the spaceship.
- Up Arrow: Move forward.
- Down Arrow: Move backward.
- Spacebar: Shoot bullets.
Starting Asteroids with pygame version: 2.x.x
Screen width: 1280
Screen height: 720
Game over!
