Game Base

This is what I tend to use as the base for all of my games. It uses C++11, so older compilers probably can't use it without adjustments. It also uses SFML 2, so make sure you have that.


It works on a 'scene'-based system. It comes with four premade ones: Main Menu, Options, Controls, and Game.

The main menu scene simply links to the game and options scenes, and has a quit button as well.

The options scene has a volume slider, a link to the controls scene, and a button to reset everything back to their default values (as defined in the Options constructor, not the scene).

The controls scene manages re-assigning input bindings. There are none by default, so make sure you define them in the Options constructor (or remove the link to the controls scene).

The game scene is empty, but obviously that is where you are intended to put the actual game code. :P

To change scenes, you call something like game.changeScenes< GameScene >();. You can (optionally) pass a SceneChangeEvent as the first parameter to specify why (quit, victory, failure, ...) and some details (like the final score). You can also pass more parameters, which go to the scene's constructor, which can be useful if you want to reuse a single class for multiple things (such as multiple difficulties?).


To add a new control, you would put something like this in the constructor of the Options class: controls.insert( std::make_pair( "Up", InputBinding( sf::Keyboard::W ) ) );To use an InputBinding , just store a ( const ) reference to it and call if ( binding.check() ) { /* stuff */ }.

To add more non-control options, just add more fields to Options and set them in the constructor. To make them properly persistent you will have to manually edit save and load functions (I blame C++ not having reflection :P).


For resources, you can just call the ResourceManager functions on Game , such as game.getTexture( "res/player/idle.png" );. ResourceManager currently isn't designed well though, but I don't know precisely how I want to do it.

Anyways, that should be enough to start using it. I haven't actually released a game that uses the new options/controls yet, but hopefully it will be fairly easy to use.

It can be found here.