SFML

After my first year of uni I wanted to keep my self busy and continue to develop my C++ skills and practice design patterns. This is where I came across the SFML library. This library reminded me a lot of the XNA library used with C# except compatible with C++. SFML also uses OpenGL instead of direct X, and as I was going to be studying OpenGL in my following year I figured it would be worth studying.

I structured my project around the use of scenes, similar to how the Unity game engines does this. So I can have a scene for my splash screen, and then transition into the main menu scene, and then the game scene. Though in order for me to make these changes I needed to be able to communicate to the game engine class to change the current scene. I could have done this through a singleton, but decided to create a broadcasting system that can allow objects to subscribe to certain broadcasters in order to receive messages. This approach is more stable and makes systems more independent by not having them directly reference other game objects or singletons in order to communicate. This makes code maintenance far easier though does add some overhead.

What this means is that the game engine object that manages the game loop and the active scene subscribes to a broadcaster called ‘ENGINE’. Then the splash screen scene object can broadcast a message through this broadcaster to all of its listeners with a game event to change the current scene.

When the main menu scene is active I will need buttons that can communicate with the current active state to load in the correct menu. This is where the broadcaster called ‘STATE’ is used, as all active states will end up subscribing to it. The way these buttons work is through inheritance of a standard button that manages the drawing, interaction, and base functionality of the button. While another button type called event button inherits from this and extends it with the ability to store an event with polymorphism as well as broadcasters to cast the stored event through when clicked.

Once I am in the game state I can create a world map using sprite tiles; the sprite I use are from the Legend of Zelda. These sprites maintain a reference to a texture and UV coordinates in a rectangle to represent which part of the texture the sprite inhabits. I can then manage sprite animation by storing multiple rectangles and changing them out in time to set key frames. I can also manage the creation of these tiles through a factory class, that can also set up any animated tiles.

I stored maps as texture files where specific colours represented specific tiles. This was a temporary system to test out maps. Below is an example of a texture and the map it created.

This project was very interesting from an academic point of view as it gave insight into method of communication in a system and the use of design patterns to maintain structure.

Code for this project can be found here in the code listings under SFML Project