Copyright
by
The
Goodheart-Willcox
Co.,
Inc.
162 Introduction to Video Game Design
Resetting the Detonator
Did you notice as you test played the game that you only get one chance to activate the
detonator? After you activate it, it is stuck down. If you put the dynamite in the wrong place, you
can place more dynamite, but you have no way to set it off. There needs to be a way for the
player to reset the detonator. You will program the game so that when the player presses the
[Enter] key, the detonator will be reset to the up position.
42. Open the Object Properties dialog box for the OBJ_Detonator_Down object.
43. Program this logic statement: IF the player presses the [Enter] key, THEN destroy the
OBJ_Detonator_Down object AND create an instance of the OBJ_Detonator_Up object
at (0,0) relative to the OBJ_Detonator_Down object. Program this as a block of code. See
Figure 10-6.
44. Test play the game. Check to see that you can destroy the dynamite sticks, place a new
dynamite stick, reset the detonator, and destroy the new dynamite stick.
45. Debug the game if needed.
46. Save your work.
Programming with Variables
The game is much more fun…destroying things always seems to help! But, the dynamite is
automatically available to the player. This is too easy. To increase the challenge, you will program
the game so the player can only carry one stick of dynamite at a time. Variables will be used to
achieve this new challenge. A variable is a programming item holding a temporary value (number
or text) that can vary or change. Remember that pack of dynamite you placed earlier? The player
will pick up a single stick of dynamite each time the avatar touches the dynamite pack.
47. Open the Object Properties dialog box for the OBJ_Dynamite_Pack object.
48. Add a create event.
49. Drag the Set Variable button from the Control tab and drop it into the Actions:
column. The Set Variable dialog box is displayed, Figure 10-7.
Block of code for
resetting the detonator
Figure 10-6
Set
Variable