Building Behaviors
With our game properties defined, we now need to add behaviors to our actors. Behaviors are the "brain" of an actor, controlling what the actor can and cannot do, such as move, run, and jump. Behaviors can also be event-based, such as adding points to a score when a monster is killed.
Let's examine the types of behaviors you can add to an actor, as shown in Figure 2-24.
Figure 2-24. The behavior designer for an actor
Shortcuts: Shortcuts are like macros that add multiple behaviors for common tasks. For example, rather than defining individual motion behaviors for moving left, right, and jumping, you can add the run and jump behaviors by pressing the "run and jump by pressing keys" shortcut.
Behavior List: When you add a behavior, it is added to the behavior list.
Motion: This enables you to specify an actor's motion. We will use this extensively for our actors.
Shoot: As the name implies, this behavior enables you to shoot a projectile—for example, a bullet—from an actor. We will use this for gun-wielding actors.
State: This behavior enables you to switch the states for an actor. This is useful for actors that have two states, a left-facing and right-facing state, that you could switch depending on whether a user presses the left or right arrow key.
Sound: This behavior enables you to play a sound based on a particular event.
Disappear: This behavior controls the visibility ...
Get Coding4Fun now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.