Space Shooter is a 2D arcade-style shooter game built with C++ and raylib. It was developed as a semester project for the Object-Oriented Programming (OOP) course at ITU. The game encapsulates major OOP principles such as inheritance, polymorphism, templates, file I/O, and design patterns like Singleton, all wrapped in an engaging and nostalgic arcade experience.
🧠 Classic concept — Modern C++
- Use
AandDkeys to move your spaceship left/right. - Press
SPACEto shoot bullets upward and destroy incoming enemies. - Each enemy destroyed gives you +10 points, but if:
- An enemy reaches the bottom → –10 points
- An enemy hits your ship → 💀 Game Over
- The game saves your progress automatically using a
.jsonfile in thePlayer_data/folder and maintains a global high score inHighestScore.txt.
| Concept | Implemented In |
|---|---|
| Encapsulation | Classes like Ship, Enemies, Bullets, etc. |
| Inheritance | All drawable objects inherit from Game_objects |
| Polymorphism | Virtual draw() function in base class |
| Templates | Player<U, S> class using templates |
| File I/O | Save/load scores via .json & .txt |
| Static / Singleton | Console and player score logic |
| Operator Overloading | operator<< in Player class |
class Game_objects {
protected:
int x, y;
public:
Game_objects(int x, int y);
virtual void draw() = 0; // Polymorphic draw
};float closestX = max(enemies[i].getX(), min(bullets[j].getX(), enemies[i].getX() + enemies[i].getWidth()));
float closestY = max(enemies[i].getY(), min(bullets[j].getY(), enemies[i].getY() + enemies[i].getHeight()));
float distanceX = bullets[j].getX() - closestX;
float distanceY = bullets[j].getY() - closestY;
if ((distanceX * distanceX) + (distanceY * distanceY) <= (bullets[j].getRadius() * bullets[j].getRadius())) {
bullets.erase(bullets.begin() + j);
enemies.erase(enemies.begin() + i);
score += 10;
}void Player<U, S>::saveToFile(U name) {
json j;
j[name] = getScore(name);
ofstream outfile(name + ".json");
outfile << setw(4) << j;
}float Game_Manager::level_Manager() {
if (score > 100) return 0.5;
else if (score < 200) return 1.0;
return 0.0;
}Space-Shooter/
├── .vs/
├── Fonts/ # Custom game fonts
├── Player_data/ # JSON files storing player scores
├── Sounds/ # Game background music and sound effects
├── external_lib/nlohmann/ # JSON library
├── x64/
│ └── Debug/
├── Bullets.cpp/h # Bullet logic
├── Console.cpp/h # Console class (friend of Game_Manager)
├── Enemies.cpp/h # Enemy logic and movement
├── Game_Manager.cpp/h # Main game loop and control logic
├── Game_objects.cpp/h # Abstract base class for all drawable objects
├── HighestScore.txt # Stores highest score across all players
├── Player.cpp/h # Player template class with file I/O
├── Ship.cpp/h # Player spaceship logic
├── Space-Shooter.cpp # Entry point for the game
├── Space-Shooter.sln # Visual Studio Solution file
├── Space-Shooter.vcxproj # Project configuration
| Dependency | Purpose |
|---|---|
| raylib | Graphics, Input, Audio |
| nlohmann/json | JSON I/O for player scores |
This project is built with Visual Studio on Windows.
- Clone this repository:
git clone https://github.com/Hassan-Mef/Space-Shooter-game.git
- Open the solution file Space-Shooter.sln in Visual Studio.
- Make sure raylib is properly set up in your include/lib directories.
- Build the project and run.
- On game launch, player is prompted to enter a name.
- If the name exists in
/Player_data, their profile is loaded. - If not, a new profile is created using
Player<string, int>with default score. - All scores are auto-saved after the game ends.
📝 Example:
Player_data/
└── Shaggy.json
{
"Shaggy": 120
}
- Applying OOP in real-world projects.
- Working with external libraries (raylib, JSON).
- Understanding memory, vector management, object lifecycles.
- Handling I/O via file streams for persistent data storage.
Made with ❤️ by a Hassan-Mef from ITU as part of the university OOP coursework.
This project is provided for academic and educational purposes. Feel free to fork, clone, or modify.
- Power-ups and level scaling
- Multiple enemy types with varying difficulty
- Add UI screens (pause, leaderboard, etc.)
- Gamepad and mobile support