174
Video Game Design Foundations
IF
the dart object collides with the balloon object,
THEN
destroy the balloon object
AND
create an explosion animation object
AND
add 100 points to the player’s score.
In this example, the
AND
operator allows three events to occur from a single
collision action. The balloon is destroyed (1), an explosion appears (2), and
the player scores 100 points (3). An
AND
operator can also be included in a
condition statement. Refer to Figure 5-6.
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.
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?
UP!
5.2
Figure 5-6.
Goodheart-Willcox Publisher
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.