O'Reilly logo

Microsoft XNA 4.0 Game Development Cookbook by Luke Drumm

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

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 ...

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