Chapter 5 Collision Theory and Logic 129
IF
the dart object collides with a yellow balloon object
AND
IF
the yellow balloon object overlaps any other balloon object,
THEN
destroy yellow balloon object
AND
destroy all balloon objects it overlaps
AND
create an explosion animation
AND
add 500 points to the player’s score.
Just as with the
AND
operator, the
OR
operator works as a conjunction in program-
ming 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 defl ate during gameplay.
When it does, the existing balloon object is
replaced with an animation of the defl ating
balloon and a small balloon underneath the
animation. The small balloon is only visible
when the defl ating animation has fi nished. In
this example, the defl ating 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 defl ating 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.
A B
Figure 5-6. A—The dart is about to hit the yellow balloon. The yellow balloon is overlapped by a blue balloon, which is
overlapped by a pink balloon. B—The dart pops the yellow balloon and any overlapping balloons with a single explosion
animation; the player scores 500 points.
THINK ABOUT IT
ACTIVITY 5.2
Look at the dart in Figure 5-6B.
When the balloon pops, the
dart has not been programmed
to stop or be destroyed. How
do you think a logic statement
should be written to describe what
happens to the dart when it hits a
balloon?
Previous Page Next Page