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 ...

Get Procedural Content Generation for C++ Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.