Procedural items

Now that the player and enemies have been taken care of, let's turn our attention to items. We have a number of classes that can have their member variables assigned randomly. We'll set up the potion class the way we set up the humanoid class, where we created a number of distinct objects from a single class.

Random Gem and Heart classes

We'll start with the smallest classes, namely Heart and Gem. These are very simple classes that have a single variable that is currently hard-coded. Let's update this so that their values are randomly generated every time they are created. Since we want this to happen each time an object is created, we'll place it in the items' constructors.

In Gem::Gem, we'll make the following change:

// Set the ...

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.