Vladislav Pomogaev

Engineering Physics Graduate

2D Game Engine in C++


At the start of 2017 I really wanted to make my own 2D strategy game, similar to “FTL” and other indie games. I started by getting to know the SDL (Simple Directmedia Layer) library in C++ by using it in a variety of test projects, before eventually deciding that I wanted to make a simple game engine.

I never did finish this project, but I did get a lot of the core functionality done, like the “level-editor” which is shown above. Here’s how the engine works in term of C++ objects and their relationships:

Untitled Diagram (1)
Block diagram of the C++ objects and their relationships with each other. Blocks are defined which contain a texture, their reference to a coordinate system, and vectors that hold block states, such as their “health”, status, and any methods that the user can use to interact with them. All of the blocks are rendered using the SDL library onto a window. Levels of blocks can be loaded upon command.

Here is a list of functions that my level-editor/game engine can currently do. Almost all of the functionality is done through the manipulation of C++ objects and the SDL library.

  • Supports loading and saving XML files with texture, level layout, and character data
  • Multiple texture files can be used, including sprite animations
  • Camera object allows panning
  • Allows the used to draw a map using textures by generating blocks inside a vector array
  • Blocks have parameters including: light levels, health, object properties, and more…
  • Proper garbage collection of objects, textures, and XML data
  • Blocks can interact with each other (collision detection)

Even though I never made a game using this code, I did manage to teach myself a lot of the C++ programming language. My favorite resources to use were the C++ reference, the Lazyfoo SDL tutorials, and this YouTube video series about how to make a RPG (although I’m not a big fan of the RPG genre).

You can download the source code as part of a Visual Studio 2015 Project here.