Cosmetics


It's always best to work on the mission-critical elements of a project first and save cosmetics for the end. Otherwise, you might spend a lot of time working on something that doesn't get used. Cosmetics include creating visual effects, disabling controls when they aren't supposed to be used, and improving functionality.

Player Image and Score Dimming

To make Player 2's controls invisible and dim Player 2's image and score when the game is started, I added the following code to frame 1 of the main timeline:

 // Dim player 2's image and score, and hide controls  player2._alpha=20;  player2controls._visible=false; 

Because the switchPlayers() function was already being used to make the fire buttons visible, I decided to use it to swap the players' controls and dim the player images and scores. On frame 1, inside the switchPlayers() function, I first added the following code inside the if (currentplayer==1) evaluation:

 // Swap control visibility  player1controls._visible=true;  player2controls._visible=false;  // Swap player & score brightness  player1._alpha=100;  player2._alpha=20; 

Then inside the associated else statement, I added the following code:

 // Swap control visibility  player2controls._visible=true;  player1controls._visible=false;  // Swap player & score brightness  player2._alpha=100;  player1._alpha=20; 

Because both sets of controls remain on the stage rather than being attached and removed each time, the controls' settings are maintained while the other player is playing.

Trees

At this point, I was able to worry about the fact that the tanks were rolling over the trees as if they were bushes. I tried moving the layer with the trees above the layer with the tanks, but I quickly realized that the trees were now moving around underneath the tree trunks as well! In the Library, I duplicated the tree symbol, naming it tree top and renaming the existing tree symbol as tree bottom. In the tree top symbol, I deleted the trunk and shadow layers ; in the tree bottom symbol, I deleted the branches and leaves layer. I created a new layer, selected all the tree bottom instances, copied them, and used the Paste in Place command to place them in the same locations on the new layer. Then I had to manually replace each of the symbols in the new layer with the tree top symbol. Because all the tree top and symbol instances were in exactly the same location as the tree bottom symbol instances, it appeared as though they were still the same symbol. But I was able to make the tanks move above the tree trunks and below the tree branches by moving the tanks layer between the two tree layers.

Disabling Tank and Controls

