Chapter 5 Collision Theory and Logic 135
Look at line 1 in the event frame. The
IF
side of the logic statement
is in the fi rst column. The
THEN
side of the logic statement is shown in
the remaining columns. The condition on line 1 states “collision between
dart object and balloon object.” When that condition is met, the computer
processes the events in the
THEN
statement.
Notice the four check marks in line 1 in the event frame. The fi rst check
mark is in the
Create New Objects
column. This event creates a new explo-
sion animation object at coordinates 0,0 relative
to the balloon object. The next check mark is
in the
Player 1
column. This event adds 100
points to Player 1 score. The next check mark
is in the
Balloon Object
column (the name
of this column matches the name assigned
to the object). This event is set to destroy the
balloon object. The last check mark is in the
Pops
column. This event increases by one the
counter keeping track of the number of pops. To
see this type of object-oriented programming as
a logic statement, add the word
IF
before the
condition and the word
THEN
before an event.
See Figure 5-13.
Remember, collision theory is more than
just setting collision events. To make objects
appear solid, the programmer needs to add
some realistic effects to the collision. Think
about what happens when someone walks
into a glass door. Do they just stop or do they
bounce with their head whipping back and
arms fl ailing? Adding a realistic animation after
the collision will help with the illusion that an
object is solid. An example of that programming
might look like this:
IF
the coyote collides with the brick wall,
THEN
the coyote will move backward
AND
the animation will change from
walking to falling down.
Collision theory controls almost every inter-
action in video game action. The computer
follows the programming of the collision state-
ments that keep objects moving, stopping,
exploding, or standing on a platform. Just
because it is blue and has waves, does not make
it water. The computer does not make these
types of visual assumptions; only programmers
IF
THEN
AND
AND
AND
Figure 5-13. Logical operators can be added to help
explain how a logic statement is constructed in The Games
Factory 2.
CHEAT CODE: RELATIVE
The term relative is used when placing or
moving an object in a game to describe
from where the position is determined.
When you place a duck three units to
the left of a frog, you are placing it
relative to the position of the
frog. If something is placed at
coordinates 0,0 relative to an original object, it is in the
exact same spot as the original.
THINK ABOUT IT
ACTIVITY 5.4
Think about creating logic statements
for the interactions programmed
in Figure 5-12. Examine the
conditions programmed on
lines 6 and 7. These lines have
AND/OR operators between the
two conditions on each line. Which
conjunction works best in each line?
Previous Page Next Page