175
Chapter 5 Collision Theory and Logic
Just as with the
AND
operator, the
OR
operator works as a conjunction in
programming logic. The
OR
operator allows multiple results to take place under
a given condition or event. In the balloon pop game, a random balloon begins
to deflate during gameplay. When it does, the existing balloon object is replaced
with an animation of the deflating balloon and a small balloon underneath
the animation. The small balloon is only visible when the deflating animation
has finished. In this example, the deflating animation and the small balloon
should be treated as if they were only one object. The
OR
operator is perfect for
making this happen.
If the dart collides with either the deflating animation or the small balloon,
the game should display the same events. The events need to “pop” both
the animation and the small balloon underneath. This operation would look
something like the example below. Refer to Figure 5-7.
IF
the dart object collides with a small balloon object
OR
IF
the dart object collides with a deflating balloon animation,
THEN
destroy the small balloon object
AND
destroy the deflating balloon animation
AND
create explosion animation
AND
add 500 points to the player’s score.
The last of the basic programming operators is the
ELSE
operator. This
operator may also be called the
OTHERWISE
operator. The
ELSE
operator
describes what will happen if a certain action or reaction does not take
place. You have likely seen this many times when trying to beat a level in a
video game.
Figure 5-7.
Goodheart-Willcox Publisher
A—The dart is about to hit the small balloon. B—When the dart hits the small balloon, the
balloon pops and the player scores 500 points.