Frame 1
stop();
Frame 2
function initGame() {
firstBox = 1;
lastBox = 0;
hits = 5;
totalBox = 50;
timeSinceLastBox = 0;
bgSpeed = 0;
attachMovie("rect", "rect", 999999);
rect._x = 275;
rect._y = 200;
}
function moveRect() {
if (rect._currentFrame > 4) {
dx = 0;
} else if (Key.isDown(39)) {
dx = bgSpeed;
rect.gotoAndStop("left");
} else if (Key.isDown(37)) {
dx = -bgSpeed;
rect.gotoAndStop("right");
} else {
dx = 0;
rect.gotoAndStop("normal");
}
rect._x = rect._x + dx;
if (rect._x < 150) {
rect._x = 150;
}
if (rect._x > 400) {
rect._x = 400;
}
if (bgSpeed < 20) {
bgSpeed = bgSpeed + 0.5;
}
}
function newBox() {
if (timeSinceLastBox > 5) {
if (lastBox < totalBox) {
if (Math.random() < 0.1) {
lastBox++;
attachMovie("box", "box" + lastBox, lastBox);
_root["box" + lastBox]._x = (Math.random() * 250) + 150;
_root["box" + lastBox]._y = 450;
f = int(Math.random() * _root["box" + lastBox]._totalFrames) + 1;
_root["box" + lastBox].gotoAndStop(f);
timeSinceLastBox = 0;
_root["box" + i].hit = false;
}
}
}
timeSinceLastBox++;
}
function moveBox() {
i = firstBox;
while (i <= lastBox) {
x = _root["box" + i]._x;
y = _root["box" + i]._y - bgSpeed;
if (y < -50) {
removebox(i);
} else if (((_root["box" + i].hit == false) and (Math.abs(y - rect._y) < 90)) and (Math.abs(x - rect._x) < 25)) {
hits = hits - 1;
_root["box" + i].hit = true;
rect.gotoAndPlay("hit");
bgSpeed = 0;
if (hits == 0) {
removeAll();
totalBox = n;
gotoAndPlay ("lose");
}
}
_root["box" + i]._y = y;
i++;
}
}
function removeBox(n) {
_root["box" + n].removeMovieClip();
firstBox = n + 1;
if (n == totalBox) {
removeAll();
gotoAndPlay ("win");
}
}
function removeAll() {
i = firstBox;
while (i <= lastBox) {
_root["box" + i].removeMovieClip();
i++;
}
rect.removeMovieClip();
}
stop();
Instance of Symbol 20 MovieClip in Frame 2
onClipEvent (load) {
_root.initGame();
}
onClipEvent (enterFrame) {
_root.moveRect();
_root.newBox();
_root.moveBox();
}
Frame 3
stop();
Frame 4
stop();
Symbol 15 Button
on (release) {
gotoAndStop (2);
}