frame 1 :
stop();
// declare and initialise variables
bombNum = 0;
lives = 3;
score = 0;
speed = 10;
// --------- INITIALISE ALIENS ------------- //
_global.initAliens = function(mc) {
depth = 0;
for (var i = 0; i<3; i++) {
for (var j = 0; j<10; j++) {
attachMovie(mc, mc+i+"_"+j, 100+depth);
_root[mc+i+"_"+j]._x = j*40;
_root[mc+i+"_"+j]._y = i*40-80;
depth++;
}
}
};
// ------- MOVE ALIENS ----------------- //
_global.moveAliens = function(mc, frame, alspeed) {
// count the dead baddies
_root.deadcount = 0;
// loop through baddies
for (var i = 0; i<3; i++) {
for (var j = 0; j<10; j++) {
// move horizontal
_root[mc+i+"_"+j]._x += speed;
// check if aliens hit defender
if (_root[mc+i+"_"+j].hitTest(_root.defender)) {
cleanup(mc);
_root.gotoAndStop(1);
}
// check if any aliens left alive
if (_root[mc+i+"_"+j] != null) {
++_root.deadcount;
}
// -------test bullet hit
bulleti = 6;
while (--bulleti>1) {
if (_root[mc+i+"_"+j].hittest(eval("_root.bullet"+bulleti))) {
_root[mc+i+"_"+j].removeMovieClip();
eval("_root.bullet"+bulleti).removeMovieClip();
_root.score += 1;
}
}
// hits left wall
if (_root[mc+i+"_"+j]._x<0) {
// set direction to right
speed = alspeed;
// drop down
dropdown = true;
break;
}
// hit right wall
if (_root[mc+i+"_"+j]._x>Stage.width) {
// set direction to left
speed = -alspeed;
// drop down
dropdown = true;
break;
}
}
}
// drop down all the rows
if (dropdown) {
for (var i = 0; i<3; i++) {
for (var j = 0; j<10; j++) {
_root[mc+i+"_"+j]._y += 20;
}
}
}
// reset flag
dropdown = false;
// if all aliens are dead
if (_root.deadcount == 0) {
// go to next level
_root.bombspeed = 0.0;
_root.gotoAndStop(frame);
}
};
// ----------- INIT BOMBS --------------- //
_global.initBombs = function(bombspeed) {
// drop bombs
if (Math.random()<bombspeed) {
// duplicate the bomb mc
attachMovie("bomb", "bomb"+bombNum, 200+bombNum);
// set the coords to a random position
eval("_root.bomb"+bombNum)._x = random(700);
eval("_root.bomb"+bombNum)._y = 300*Math.random();
// increment the bomb number
bombNum++;
// if more than 10 bombs , start again at 0
if (bombNum>10) {
bombNum = 0;
}
}
};
// -------------- MOVE BOMBS ---------------- //
_global.moveBombs = function(mc) {
var bombi = 0;
while (bombi<11) {
_root["bomb"+bombi]._y += 5;
// hitest defender
if (_root["bomb"+bombi].hittest(_root.defender)) {
_root["bomb"+bombi].removeMovieClip();
_root.lives -= 1;
// lives are all gone
if (_root.lives<=0) {
// go to start
Mouse.show();
_root.bombspeed = 0.0;
_root.gotoAndStop(1);
for (var i = 0; i<3; i++) {
for (var j = 0; j<10; j++) {
_root[mc+i+"_"+j]._visible = false;
}
}
break;
}
}
// test if bomb goes offscreen
if (_root["bomb"+bombi]._y>Stage.height) {
_root["bomb"+bombi].removeMovieClip();
}
bombi++;
}
};
// ---------- CLEAN UP -------- //
_global.cleanup = function(mc) {
_root.bombspeed = 0.0;
for (var i = 0; i<3; i++) {
for (var j = 0; j<10; j++) {
// move horizontal
_root[mc+i+"_"+j]._visible = false;
}
}
};
FRAME 2:
stop();
// initialise variables
bulletNum = 0;
dropdown = false;
speed = 10;
_root.bombspeed = 0.1;
initAliens("zombie");
// ----------- ONLOAD ----------- //
_root.onLoad = function() {
Mouse.hide();
};
// ------------- ENTERFRAME ---------- //
_root.onEnterFrame = function() {
// move the defender with the mouse.
_root.defender._x = _root._xmouse;
_root.defender._y = 385;
// bullet move
var y = 0;
while (y<6) {
eval("_root.bullet"+y)._y -= 30;
y++;
}
moveBombs("zombie");
moveAliens("zombie", 3, 10);
initBombs(_root.bombspeed);
};
// ------------- MOUSE CLICK ---------- //
_root.onMouseDown = function() {
// duplicate the bullet mc
attachMovie("bullet", "bullet"+bulletNum, bulletNum);
// set the coords to the mouse clik
eval("_root.bullet"+bulletNum)._x = _root.defender._x;
eval("_root.bullet"+bulletNum)._y = _root.defender._y;
// increment the bullet number
++bulletNum;
// if more than 5 bullets , start again at 0
if (bulletNum>5) {
bulletNum = 0;
}
};