Game Development Reference
In-Depth Information
Implementing the npcScript class
The npcScript class will encode the base state machine for NPCs. To develop
a robust non-player character system requires a model of the behavior we want to
present to the player. Once we have a model, we can build an FSM that meets our
functional needs. We shall list these requirements in the following part.
In our e-learning game, the non-player characters will need to do the following:
• Travel about the world in a smooth, realistic way
• When approached by the player, the NPC should stop and face the player to
interact
• When the player leaves the NPC or finishes the interaction, it should continue
moving about the world
Based on these requirements, it is clear that we will need a number of states that we
can encode in a public enumeration. To prove that the NPC framework works and
meets our design needs, we will implement the patrol and turnToPlayer states
as a minimum viable product for the NPC system. Once these are working, it will
be clear that the system works and that the reader can then extend the system with
more behaviors:
public enum npcState
{
invalid = -1, //enum to encode error npc state
none = 0,// enum to encode npc having no state
idle = 1,// enum encoding npc waiting idly
patrol = 2,// enum for npc patrolling about
turnToPlayer = 3,// enum for npc to face
player
InteractWithPlayer = 4,// enum for npc
interacting with player
Celebrate = 5,// enum for npc celebrating
Disappointed = 6 //enum for npc acting
disappointed
};
Search WWH ::




Custom Search