130 Video Game Design Foundations
IF
the dart object collides with a small balloon object
OR
IF
the dart object collides with a defl ating balloon animation,
THEN
destroy the small balloon object
AND
destroy the defl ating 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.
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,
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.
Deflating balloon Score is increased
A B
Figure 5-7. 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.
Previous Page Next Page