176
Video Game Design Foundations
Think about a game that requires you to collect gold coins and a key. You
cannot open the door to the next level without meeting both objectives. The
doorway will usually display a message telling you what you are missing, as
illustrated in Figure 5-8. In the example below, the condition tests if the player
has at least 100 gold and one key.
IF
gold = 100
AND
IF
key = 1,
THEN
display the message “Well done. You may pass to level 2,”
ELSE
display the message “You need 100 gold and the key to pass.”
The
ELSE
operator works like a true/false test. If the condition is true, the
THEN
events are initiated. If the condition is false, the
ELSE
events are initiated.
In the balloon pop example, the
ELSE
operator helps end the game when
the player runs out of darts. Every time a dart is launched, a test needs to be
performed to see if there are any more darts. In other words, the question is
asked, “is number of darts more than zero?” If the condition is true, then a dart
needs to be loaded into the hand (avatar). If the condition is false, the game
ends.
The following logic statement can be used to program the end of the
balloon pop game.
IF
number of darts 0,
THEN
load one dart in the hand,
ELSE
display the message “Game Over.”
This statement describes what happens each time the player throws a dart.
If there is still a dart available, then the player gets to throw another dart.
Otherwise, the game is over, as shown in Figure 5-9.
Figure 5-8.
A game should
tell you what is
missing when trying
to complete an
objective. Here, the
game is telling the
user the key must be
located to open the
door and enter the
next level.
Goodheart-Willcox Publisher
www.g-wlearning.com
your know-how
with Animated
Review 5-1.
k h
Level L L L L L L L L L L L L L L l l L L L L L L L L L L L L L L L L L L L L L L L L L L L e e e e e e e e e e e e e e e e e e e e e e e e v v v v v v v v v v v v v v v v v v v v v v v v e e e e e e e e e e e e e e e e e e e e e e e e l l l l l l l l l l l l l l l l l l l l l l l up u u u u u u u u u u u u u u u u u u u u u u u u p p p p p p p p p p p p p p p p p p p p p p p p p L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l u u u u u u u u u u u u u u u u u u u u u u u u u u u u u u u u u u u u p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p