Frame 1
function checkp(ball, pad) {
var bounds = pad.getBounds(_root);
if ((ball._x > bounds.xMin) && (ball._x < bounds.xMax)) {
var dx = (ball._x - pad._x);
var dy = (ball._y - pad._y);
var angle = ((pad._rotation * Math.PI) / 180);
var cosa = Math.cos(angle);
var sina = Math.sin(angle);
var y1 = ((dy * cosa) - (dx * sina));
var vy1 = ((ball.vy * cosa) - (ball.vx * sina));
if ((y1 > -10) && (y1 < vy1)) {
var x1 = ((dx * cosa) + (dy * sina));
var vx1 = ((ball.vx * cosa) + (ball.vy * sina));
y1 = -10;
vy1 = vy1 * bounce;
dx = (x1 * cosa) - (y1 * sina);
dy = (y1 * cosa) + (x1 * sina);
ball._x = pad._x + dx;
ball._y = pad._y + dy;
ball.vx = (vx1 * cosa) - (vy1 * sina);
ball.vy = (vy1 * cosa) + (vx1 * sina);
vr = vr - ((vy1 * dx) * 0.001);
}
}
}
function checkfloor(ball) {
var bounds = floor.getBounds(_root);
if ((ball._x > bounds.xMin) && (ball._x < bounds.xMax)) {
var dx = (ball._x - floor._x);
var dy = (ball._y - floor._y);
var angle = ((floor._rotation * Math.PI) / 180);
var cosa = Math.cos(angle);
var sina = Math.sin(angle);
var y1 = ((dy * cosa) - (dx * sina));
var vy1 = ((ball.vy * cosa) - (ball.vx * sina));
if ((y1 > -10) && (y1 < vy1)) {
var x1 = ((dx * cosa) + (dy * sina));
var vx1 = ((ball.vx * cosa) + (ball.vy * sina));
y1 = -10;
vy1 = vy1 * bounce;
dx = (x1 * cosa) - (y1 * sina);
dy = (y1 * cosa) + (x1 * sina);
ball._x = floor._x + dx;
ball._y = floor._y + dy;
ball.vx = (vx1 * cosa) - (vy1 * sina);
ball.vy = (vy1 * cosa) + (vx1 * sina);
}
}
}
function ballMove() {
this._rotation = this._rotation + (this.vx * Math.PI);
this.vy = this.vy + grav;
this._x = this._x + this.vx;
this._y = this._y + this.vy;
if (((this._x > 540) || (this._x < 0)) || (this._y > 400)) {
this.removeMovieClip();
}
var pp;
var i = 0;
while (i <= numPaddles) {
pp = _root["p" + i];
checkp(this, pp);
i++;
}
checkfloor(this);
checkwheel(this);
}
function checkwheel(ball) {
var dx = (ball._x - wheel._x);
var dy = (ball._y - wheel._y);
var dist = Math.sqrt((dx * dx) + (dy * dy));
if (dist < 60) {
var angle = Math.atan2(dy, dx);
ball._x = wheel._x + (Math.cos(angle) * 60);
ball._y = wheel._y + (Math.sin(angle) * 60);
var ballspeed = Math.sqrt((ball.vx * ball.vx) + (ball.vy * ball.vy));
ball.vx = (Math.cos(angle) * ballspeed) * (-bounce);
ball.vy = (Math.sin(angle) * ballspeed) * (-bounce);
}
}
bounce = -0.3;
grav = 0.5;
numPaddles = 6;
oneSlice = 360 / numPaddles;
count = 0;
i = 0;
while (i < numPaddles) {
pad = attachMovie("paddle", "p" + count, count++);
pad._x = 520;
pad._y = 230;
pad._rotation = (pad.base = i * oneSlice);
i++;
}
onEnterFrame = function () {
if ((getTimer() - start) > 1000) {
start = getTimer();
ball = attachMovie("ball", "b" + count, count++, {_x:50, _y:10, vx:Math.random(), vy:Math.random(), onEnterFrame:ballMove});
ball.gotoAndStop(Math.floor(Math.random() * 7) + 1);
}
vr = vr * 0.95;
baseRot = baseRot + vr;
wheel._rotation = baseRot;
i = 0;
while (i <= numPaddles) {
_root["p" + i]._rotation = baseRot + _root["p" + i].base;
i++;
}
};