Skip to content

TM-Mehrab-Hasan/SpaceWar-Game-In-CPP

Repository files navigation

SpaceWar Game in C++

A 2D space shooter game built with modern C++ and OpenGL. Navigate through space, battle enemies, and survive in this action-packed arcade-style game!

Cover Image

Features

  • 2D Space Combat: Control your spaceship and battle enemy ships
  • Multiple Enemy Types: Various AI-controlled enemies with different behaviors
  • Parallax Scrolling: Beautiful layered background effects for depth
  • Dynamic Audio: Sound effects and background music
  • Health System: Player health with regeneration mechanics
  • Bullet Physics: Realistic projectile system with collision detection
  • Scalable Difficulty: Enemies spawn with increasing difficulty over time

Screenshots

Spaceships

Blue Ship Gray Ship Green Ship Purple Ship

Game Elements

Health Bar Health UI Elements

Technology Stack

  • Language: C++ (C++17)
  • Graphics: OpenGL with GL2D renderer
  • Audio: raudio library
  • Input: GLFW for window management and input handling
  • Math: GLM (OpenGL Mathematics)
  • Build System: CMake
  • Libraries Used:
    • GLFW 3.3.2 - Window and input management
    • GLAD - OpenGL function loading
    • GLM - Mathematics library
    • stb_image - Image loading
    • stb_truetype - Font rendering
    • raudio - Audio playback
    • Dear ImGui - Debug UI (optional)
    • ENet - Networking capabilities

Project Structure

SpaceWar Game in CPP/
├── src/
│   ├── gameLayer/          # Core game logic
│   │   ├── gameLayer.cpp   # Main game loop and logic
│   │   ├── bullet.cpp      # Bullet physics and rendering
│   │   ├── enemy.cpp       # Enemy AI and behavior
│   │   └── tiledRenderer.cpp # Background rendering
│   └── platform/           # Platform-specific code
│       ├── glfwMain.cpp    # Application entry point
│       ├── platformInput.cpp # Input handling
│       └── opterPlatformFunctions.cpp # Utility functions
├── include/                # Header files
├── resources/              # Game assets
│   ├── spaceShip/         # Ship sprites and animations
│   ├── space/             # Space backgrounds and objects
│   ├── background*.png    # Parallax background layers
│   ├── health*.png        # Health UI elements
│   └── *.flac            # Audio files
├── thirdparty/            # External libraries
└── CMakeLists.txt         # Build configuration

Building the Game

Prerequisites

  • CMake (3.10 or higher)
  • C++ Compiler with C++17 support:
    • Visual Studio 2019/2022 (Windows)
    • GCC 7+ (Linux)
    • Clang 6+ (macOS)

Build Steps

  1. Clone the repository:

    git clone <repository-url>
    cd "SpaceWar Game in CPP"
  2. Generate build files:

    cmake -S . -B build
  3. Build the project:

    cmake --build build --config Release
  4. Run the game:

    • The executable will be in build/Release/
    • Make sure the resources/ folder is in the same directory as the executable

Alternative Build (Visual Studio)

For Visual Studio users:

cmake -S . -B build -G "Visual Studio 17 2022"
cmake --build build --config Release

Controls

  • Movement: WASD or Arrow Keys
  • Aim: Mouse cursor
  • Shoot: Left Mouse Button
  • Exit: ESC key

Game Mechanics

Player

  • Move freely in 2D space
  • Aim with mouse cursor
  • Shoot projectiles at enemies
  • Health regenerates slowly over time
  • Game over when health reaches zero

Enemies

  • Spawn randomly around the player
  • Different ship types with varying:
    • Speed and maneuverability
    • Fire rate and bullet speed
    • Health and durability
  • AI that pursues and attacks the player
  • Despawn when too far from player

Combat

  • Projectile-based combat system
  • Collision detection between bullets and ships
  • Health system for both player and enemies
  • Audio feedback for shooting and impacts

Asset Credits

  • Fonts: CommodorePixeled.ttf
  • Graphics: Custom space ship sprites and UI elements
  • Audio: Sound effects for shooting and ambient audio

Development Notes

This project demonstrates:

  • Modern C++ game development practices
  • OpenGL 2D rendering techniques
  • Entity-component-like architecture
  • Audio integration in games
  • CMake build system setup
  • Cross-platform game development

Contributing

Feel free to submit issues and enhancement requests!

License

This project is for educational purposes. Please check individual library licenses in the thirdparty/ directory.


Original Tutorial: Based on the YouTube video by meemknight.

CMake Setup Tutorial: CMake Setup Video

Part 2 Tutorial: Adding Menu System

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published