Skip to content

MateiS2002/python-asteroids-boot.dev

Repository files navigation

Asteroids in Python

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.

Certificate

bootdev_certificate-5

What I Learned

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.Vector2 for 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 Group containers.
  • 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.

Usage

This project uses uv for dependency management, but you can also use pip with the requirements.txt file.

Option 1: Using uv (Recommended)

Setup Virtual Environment

# Create a virtual environment and install dependencies
uv sync

Activate Virtual Environment

# On macOS/Linux:
source .venv/bin/activate

# On Windows:
.venv\Scripts\activate

Option 2: Using pip

# Install dependencies
pip install -r requirements.txt

Run the game

python3 main.py

Controls

  • Left/Right Arrows: Rotate the spaceship.
  • Up Arrow: Move forward.
  • Down Arrow: Move backward.
  • Spacebar: Shoot bullets.

Output

Starting Asteroids with pygame version: 2.x.x
Screen width: 1280
Screen height: 720
Game over!

About

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.

Resources

Stars

Watchers

Forks

Contributors

Languages