Getting Started

First, please ensure that one of the following is set up for your corresponding system:


Get cerlib

Download cerlib and extract it.

That’s all!

Some knowledge of (modern) C++ is recommended. CMake knowledge is not required.


The Game

cerlib provides a Python script that generates a game template for you. After extracting cerlib, simply execute and follow the instructions:

python3 cerlib/CreateGame.py

The game template consists of:

  • src: Contains the game’s source code
    • Main.cpp: Implements the game
  • assets: Contains the game’s asset files, such as images and sounds
  • CMakeLists.txt: Sets up the game project

Let’s have a look at Main.cpp:

Main.cpp
#include <cerlib.hpp>
#include <cerlib/Main.hpp>

using namespace cer;

int main(int /*argc*/, char* /*argv*/[]) {
    auto game   = Game("MyGame");
    auto window = game.window();
    auto img    = Image("logo.png");

    while (game.tick()) {
        auto time = game.time();

        auto imgPos = (window.sizePx() - img.size()) / 2;
        imgPos.x += sin(float(time.totalTime) * 2) * 100;

        drawSprite(img, imgPos, white);
    }

    return 0;
}

The Game class represents the central game instance and is responsible for the entire game’s lifecycle. As soon as a game instance is created, you’re able to create and load objects such as images and fonts.

The game’s tick method has to be called continuously, and as long as it returns true, the game counts as running. Within the loop, you’re able to using the game’s time property to perform game logic updates.

Finally, you can draw the game’s visuals.


Running the game


Note

You can always build the game however you please, since it’s a normal CMake project. You’re not tied to any editor or IDE. This introduction simply guides you through a path of least resistance.

You can now see the game running:

nice

Congratulations! You got your game running.