Character state machines
Defining a character's temperament and possible actions in the form of a finite state machine is a simple but effective way to simulate emotion, personality, and those subtle quirks that hint at humanity.
In this recipe, we're going to create a pretty simple example in the form of a security guard who gets progressively more or less excitable depending on whether he can hear or see the hero of the game.
Just like a real person might react, the guard doesn't instantly jump into full-blown anger upon the smallest noise, nor does he instantly calm down upon losing sight of the hero.
Getting ready
This recipe requires only an XNA-compatible font of your choosing.
How to do it...
To create your own character state machine:
1. Add a new
SpriteFont
to your solution, namedText
.2. Create a class to represent the emotional state of a character:
class StateNode { public string Id;
3. Complete the class by including a list of possible nodes to transit to, along with a method to...