• 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 - Ball Movement

Category : Flash Views : 40084
Version : 8 Rating : 
2.9/5 (67 votes)
  • Currently 2.85/5
  • 1
  • 2
  • 3
  • 4
  • 5
Type : Text Source File: ping-pong-ball-movement.zip
Result: See the result


Index SeriesNext >>>

Previous | 1 | 2 | 3 | 4 | Next

this._x += xspeed; this._y += yspeed;
Move the Ball to desired direction.

if (this._y > 200) {
If the Ball moves below 200px the player didn't catch the Ball.

_x = (Math.random() * 80) + 10; _y = (Math.random() * 180) + 10;
Reset the ball coordinate.

dir = Math.round(Math.random() * 1); speed = 10; 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); }
And get new direction and speeds just like on the load event.

else if (this._y < 0) {
If the Ball is above 0px the PC didn't catch the Ball.

_x = (Math.random() * 80) + 10; _y = (Math.random() * 180) + 10; dir = Math.round(Math.random() * 1); speed = 10; if (dir == 1) { var Ang = -45 ; } else { var Ang = 225; } xspeed = speed * Math.cos((Ang) * Math.PI / 180); yspeed = speed * Math.sin((Ang) * Math.PI / 180); } }
Above is almost the same code as before; we just use different angles as we want the Ball to start moving up instead of down. For that we use the angles -45 and 225.

This is all in the ball's movement. Next tutorial is about moving the player pad.


More cool tech articles from other blogs.

Place your ad here
Loading...


Previous | 1 | 2 | 3 | 4 | Next

Index 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.