O'Reilly logo

Procedural Content Generation for C++ Game Development by Dale Green

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The random potion class

For the biggest class update, we'll turn our attention to the potion class. This class currently has a fixed sprite and doesn't give the player anything. With the humanoid class, we can generate a random type and essentially create two different enemies from a single class. We're going to use this same approach for the potions.

Creating a random potion

To start, let's define an enumerator in Util.h that denotes all potion types. We'll create one for each stat, as follows:

// Potions.
enum class POTION {
  ATTACK,
  DEFENSE,
  STRENGTH,
  DEXTERITY,
  STAMINA,
  COUNT
};

To save a lot of typing, the potion class already has the member variables and the getter functions for each possible stat, we just need to use them. One thing that we ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required