• Home
  • Free Tutorials
  • Free Video Tutorials

Adobe Photoshop
Autodesk 3ds Max
CSS
Flash
Help Center Live
iPhone
Joomla
Make Money Online!
Mambo
mIRC
Outlook Express
SEO / SEM
Simple Machine Forum
Target Explorer

Ping Pong - Score

Category : Flash Views : 18887
Version : 8 Rating : 
3.0/5 (41 votes)
  • Currently 3.02/5
  • 1
  • 2
  • 3
  • 4
  • 5
Type : Text Source File: ping-pong-score.zip
Result: See the result


<<< PreviousIndex SeriesNext >>>

Previous | 1 | 2 | Next

Now let's make the game get difficult.
Every time the ball bounces on the pads or on the wall we need to increase the speed, this is also very easy.

Just add this code to the collision detection inside the Ball Movie Clip:
if (_root.Limits.Border.hitTest(this._x + xspeed, this._y + yspeed, true)) { xspeed = -xspeed; //if xspeed was 2; 2 * 1.05 = 2.1 xspeed *= 1.05; //if yspeed was 2; 2 * 1.05 = 2.1 yspeed *= 1.05; } if (_root.Limits.Pads.hitTest(this._x + xspeed, this._y + yspeed, true)) { yspeed = -yspeed; //the same thing as above xspeed *= 1.05; yspeed *= 1.05; }

Code Explanation

Most of the codes here have already been explained in the previous tutorial. We will just discuss the code that we have made changes.

var opScore = 0; var plScore = 0;
The first variable is used for the opponent's score and the second the player's score.

if (this._y > 300) { _x = (Math.random() * 180) + 10; _y = (Math.random() * 280) + 10; dir = Math.round(Math.random() * 1); speed = 15;
The rest of this code was already explained in the first tutorial of this game.

_root.opScore++;
We need to add this line, so we increase the opponent score by one every time the player didn't catch the ball.

else if (this._y < 0) { _x = (Math.random() * 180) + 10; _y = (Math.random() * 280) + 10; dir = Math.round(Math.random() * 1); speed = 15;

_root.plScore++;
Here, the code is used to tncrease the player score by one every time the opponent didn't catch the ball.

if (_root.Limits.Border.hitTest(this._x + xspeed, this._y + yspeed, true)) { xspeed = -xspeed; xspeed *= 1.05; yspeed *= 1.05;
The last two lines are used to increase the speed of the ball every time it hits a wall.

if (_root.Limits.Pads.hitTest(this._x + xspeed, this._y + yspeed, true)) { yspeed = -yspeed; xspeed *= 1.05; yspeed *= 1.05;
The last two lines increase the speed of the ball every time it hits a pad.

That all for this tutorial, in the next one we are going to make the game pause and add a scrolling text on it.


More cool tech articles from other blogs.

Place your ad here
Loading...


Previous | 1 | 2 | Next

<<< PreviousIndex SeriesNext >>>
How to Video Tutorials on software by Helpvids.com

Sponsors





Studio | Advertisement | About Webzo | Contact Webzo | Terms of Use | Free Video Tutorials by Helpivds

Copyright © 2007 NR Concepts Ltd. All rights reserved.