Copyright
by
The
Goodheart-Willcox
Co.,
Inc.
160 Introduction to Video Game Design
Next, you need to program the detonator so when the player pushes down the handle, the
dynamite sticks explode. The logic statement for this is:
IF the avatar collides with the OBJ_Detonator_Up object, THEN change the
OBJ_Detonator_Up object to the OBJ_Detonator_Down object AND create an
explosion AND destroy the dynamite stick.
25. Open the Object Properties dialog box for the OBJ_Detonator_Up object.
26. Add an event for a collision with the avatar. Even though the detonator is not the object
that will be moving, the collision is still between the detonator and the avatar.
27. There are many actions that need to happen all at once, so begin a block of code by
dragging the Start Block button from the Control tab and drop it into the Actions:
column.
28. Add an action that creates an instance of the OBJ_Detonator_Down object at (0,0)
relative to the OBJ_Detonator_Up object.
29. Add an action that destroys the OBJ_Detonator_Up object.
30. Add an action that creates an instance of the OBJ_Explosion object at (0,0) relative to
the OBJ_Dynamite_Stick object.
31. Add an action that destroys the OBJ_Dynamite_Stick object.
32. Close the block of code by dragging the End Block button from the Control tab and
dropping it at the bottom of the Actions: column. See Figure 10-4.
33. Test play the game. See if you can walk up to the doors and press the space bar to place
a stick of dynamite. After placing a stick of dynamite, run into the detonator to see if the
dynamite stick blows up and the detonator plunger is depressed. Note: the doors will not
be destroyed; this will be programmed in the next section.
34. Debug the game if the stick of dynamite is not placed or does not explode or if the
detonator does not change to the down position. Note: the explosion will be fi xed in the
next section.
35. Save your work.
Select the
object to create
Apply the instance
to the avatar
Enter the
location
Make the location
relative to the avatar
Figure 10-3
Start
Block
End
Block
Run the
Game