Book Image

JMonkeyEngine 3.0 Cookbook

By : Rickard Eden
Book Image

JMonkeyEngine 3.0 Cookbook

By: Rickard Eden

Overview of this book

Table of Contents (17 chapters)
jMonkeyEngine 3.0 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a trigger system


Almost all story-driven games require some kind of system to trigger some sort of event for example, dialogs, enemies, or doors opening. Unless the game is very small, you generally don't want to hardcode these. The following recipe will describe a trigger system, which can be used for almost any type of game from FPSs to RTSs and RPGs.

We'll start out by laying the ground work with an AppState controlling all the script objects and the basic functionality of a Trigger class. Then, we'll look into how to actually activate the trigger and use it for something.

Getting ready

Before we start with the actual implementation, we create a small interface that we will use for various scripting scenarios. We call it ScriptObject and it should have the following three methods:

void update(float tpf);
void trigger();
voidonTrigger();

How to do it...

Now, we can implement the ScriptObject in a class called Trigger. This will have six steps:

  1. Add the following fields to the Trigger...