Video Game Design and Programming Concepts 130 Copyright Goodheart-Willcox Co., Inc. May not be reproduced or posted to a publicly accessible website. 81. In the Create Object dialog box, select the Platform 1 object, as shown in Figure 10-13. Then, click the OK button. The frame editor is displayed for you to select where the object is to be created. 82. Applying what you have learned, set the absolute position at (0, 480). 83. Test the frame to see if the platforms spawn and move up. Note: the Platform 2 object will move off the screen, but it will not spawn. The only platform that needs to spawn is the Platform 1 object. Close the game window when done testing. Setting a Random Platform The Counter_Random object has been set to generate a random number. This number will be used in a formula to select the animation direction for the Platform 1 object. In effect, this randomizes where the hole will be in each platform. 84. On the event line for every 1.70 seconds, right-click in the cell below the icon for the Platform 1 object, and click Animation Change Direction of animation… in the shortcut menu. 85. In the Direction of Animation dialog box, click the Calculate Direction button (1+1) to display the expression editor. 86. Right-click on the icon for the Counter_Random object at the bottom of the expression editor, and click Current value in the shortcut menu. The code value (“Counter_Random”) is added to the expression. This code means use the value method, which tells the computer to start looking for a value. The item inside the parentheses is the value. If this is a number, the computer will simply use that number, but by adding “Counter_Random” instead, the computer will get the value the Counter_Random object is currently holding. 87. Click after the closing parenthesis, and enter *8 to complete the expression, as shown in Figure 10-14. The asterisk (*) is a multiplication symbol (×) in computer applications. The complete expression will take the value of the Counter_Random object and multiply it by 8. Remember, the counter will randomly select either 0, 1, 2, or 3. Examine the following table. Notice that multiplying the random number by 8 produces a number corresponding to one of the four animation direction nodes specified for the Platform 1 object. Counter_Random Value Multiplier Resulting Value Animation Direction 0 8 0 Right 1 8 8 Up 2 8 16 Left 3 8 24 Down 88. Click the OK button to add the expression. Run Frame Select object to create Goodheart-Willcox Publisher Figure 10-13. When programming spawning, select which object will be created (spawned).
Previous Page Next Page