web design template web design template web design template

Page : 1 2 3 4

1. At frame 3 of Walls layer select the top wall

2. Choose Window > Actions

3. In the Actions panel type the following actions


onClipEvent (enterFrame) {
  if (this.hitTest(_parent.ball)) {
    _root.numy = 12;
    _root.go=1;
  }  
}


// This action checks the collision of ball with the wall and assigns a new value '12' to 'numy' variable. It also assigns value '1' to a new variable 'go' which is not initialized yet. When any variable is not initialized then its default value is considered as '0'

4. Now select the wall on the right hand side

5. In the Actions panel type the following actions

onClipEvent (enterFrame) {
  if (this.hitTest(_parent.ball)) {
    _root.numx = -random(10);
    _root.go=1;
  }  
}


// This action checks the collision of ball with the wall and assigns a new value '-random(10)' to 'numx' variable. '-random(10)' generates any number from 0 to -9.

6. Select the wall on the left hand side

7. In the Actions panel type the following actions

onClipEvent (enterFrame) {
  if (this.hitTest(_parent.ball)) {
    _root.numx = random(10);
    _root.go=1;
  }  
}

// This action checks the collision of ball with the wall and assigns a new value 'random(10)' to 'numx' variable. 'random(10)' generates any number from 0 to 9.

8. Select the floor (wall2 Movie Clip)

9. In the Actions panel type the following actions

onClipEvent (enterFrame) {
  if (this.hitTest(_parent.ball)) {
    _root.hit--;
    _root.go=2;
    _parent.life.play();
    _root.numy = -12;
    gotoAndPlay(2);
  }  
  if (_root.hit == 0) {
    gotoAndStop(5);
  }  
}



// _root.hit--;
Everytime when ball hits the floor, this action reduces the value of variable 'hit' by 1.

// _root.go=2;
This action assigns value '2' to variable 'go'

// _parent.life.play();
This action targets the life movie clip and starts playing it.

// _root.numy = -12;
This action assigns a new value '-12' to variable 'numy'

// if (_root.hit == 0) {
    gotoAndStop(5);
  }  
}
This action checks whether the value of variable 'hit' is exactly '0' then the actionscript will stop at frame 5.


10. At frame 3 of Bat layer select the bat movie clip.

11. In the Actions panel type the following actions

onClipEvent (load) {

  startDrag("", true, -46, 120, 46, 120);
  Mouse.hide();
}
onClipEvent (enterFrame) {
  if (this.hitTest(_parent.ball) && _root.go == 1) {
    _root.numy = -12;
    _root.score++;
  }  
}



// onClipEvent (load) {

  startDrag("", true, -46, 120, 46, 120);
  Mouse.hide();
}
This action helps the bat movie clip to drag in a specific area with the help of mouse. At the same time it hides the mouse.

// if (this.hitTest(_parent.ball) && _root.go == 1)
This action checks two conditions at a time. It checks whether ball hits bat and the value of variable 'go' is exactly '1'

// _root.numy = -12;
This action assigns a new value '-12' to variable 'numy'

// _root.score++;
Everytime when ball hits bat, this action increments the value of variable 'score' by '1'


12. At frame 3 of Ball layer select the ball movie clip.

13. In the Actions panel type the following actions

onClipEvent (enterFrame) {

  setProperty(this, _x, getProperty(this,_x)+ _root.numx);
  setProperty(this, _y, getProperty(this,_y)+ _root.numy);
}


// setProperty(this, _x, getProperty(this,_x)+ _root.numx);
This action determines the x position of ball.

// setProperty(this, _y, getProperty(this,_y)+ _root.numy);
This action determines the y position of ball. Both these actions determines the movement of the ball.

14. Select the wall2 movie clip (floor) and shift it slightly down so that it creates some space between the bat and itself.


Now come back into Scene 1 and on a new layer create an outline to the game.

Note: After finishing upto here you can place the ball anywhere in the game. When the game will start the ball will start falling from that point.

Choose Control > Test Movie and see how the game works. If you wish to increase the speed of the game, change the frame rate (fps) of the flash movie (Choose Modify > Document). Make it 35 or 40. It will increase the speed of the ball and the game will become more difficult to play.

Regards,

Manoj Kotak.
The author is Director of Image Online Pvt. Ltd.
Developer of Layout Galaxy web site design templates for photoshop and Flash.

All accompanying logos, brands and product names are trademarks of their respective companies.

Blood for humans comes only from humans : Donate Blood
http://www.donate-blood.org   E-mail - om@donate-blood.org





© Image Online  2001-2003