Selecting a random main track
Currently, the game has no sounds or music. We have been running the game frequently throughout the course of the book, and hearing the same track over and over can get very tedious. So, we've waited until now to put it in. It's a very simple process to add sounds. So, we'll cover this process in its entirety.
To start, we'll add a main music track that will underpin the game. However, instead of having a fixed track, we will add multiple possibilities and randomly choose one during startup.
Let's start by defining all the possibilities in an enumerator in the usual way. Add the following code to Util.h
:
// Music tracks. enum class MUSIC_TRACK { ALT_1, ALT_2, ALT_3, ALT_4, COUNT };
As the enum
shows, we're going to have four possible tracks. These are already included in the /resources/music/
folder. So, all that we have to do is select one track at random and load it at the start of the game. Since we want this music to start straightaway, we...