
Procedural Content Generation for C++ Game Development
By :

Currently, when we load our game, set items are spawned. We need to add an element of randomness to do this, and something as simple as a switch
statement is all that's needed. Where we can, we always want to add options to create random and procedurally generated content.
To randomly spawn our items, we need to generate a random number between 0
and the number of items we have, and then use that in a switch
statement. As stated previously, there isn't one approach to procedural generation, so there will be other methods to doing this.
Let's add in the number generation and switch
statements to choose which item to spawn. The updated Game::PopulateLevel
function should look as follows:
// Populate the level with items. void Game::PopulateLevel() { // A Boolean variable used to determine if an object should be spawned. bool canSpawn; // Spawn an item. canSpawn = std::rand() % 2; if (canSpawn) { int itemIndex = std::rand() % 2; ...
Change the font size
Change margin width
Change background colour