Constructing dialogue
Whether divulging small nuggets of information, engaging in trade, or just adding that little bit of texture, for gaming genres such as the role-playing game, the ability to converse with characters in the surrounding world is often at the heart of the storytelling process.
In this recipe, we're going to examine a technique for constructing dialogue trees loosely based on the Gang of Four command pattern.
Getting ready
An XNA-compatible font of your choice is all that's required for this recipe.
How to do it...
To create a dialogue engine:
1. Add a new
SpriteFont
to the solution namedDialogue
.2. Create an interface to define how to interact with an NPC during conversation:
interface ChatSupplier { IEnumerable<ChatOptionDisplayable> ChatOptions { get; } void Select(ChatOptionDisplayable chatOption); }
3. Define the options that can be presented by an NPC in a conversation:
interface ChatOptionDisplayable { float DisplayHeight { get; set; } string Text { get; ...