Exercise 5-5: Playing the Game Again
Now that the game works, you’ll make the game playable multiple times.
- Make sure you are working in the same file from the last exercise.
- Select the first keyframe of the actions layer and open the Actions panel.
- At the bottom of the DEFINE VARIABLES AND CREATE OBJECTS section of your code, create a new variable called nailOut, with a data type of Number and a value of the nail’s current Y position.
var bashAmt:Number = 15;
var rotateAmt:Number = -15;
var nailIn:Number = 470;
var nailOut:Number = nail_mc._y;
- At the bottom of the DEFINE EVENT HANDLERS section of your code, create the skeleton of an onPress event handler for the top_btn button.
top_btn.onPress = function():Void
{
}
- Inside the event handler you just created, reset the value of the rotateAmt variable to be –15.
top_btn.onPress = function():Void
{
rotateAmt = -15;
}
- On the next line, re-enable the bottom_btn button using its enabled property.
top_btn.onPress = function():Void
{
rotateAmt = -15;
bottom_btn.enabled = true;
}
- On the next line, reset the nail’s Y position to the value held inside the nailOut variable.
top_btn.onPress = function():Void
{
rotateAmt = -15;
bottom_btn.enabled = true;
nail_mc._y = nailOut;
}
- Test the movie, and pound! Once the game is finished, click the top of the screen to start the game over again. Nice!
Another Game Complete!
Congratulations, you just finished another game! Though the gamewas fairly simple to create, it takes much more advantage of the Wii remote than the other games you’ve created. Once you upload this game to a web server and play it on your Wii, the Wii remote will act as a hammer as you play the game. In other words, swinging the hammer in the game will actually be pretty close to swinging a hammer in real life.
Now that you’re familiar with using the Wii remote in a similar way to how it is used in commercial Wii games, we’ll start building games with more complex interactivity.
For more on this book and to purchase from Amazon, visit its book page in our Library
|
|