Time for action – employing scripting for npc AI

Let's implement a script serving as artificial intelligence (AI) for a nonplayer character in a simple Dungeons & Dragons game. The engine will periodically execute the script, exposing two objects to it—the creature and the player. The script will be able to query the properties of the player and invoke functions on the creature.

Let's create a new project. We'll start by implementing the C++ class for creatures in our game world. Since both the NPC and player are living entities, we can have a common base class for them. In Chapter 4, Qt Core Essentials, we already had a data structure for players, so let's use that as a base by equipping our entities with similar attributes. Implement LivingEntity ...

Get Game Programming Using Qt 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.