Guts & Glory - Scaffolds are in place

Written by Ithai Levi

Guts & Glory is going to be an arcade game, hopefully a great arcade game. However, it must begin its way as a well-designed software project, more specifically, a well-designed C++ project.

The last week was all about establishing the Guts & Glory software scaffolds, so it can grow into a beautiful game.

The first challenge I faced was leaving the prototype as it was. It’s difficult not to spiral into adding more and more cool features and ideas, directly into the already running prototype. However, having a messy code base together with a tight schedule is no fun.

“The plan is useless, planning is Essential”

I needed a blueprint for a clean shiny new game that will be well-designed and can withstand the rapid pace of development I plan for. Working on Guts & Glory in my spare time means every hour counts, so I need to be calculated and organized.

Guts & Glory blueprint

Once I had the blueprint ready I began coding the skeleton of the game.

The most central element in my design is the GameState class. The GameState interface allows the main game class to delegate its callbacks based on the alternating game states.

Concrete GameStates are used to implement the game menu, levels and other displays. Each GameState is responsible to dynamically allocate and release its resources. Nothing too fancy. Just the plain old state pattern working as it should.

Here’s how my main game source looks like now:

#include "GutsAndGlory.h"
#include "MainMenu.h"

GutsAndGlory game;

GutsAndGlory::GutsAndGlory()
{
}

void GutsAndGlory::initialize()
{
    GameState::current = new MainMenu();
    GameState::current->initialize( this );
}

void GutsAndGlory::finalize()
{
    GameState::current->finalize();
    delete GameState::current;
}

void GutsAndGlory::update( float elapsedTime )
{
    GameState::current->update(this,elapsedTime);
}

void GutsAndGlory::render( float elapsedTime )
{
    GameState::current->render( this, elapsedTime );
}

void GutsAndGlory::gamepadEvent( Gamepad::GamepadEvent evt,
                                 Gamepad * gamepad )
{
    if (GameState::current) {
        GameState::current->gamepadEvent( this, evt, gamepad );
    }
}

void GutsAndGlory::keyEvent( Keyboard::KeyEvent evt, int key )
{
    if (GameState::current) {
        GameState::current->keyEvent( this, evt, key );
    }
}

void GutsAndGlory::touchEvent( Touch::TouchEvent evt, 
                               int x, int y, 
                               unsigned int contactIndex )
{
    if (GameState::current) {
        GameState::current->touchEvent( this, evt, x, y, contactIndex );
    }
}

Nothing’s in there. Everything has its place now.

Aircraft Salvage

The next step was to extract the reusable pieces of code from the prototype, embedding the code in the right places, based on the blueprint.

My C++ coding style is somewhat strange if you are used to the classical OOP and OOD concepts. I don’t use private or protected members at all. If it’s in the header, then it’s public. These days, I tend to use C++ as a convenience layer on top of C.

Engines Started

The outcome: the Guts & Glory game fully scaffolded. This means I have all major classes interacting properly, game states alternating and the basic flow working.

You can see me assigning my gamepads, going through a preliminary level menu, playing and then going through the level stats placeholder and back to the menu.

It’s now just a matter of filling in the blanks :)

Next Waypoint

Now that I have the skeleton for the game, I want to focus on having a playable pre-alpha. A build that I can potentially start giving away to the few and the brave, containing the first few levels and the core of the PvP mode. Back to work.