To disable the tank movement while the bomb is in motion or the newgame movie clip is attached, I modified the first evaluation inside the onClipEvent(mouseDown) event on the player1tank symbol to also check whether the fire button is visible:

 if (_root.player1fire._visible &&  _root.player1target.hitTest(_root._xmouse, _root._ymouse, true)) { 

To disable the tank movement when the tank is already rotating or moving, I put the code inside the onClipEvent(mouseDown) event on the player1tank movie clip into the following if statement:

 // If the player 1 target was clicked upon and the tank isn't already  // moving or rotating, calculate the destination,  // and degrees, and trigger rotation, then movement  if (!motion && !rotation) {        // existing code here  } 

To disable the mouse icon swapping to the crosshairs over one of the islands when one player is waiting for the other to fire, I modified the if statement inside the onClipEvent(enterFrame) on the player1target movie clip to check whether the fire button is visible:

 if ((_root.player1fire._visible && _root.player1target.hitTest  (_parent._xmouse, _parent._ymouse, true))  (_root.player2fire.  _visible && _root.player2target.hitTest(_parent._xmouse,  parent._ymouse, true))) { 

To disable the controls while the bomb is in motion or the newgame movie clip is attached, in the indicator-long and indicator-short movie clips, I changed the code inside the on(press) event to this:

 if (_root.player1fire._visible  _root.player2fire._visible) {     _parent.dragging = true;  } 
Making the Controls Resettable

The controls were dynamically updated by the onClipEvent(enterFrame) event on the tank whenever the player pressed the invisible button on one of the three controls' indicators, setting the dragging variable to true. But if I had tried to also use other events to set the dragging variable to true, the onClipEvent(enterFrame) event on the tank would have immediately set it back to false. To allow other events to also update the controls, I had to move the code that updated each of the controls from the onClipEvent (enterFrame) on the player1tank and player2tank movie clips into new, separate functions. Based on the argument passed to it, these functions update the appropriate control and, except with the power control, animate the turret . The code on player1tank, for example, is as follows :

 // Define functions that update the controls and tank rotation  // & angle so they can be called when the movie is started, when  // a tank is hit, and when a new game is started.  function updateAngle(degrees) {     // Update the angle control      _root.player1controls.angle.indicator._rotation=degrees;      // Update the turret      this.turret.gotoAndStop(Math.abs(Math.round((90-degrees)/15)));  }  function updateDirection(degrees) {     // Update the direction control      _root.player1controls.direction.indicator._rotation=degrees;      // Update the turret      this.turret._rotation = degrees-90;  }  function updatePower(degrees) {     // Update the power control      _root.player1controls.power.indicator._rotation = degrees;  } 

By moving the code to update the controls and the turret into new functions, this code was replaced with a single call to the appropriate function that sends the degrees variable as an argument ”for example:

 // Update angle using function in onClipEvent(load) above  updateAngle(degrees); 

To actually update the controls to their middle points when the movie started, I added the following code to frame 1 of the player1controls movie clip:

 // Initialize control settings  _root.player1tank.updateAngle(45);  _root.player1tank.updateDirection(90);  _root.player1tank.updatePower(90); 

Hit Area

Until now, the bomb would decide that it had hit the tank only if the center point of the hitTest() function determined that the bomb movie clip intersected with the tank body or turret. To increase the area that would count as a hit, I had to increase the size of the tank movie clip. I placed an invisible button inside both tank movie clips to increase their size . (See Figure 25.13.)

Figure 25.13. The light gray indicates the invisible button that increases the size of the tank movie clips so that they are easier to hit.

graphics/25fig13.gif

Blast Skin

The blast skin is an overlay that the artist created, which makes the tank look like it has exploded. At first I tried putting the tank blast skin inside both tank body symbols so that it would automatically rotate when the tanks were moved. But because the tank turret symbols were on top of the tank body symbols, much of the tank blast skin was covered up. Instead, I placed the tank blast skin in the tank symbol itself, in a layer above the turret and body symbols.

This made it necessary to rotate the tank blast skin before making it visible when a tank was hit.

To make the blast skins invisible when the movie starts, I added the following to the main timeline:

 // Turn off blasted tank skins  player1tank.blast._visible=false;  player2tank.blast._visible=false; 

To make the blast skins invisible when a new game is started, I added the following into the on(press) event on the invisible button inside the newgame movie clip:

 // Reset the tank blast skins  _root.player1tank.blast._visible=false;  _root.player2tank.blast._visible=false; 

Because the tank blast skin no longer had the right proportions when the turret was pointing straight up, I had to add code to check the angle of the turret. On the bomb movie clip, inside the if statement that calls the hitTest() function to see whether the bomb movie clip intersects with the player1tank movie clip, I added the following if statement:

 // Player 1 was hit, make sure turret is not between  // the blast skin and tank body  if (_root.player1controls.angle.indicator._rotation < 25) {        _root.player1tank.updateAngle(45);  } 

If the _rotation property of the angle control's indicator is less than 25 °, it is reset to 45 ° with the updateAngle() function in the player1tank movie clip.

Because Player 2's controls are pointing the other direction, the values of the _rotation property are negative. So, on the bomb movie clip, inside the if statement that calls the hitTtest() function to see whether the bomb movie clip intersects with the player2movie clip, I added the following if statement:

 // Player 2 was hit, make sure turret is not between  // the blast skin and tank body  if (_root.player2controls.angle.indicator._rotation > -25) {     _root.player2tank.updateAngle(-45);  } 

To then evaluate whether the bomb has hit either island, I added the following code inside the else statement on the bomb:

 else if (_root.player1island.hitTest(_root._x, _root._y, true)   _root.player2island.hitTest(_root._x, _root._y, true)) {     // The island was hit, display sand blast      _parent.gotoAndStop("sandblast");  } 

Because of the (or) operator, the if statement evaluates as true if either of the two hitTest() functions indicates that one of the islands has been hit. If it has, the playhead is moved to the frame that contains the sand blast movie clip.



Inside Flash
Inside Flash MX (2nd Edition) (Inside (New Riders))
ISBN: 0735712549
EAN: 2147483647
Year: 2005
Pages: 257
Authors: Jody Keating

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net