Ping Pong - Score
| Category | : Flash | Views | : 18886 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : ping-pong-score.zip | ||
| Result | : See the result | ||||
| <<< Previous | Index Series | Next >>> |
Score is very easy to make, for this game we will have two scores. The player score and the opponent score:

They are just dynamic text boxes linked to a variable, "_root.opScore" and "_root.plScore".
Both are align to the right, so we can have 3 digits scores without having the number in the middle of the game.

In the main timeline, paste this code:
var opScore = 0;
var plScore = 0;
Open the actions for the ball Movie Clip and make these changes:
//if the opponent made a point
if (this._y > 300)
{
_x = (Math.random() * 180) + 10;
_y = (Math.random() * 280) + 10;
dir = Math.round(Math.random() * 1);
speed = 15;
//increase the opponent score by 1.
_root.opScore++;
if (dir == 1)
{
var Ang = 45;
} else {
var Ang = 135;
}
xspeed = speed * Math.cos((Ang) * Math.PI / 180);
yspeed = speed * Math.sin((Ang) * Math.PI / 180);
}
//if the player made a pont
else if (this._y < 0)
{
_x = (Math.random() * 180) + 10;
_y = (Math.random() * 280) + 10;
dir = Math.round(Math.random() * 1);
speed = 15;
//increase the player score by 1.
_root.plScore++;
if (dir == 1)
{
var Ang = 45 - 90 ;
} else {
var Ang = 135 + 90;
}
xspeed = speed * Math.cos((Ang) * Math.PI / 180);
yspeed = speed * Math.sin((Ang) * Math.PI / 180);
}
This is all you need to do for the score, very easy and simple.More cool tech articles from other blogs.
| <<< Previous | Index Series | Next >>> |
