Upcoming Events
Southwest Gaming Expo
11/20 - 11/22 @ Dallas, TX

Workshop on Network and Systems Support for Games (NetGames 2009)
11/23 - 11/25 @ Paris, France

ICIDS 2009 Interactive Storytelling
12/9 - 12/11 @ Guimarães, Portugal

Global Game Jam
1/29 - 1/31  

More events...


Quick Stats
6761 people currently visiting GDNet.
2341 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!



Link to us

Link to us

  Intel sponsors gamedev.net search:   

Nintendo Wii Flash Game Creator's Guide: Chapter 5
Utilizing the Wii Remote: A Hammer Game


Exercise 5-4: Winning the Game

In this exercise, you’ll stop the nail from going too far into the wood and disable the interactivity of the hammer once the game is over.

  1. Make sure you are working in the same file from the last exercise.
  2. Hide the buttons layer, and unlock the nail layer if it’s locked.
  3. On the nail layer, using the Selection tool, move the nail down until it looks as if it is all the way in the wood, as shown next. Then, note the Y position of the nail in the Property Inspector. You’ll use this value later.

  4. Select the first keyframe of the actions layer and open the Actions panel.
  5. In your code, at the bottom of the DECLARE VARIABLES AND CREATE OBJECTS section, create a new variable called nailIn, with a data type of Number and a value of 470. This value will represent the value of the nail when it is fully hammered in, and is the same value you got when you moved the nail earlier in this exercise.
    var bashAmt:Number = 15;
    var rotateAmt:Number = -15;
    var nailIn:Number = 470;
    
  6. At the bottom of the bottom_btn.onRollOver event handler, create the skeleton of a conditional statement that checks to see if the Y position of the nail is greater than or equal to the value of the nailIn variable.
    bottom_btn.onRollOver = function():Void
    {
      hammer_mc._rotation = rotateAmt;
      nail_mc._y += bashAmt;
      rotateAmt -= bashAmt / 7;
      if(nail_mc._y >= nailIn)
      {
    
      }
    }
    
  7. Inside the conditional statement you just created, set the nail’s Y position equal to the nailIn variable’s value. This will stop the nail from moving too far down.
    bottom_btn.onRollOver = function():Void
    {
      hammer_mc._rotation = rotateAmt;
      nail_mc._y += bashAmt;
      rotateAmt -= bashAmt / 7;
      if(nail_mc._y >= nailIn)
      {
        nail_mc._y = nailIn;
      }
    }
    
  8. On the next line of code, disable the interactivity for the bottom_btn button using the button’s enabled property.
    bottom_btn.onRollOver = function():Void
    {
      hammer_mc._rotation = rotateAmt;
      nail_mc._y += bashAmt;
      rotateAmt -= bashAmt / 7;
      if(nail_mc._y >= nailIn)
      {
        nail_mc._y = nailIn;
        bottom_btn.enabled = false;
      }
    }
    
  9. Test the movie, and pound that nail into the wood. Notice the nail stays where it belongs and the hammer stops rotating after you hammer the nail all the way in. Cool! All that you have left to do now is to make a way to play the game multiple times.
  10. Save the file, and keep it open for the next exercise.




Exercise 5-5


Contents
  Introduction
  Exercise 5-1
  Exercise 5-2
  Exercise 5-3
  Exercise 5-4
  Exercise 5-5

  Printable version
  Discuss this article