Skip to content

nova-550/Asteroids-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asteroids-Game

Description

This is a classic Asteroids game implemented in Python using the Pygame library. The player controls a spaceship, navigating through space while avoiding and destroying asteroids. The game features sound effects, background music, and a scoring system.

Features

  • Object-Oriented Design: Uses classes for Ship, Asteroid, and Bullet objects
  • Player-controlled spaceship with rotation and thrust
  • Multiple asteroids that move across the screen with increasing difficulty
  • Bullet shooting mechanics with collision detection
  • Lives System: 3 lives with respawn on collision
  • Level Progression: Automatic level advancement with increasing asteroid count
  • High Score Tracking: Persistent high score saved to file
  • Pause Functionality: Press 'P' to pause/unpause the game
  • Restart Option: Press 'R' to restart after game over
  • Collision detection for ship-asteroid and bullet-asteroid interactions
  • Score tracking with level and lives display
  • Sound effects for thrust, shooting, and explosions
  • Background music and visual effects
  • Error handling for missing assets

Requirements

  • Python 3.x
  • Pygame library (install via pip install pygame)

Installation and Setup

  1. Create a virtual environment (recommended):
    python -m venv venv
    
  2. Activate the virtual environment:
    • On Windows: venv\Scripts\activate
    • On macOS/Linux: source venv/bin/activate
  3. Install dependencies:
    pip install -r requirements.txt
    
  4. Ensure all game files are in the same directory structure.
  5. Run the game with: python final.py
  6. Use keyboard controls to play.

Controls

  • Left Arrow: Rotate ship left
  • Right Arrow: Rotate ship right
  • Up Arrow: Thrust forward (activates thruster sound and visual) l- Spacebar: Shoot bullets
  • Close window: Quit the game

File Structure

  • final.py: Main game script containing all logic
  • images/: Directory containing game sprites and backgrounds (e.g., ship.png is loaded as ship_img, ship_thrusted.png as ship_thrusted_img in code)
  • sounds/: Directory containing audio files for effects and music

Credits

  • Game developed using Pygame
  • Assets: Custom images and sounds (ensure proper licensing if redistributing)

Configuration

The game includes configurable parameters in final.py:

  • NUM_ASTEROIDS: Number of asteroids (default: 5)
  • ASTEROID_SPEED: Speed of asteroids (default: 2)
  • BULLET_SPEED: Speed of bullets (default: 10)
  • SHIP_SPEED: Speed of ship thrust (default: 10)
    • Note: In the code, ship images are referenced as ship_img and ship_thrusted_img to avoid conflict with the Ship class instance.
  • FRICTION: Ship deceleration rate (default: 0.2)

Error Handling

  • The game includes error handling for missing image and sound files
  • Graceful degradation if audio assets are not found
  • Informative error messages for debugging

Notes

  • The game runs at 60 FPS
  • Asteroids wrap around screen edges
  • Bullets travel in straight lines
  • Score increases for each destroyed asteroid
  • Background music loops indefinitely
  • Sound effects play only if assets are available

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages