Procedurally generated level goals
The final system that we're going to build in this chapter is one that will generate randomized level goals. In each level, we have to find the key, find the exit, and kill all enemies that get in our way. Let's add more gameplay and challenge by adding random goals that the player can also complete. Every time a level is entered, we'll potentially give the player an optional task that, if completed, will yield a random reward.
The variable and function declarations
The first step in creating this system is to declare the variables and functions that we're going to need. We'll encapsulate the behavior to generate a goal in its own function. For starters, we need to declare the following private
function in Game.h
:
private: /** * Generates a level goal. */ void GenerateLevelGoal();
Given the type of goals that we want to generate (killing enemies, collecting gold, and collecting gems), we need variables to hold these values. Let's also declare the following...