128 Video Game Design Foundations
Advanced Logic Statements
The next step in basic programming is to add multiple actions or multiple
reactions to logic statements. This is done using the
AND
and
OR
operators.
These operators work just as they would as conjunctions in any sentence.
The
AND
operator will join two or more
outcomes for a given condition or action. Refer
to Figure 5-5:
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 pressed, THEN the character moves up.
IF pressed, THEN the character moves down.
IF pressed, THEN the character moves left.
IF pressed, THEN the character moves right.
Figure 5-4. This illustration shows logical statements for a player using the arrow keys to move a character.
Figure 5-5. The action of the dart hitting the balloon
creates the reaction of the balloon disappearing, an
explosion appearing, and the score changing by 100 points.
The balloon does not actually “pop.” To create the illusion of
popping, the balloon object is destroyed and replaced by a
popping animation.
Previous Page Next Page