2D Game Engine

A full-fledged 2D game engine build in C++

Posted by Bart Blaak on January 26, 2023 · 2 mins read

Contents:


Context

This project was a group project during my minor Systems Programming in C++ at Avans University of Applied Sciences. Me and two others were tasked with creating a 2D game engine using C++. I took part through the whole process; from planning, to design, to programming.

Technical Details

  • Build in C++
  • Used C libraries:
    • SDL2 for rendering, audio, and input
    • Box2D for Physics
    • TinyXml for parsing tilemaps
  • Used C++ libraries:
    • Boost Asio for networking

Core functionalities

The engine contains all the core components often used by game engines: physics, graphics rendering, user input, and audio. Next to that, it also contains support for basic game AI and networking (multiplayer).

A simple diagram showing the overview of the engine:

engine overview 1

As a game programmer, you can use the Entity Component System (ECS) to create GameObjects and add components to them. Next to that, you can build tilemaps which can be loaded as the map for your scene.

If you’re familiar with Unity, our engine uses a similar structure. Here’s an oversimplified diagram showing the engine’s ECS structure:

Demos

Here are two quick demos in which multiple engine features come together. Perhaps try to think of which engine functionalities are being used for which objects!

First, a quick demo of a mini game in which you have to try to build a tower with boxes as high as the red line before the timer runs out.

And here’s a short demo showing the AI capabilities (among other things), namely the rockets and aliens, of which the former have “flocking” behavior and object avoidance (they try to avoid the spinning seesaw). The floating aliens have “wandering” behavior, which literally means they wander around the map. Both the rockets and aliens have wall avoidance (so they don’t disappear from the screen).

Further Exploration

Interested in the more detailed stuff? You are welcome to check out: