C++ Game Engine

The game Q*bert made in a custom made engine

The Engine

The engine is made in C++ using a variety of design patterns.

The main game loop of the engine consists out of: processing the input, updating the application, Updating the scene components and rendering the scene to the window. Delta time is used for frame independant code.

bool doContinue = true;
		
auto lastTime = std::chrono::high_resolution_clock::now();
while(doContinue)
{
	auto currentTime = std::chrono::high_resolution_clock::now();
	float deltaTime = std::chrono::duration<float>(currentTime - lastTime).count();
										
	doContinue = input.ProcessInput() && m_Running;
	GameUpdate(deltaTime);
	sceneManager.Update(deltaTime);
	renderer.Render();
										
	lastTime = currentTime;
}

Design Patterns:

  • Component System
  • Like unity and unreal the engine uses a component based system. You have a basic, empty object called a Gameobject, you add components to this object to add extra functionality. The gameobject has a list of all it's components and will update them when the gameobject is being updated.

  • Command Pattern
  • The command pattern is used when handling the input. You bind a command, which can take any parameters you want, to a button. Whenever that button is pressed, released or held the command bound to that button will execute. This avoids hard-wiring input to game actions. It also allows to more easily configure how buttons are mapped to certain actions.

  • Observer Pattern
  • The observer pattern has an object called the subject, which maintains a list of observers. Whenever the subject does something that other things should know of, it will notify all the observer it has in it's list. It helps with not having tightly coupled objects.

  • Service Locator
  • The service locator is a system that allows you to call a certain service from anywhere in your code without the code having knowledge of it's implementation. The service is an abstract class inside the locator. The user can implement this interface and register the service to the locator. If no service is registered, the service will default to a null service and will not execute any code when called. This will prevent any NULL references or calls. In the engine it's used for registering and getting a sound system. The sound system in the engine uses SLDMixer.

  • Event Queue
  • The event queue decouples an event when it's sent from when it's processed. In the engine it's used for the sound system. When a sound needs to be played, it is added to an event queue and is handled on another thread. With this system the main thread doesn't have to wait until it's done handling the sounds and can just continue, while the sound is handled elsewhere.

Libraries:

  • glm: mathematics library.
  • ImGui: graphical user interface library.
  • RapidJSON: fast JSON parser/generator.
  • SDL2: cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.
  • SDL2 Image: image file loading library.
  • SDL2 Mixer: sample multi-channel audio mixer library.
  • SDL2 TTF: sample library which allows you to use TrueType fonts in your SDL applications.

The Game

The game is a recreation of the original 1982 game Q*Bert. The goal of the game, as shown in the gif above, is to turn all the top face colors of the cubes to the same color across the pyramid. The player has 3 lives and gets points by killing enemies and changing the color of the cubes. The game has a single-player, coop & versus mode. In coop mode you will both be playing as Q*Bert, while in versus mode one of the players will be playing as Coily. You can play the game with both a controller and keyboard.

  • The enemies:
    • Coily: Starts at the top of the level and falls down, after which he will start stalking the player and try to kill him.
    • Ugg & Wrongway: They start at the right and left of the level. The are standing on a different face of the cube and traverse the pyramid sideways. They will hurt the player on contact
    • Slick & Sam: They both start at the top of the level and will decent until they jump off. While descending, they will undo some of the progress the player has made. The player can get rid of them by making contact with them

Source Control

All the source code is available on my GitHub