Frame 1
function addballs() {
var _local2;
_root.createEmptyMovieClip("balls", 1);
var _local3 = 0;
while (_local3 < 15) {
_local2 = "ball" + _local3;
balls.attachMovie("enemy", _local2, _local3 + 10);
balls[_local2]._x = (Math.random() * (Stage.width - 10)) + 4;
balls[_local2]._y = (Math.random() * (Stage.height - 10)) + 4;
balls[_local2].dx = Math.random() * 5;
balls[_local2].dy = Math.random() * 5;
_local3++;
}
Mouse.hide();
}
function calcMotion(bname) {
var _local2 = tb.fps_txt.text;
balls[bname]._x = balls[bname]._x + (balls[bname].dx * (50 / _local2));
balls[bname]._y = balls[bname]._y + (balls[bname].dy * (50 / _local2));
}
function calcCollisions(bname) {
if (start_mc._visible == false) {
if (balls[bname]._x < 17) {
balls[bname]._x = 17;
balls[bname].dx = balls[bname].dx * -1;
}
if (balls[bname]._x > (Stage.width - 17)) {
balls[bname]._x = Stage.width - 17;
balls[bname].dx = balls[bname].dx * -1;
}
if (balls[bname]._y < 17) {
balls[bname]._y = 17;
balls[bname].dy = balls[bname].dy * -1;
}
if (balls[bname]._y > (Stage.height - 17)) {
balls[bname]._y = Stage.height - 17;
balls[bname].dy = balls[bname].dy * -1;
}
if ((dist2(bname) <= 34) && (Math.ceil((scoreTimeB - scoreTimeA) / 1000) > 2)) {
eg_mc._visible = true;
Mouse.show();
setScore();
var _local3 = getHighScore();
if ((_local3 == undefined) || (_local3 < Math.ceil((scoreTimeB - scoreTimeA) / 1000))) {
eg_mc.hs_txt.text = Math.ceil((scoreTimeB - scoreTimeA) / 1000);
saveHighScore(Math.ceil((scoreTimeB - scoreTimeA) / 1000));
} else {
eg_mc.hs_txt.text = _local3;
}
var _local1 = 0;
while (_local1 < 15) {
bname = "ball" + _local1;
balls[bname]._visible = false;
_local1++;
}
}
}
}
function setScore() {
var _local1 = " ....? Uhh...wana try that again?";
eg_mc.final_txt.text = Math.ceil((scoreTimeB - scoreTimeA) / 1000) + _local1;
}
function dist(xdist, ydist) {
return(Math.sqrt(Math.pow(xdist, 2) + Math.pow(ydist, 2)));
}
function dist2(bname1) {
var _local2;
var _local1;
_local2 = Math.abs(balls[bname1]._x - player_mc._x);
_local1 = Math.abs(balls[bname1]._y - player_mc._y);
return(dist(_local2, _local1));
}
function saveHighScore(score) {
myHighScore = SharedObject.getLocal("highScore");
myHighScore.data.score = score;
myHighScore.flush();
}
function getHighScore() {
myHighScore = SharedObject.getLocal("highScore");
return(myHighScore.data.score);
}
Mouse.hide();
var timeA = getTimer();
var timeB;
var scoreTimeA;
var scoreTimeB;
eg_mc._visible = false;
time_mc.time_txt._visible = false;
var j = 0;
start_mc.onEnterFrame = function () {
if (start_mc._currentframe == 200) {
addballs();
this._visible = false;
start_mc.gotoAndStop(1);
scoreTimeA = getTimer();
time_mc.time_txt._visible = true;
}
};
_root.onEnterFrame = function () {
var _local2;
if ((eg_mc._visible == false) && (start_mc._visible == false)) {
var _local1 = 0;
while (_local1 < 15) {
_local2 = "ball" + _local1;
calcMotion(_local2);
calcCollisions(_local2);
_local1++;
}
}
timeB = getTimer();
if (j == 5) {
tb.fps_txt.text = Math.ceil(1000 / (timeB - timeA));
j = 0;
}
j++;
timeA = getTimer();
scoreTimeB = getTimer();
if (eg_mc._visible == false) {
time_mc.time_txt.text = Math.ceil((scoreTimeB - scoreTimeA) / 1000);
}
};
player_mc.onEnterFrame = function () {
if ((((_xmouse < 17) or (_xmouse > (Stage.width - 17))) or (_ymouse < 17)) or (_ymouse > (Stage.height - 17))) {
if (Math.ceil((scoreTimeB - scoreTimeA) / 1000) > 2) {
eg_mc._visible = true;
Mouse.show();
setScore();
var _local1 = 0;
while (_local1 < 15) {
var _local2 = "ball" + _local1;
balls[_local2]._visible = false;
_local1++;
}
}
} else {
player_mc._x = _xmouse;
player_mc._y = _ymouse;
}
};
eg_mc.onRelease = function () {
this._visible = false;
start_mc.gotoAndPlay(1);
start_mc._visible = true;
scoreTimeA = getTimer();
};