Chocolate Game Engine

A Beginner's First Game Engine

    I don't like to play by the rules. When people online point out that it's useless to create your own game engine, They're just ruining the fun. Well, it's fun when it works and isn't giving you constant segmentation faults when debugging, but that could just be a component of how I set up the project.

    Anyways, during April of this year, I sat down and decided to teach myself how to program with Vulkan, a modern graphics API that I find to be the best among OpenGl and DirectX. The graciously provided Vulkan Tutorial written by Alexander Overvoorde helped me set this up with no prior graphics programming knowledge beforehand. I didn't really know what I was copying down as I wrote it, but I eventually had a colorful triangle on my screen, which was pretty exciting.

    So, what gave me the inspiration to make a game engine?

    Well, I actually attempted to make a game engine back in July of 2020, when I was bored, sitting around doing nothing in my bed in Maine. The inspiration then, was because I liked to draw fictional characters and give them interesting backstories, and once I composed some random melodies at the same time, I thought it would be really cool to try to put these together into a video game from scratch. The video game series Epic Battle Fantasy also gave me a lot of motivation to make such a game because that game was my entire childhood. The characters were lovable, the jokes were as funny as 2012 jokes got, and more importantly, it was made by an indie developer.

    However, I was still very new to programming, having only gotten comfortable with C++ syntax about 2 months prior. I had no idea how to structure a program like this, so the end result was sure to be entertaining.Looking back on it, I'm pretty impressed with how I got some of the things working. I "borrowed" a sprite sheet from google images, and managed to get it walking around based on user input.

Old Engine Demo:


    Yeah, probably the only cool code in this engine was the sprite animation, which looked atrocious:

The Sprite Animation Logic:

for (int i = 0; i < MAX_ANIMATIONS; ++i)
    {
        if (sprites[i].isMoving)
        {
            sprites[i].cropDest = {((sprite % sprites[i].animations[sprites[i].currentAnimIndex].vec.frameCount) * 32) +        //  First parameter, gets the sprite clock and gets the remainder of the clock and the frame count
                                    (32 * sprites[i].animations[sprites[i].currentAnimIndex].vec.spriteOfsX),                   //  then adds the sprite X offset to get animation, and the right position

                                     32 * sprites[i].animations[sprites[i].currentAnimIndex].vec.spriteOfsY,                    //  Second parameter just gets the Y offset, vertical animation not supported ATM.
                                     32,                                                                                        //  32 pixel crop, this should be modular soon.
                                     32};
        }
        else
        {
            sprites[i].cropDest = { (32 * sprites[i].animations[sprites[i].currentAnimIndex].vec.idleFrame) +               //  First parameter, gets the sprite clock and gets the remainder of the clock and the frame count
                                    (32 * sprites[i].animations[sprites[i].currentAnimIndex].vec.spriteOfsX),               //  then adds the sprite X offset to get animation, and the right position

                                     32 * sprites[i].animations[sprites[i].currentAnimIndex].vec.spriteOfsY,                //  Second parameter just gets the Y offset, vertical animation not supported ATM.
                                     32,                                                                                    //  32 pixel crop, this should be modular soon.
                                     32};
        }
    }

    Now, in 2021, I have a lot more programming experience, and a stronger urge to make my own indie game, so I set out to try to create something much easier to use in the long run. I researched some strategies for tidying up the code, and I set out to make something. I did not expect to keep working on the project time and time again, but I just kept adding features and it seemed that the project certainly had some life.

    I improved the triangle rendering to allow for models to be rendered, and then went beyond the tutorial and got 2D sprites drawing to the screen. I then added some better systems for tidy code, and soon enough, the engine's systems could communicate with eachother easily, and I had a developer console using ImGui.

    Fast forward a couple of months into the project, and one of my friends wants to help make a game in it, so I showed him how it works, and we made massive progress together. He added a view projection and a mouse input system, so you can actually move and look around. I improved the systems even more, and added some more renderer tweaks, such as having multiple textures on a loaded model, mipmaps, and MSAA. After my friend added a ConVar system similar to that of the Source Engine, The vulkan learning experience I started in April evolved to be much more than that.

New Engine Demo:


    Recently, my friend and I made a material system that has been documented in much more detail in the material system article if you are curious.

    Now, all that is left for me to do are a few more renderer tweaks, such as lighting and mesh building.

Last updated: Sun 26 September 2021