Chapter 5 Collision Theory and Logic 127
When programming a video game, the formal term for an action is a
condition. The computer checks to see if a condition is met. When it fi nds
a condition has been met, it executes the programmed events. An event is
a change that occurs when a condition is met. In other words, it is a reaction
to the condition.
To program the go-cart example using condition-and-event relationships,
the logic statement is only slightly modifi ed to describe the exact action the
computer must take to carry out the command. That logic statement would read:
IF
the go-cart object collides with the banana peel object,
THEN
the go-cart object will change from a linear animation to a spinning
animation.
This is still the same idea, but more specifi c to help the computer identify
the object and how it changes when the collision occurs. The table in
Figure 5-3 shows the relationship between the common terms used in
constructing a logic statement.
To design a game, many events are required to get it to work properly.
When programming a game, logic is used to do more than just describe what
happens on screen. The same logic format is used to program the user inter-
face, increase score, change levels, and perform
every other interaction the player encounters. A
simple user interface to control a player moving
North, South, East, and West requires a logic
statement for each controlling motion. Refer to
Figure 5-4.
Operator Cause Operator Effect
IF you turn in homework, THEN you get a good grade.
IF you buy a ticket, THEN you watch the movie.
IF you miss the bus, THEN you are late to school.
Figure 5-2. This table shows the cause-and-effect relationship for some everyday occurrences.
THINK ABOUT IT
ACTIVITY 5.1
In the workbook activities for
Chapter 4, you created
simulations of a soccer game.
Think about these simulations.
How could you write a logic
statement to make the ball move on
its own when kicked? How could you
write a logic statement to describe
how a goal is scored for each team?
Operator Condition Operator Event
IF action THEN reaction
IF cause THEN effect
IF condition THEN event
Figure 5-3. This table shows the relationship between the common terms for constructing a logic statement.
Previous Page Next Page