Frame 1
stop();
onEnterFrame = function () {
Reset = true;
};
Frame 2
function resetAll() {
ninjaId = 0;
Ninjat = new Array();
newWaitingTime = 100;
waitingTime = newWaitingTime;
maxNumberOfEnemies = 100;
numberOfEnemies = 0;
pisteet = 0;
showPisteet = 0;
createEnemy();
Ninjat[0][10] = 100;
happi = 100;
Main.attachMovie("nuoli", "Nuoli", maxNumberOfEnemies + 10);
Main.Nuoli._x = 300;
Main.Nuoli._y = 200;
aSwing = new Sound();
aHit = new Sound();
aHaja = new Sound();
aSwing.attachSound("swing");
aHit.attachSound("hit");
aHaja.attachSound("haja");
Reset = false;
}
function mittarit() {
showPisteet = showPisteet + ((pisteet - showPisteet) / 2);
pisteMittari.text = Math.round(showPisteet);
happi = happi - ((happi - Ninjat[0][10]) / 2);
happiPalikka._xscale = happi;
}
function controls(ninjaName, i) {
if (Ninjat[i][9]) {
if (Ninjat[i][4]) {
if (Ninjat[i][7] == 2) {
osumaTarkistus(ninjaName, i);
}
if (Ninjat[i][7] > 0) {
Ninjat[i][7]--;
} else {
Ninjat[i][4] = false;
}
}
if ((Ninjat[i][8] == 0) && (!Ninjat[i][4])) {
if (!Ninjat[i][0]) {
Main[ninjaName].gotoAndStop("idle_" + Ninjat[i][3]);
} else {
Main[ninjaName].gotoAndStop("jump_" + Ninjat[i][3]);
}
}
}
}
function physics(ninjaName, i) {
if (Main[ninjaName]._x < 20) {
Main[ninjaName]._x = 20;
}
if (Main[ninjaName]._x > 540) {
Main[ninjaName]._x = 540;
}
if (Ninjat[i][0]) {
Main[ninjaName]._y = Main[ninjaName]._y - Ninjat[i][1];
Ninjat[i][1]--;
}
if (Main[ninjaName]._y <= 400) {
Ninjat[i][2]++;
Main[ninjaName]._y = Main[ninjaName]._y + Ninjat[i][2];
} else {
Ninjat[i][2] = 0;
Ninjat[i][0] = false;
}
Main[ninjaName]._x = Main[ninjaName]._x + Math.round(Ninjat[i][13]);
Ninjat[i][13] = Ninjat[i][13] / 2;
Main[ninjaName]._x = Main[ninjaName]._x + Ninjat[i][8];
if (!Ninjat[i][9]) {
if (Ninjat[i][14] > 0) {
Ninjat[i][14]--;
} else {
Main[ninjaName].removeMovieClip();
}
}
}
function createEnemy() {
ninjaName = "Ninja" + ninjaId;
Ninjat[ninjaId] = new Array(true, 0, 0, "right", false, false, 0, 0, 20, true, 30, 10, 0, 0, 3);
Main.attachMovie("ninja", ninjaName, ninjaId);
if (ninjaId == 0) {
Main[ninjaName]._y = 300;
Main[ninjaName]._x = 300;
} else {
Main[ninjaName]._y = 300;
if (Math.round(Math.random() * 2) == 1) {
Main[ninjaName]._x = Math.round((Math.random() * 600) - 600);
} else {
Main[ninjaName]._x = Math.round((Math.random() * 600) + 600);
}
}
ninjaId++;
}
function kake() {
if ((Key.isDown(39) && (!Key.isDown(37))) && (!Key.isDown(32))) {
if ((Ninjat[0][3] != "right") || (Ninjat[0][8] == 0)) {
Main.Ninja0.gotoAndStop("run_right");
}
if (Ninjat[0][0]) {
Main.Ninja0.gotoAndStop("jump_right");
} else {
Main.Ninja0.gotoAndStop("run_right");
}
Ninjat[0][3] = "right";
Ninjat[0][8] = 20;
} else if ((Key.isDown(37) && (!Key.isDown(39))) && (!Key.isDown(32))) {
if ((Ninjat[0][3] != "left") || (Ninjat[0][8] == 0)) {
Main.Ninja0.gotoAndStop("run_left");
}
if (Ninjat[0][0]) {
Main.Ninja0.gotoAndStop("jump_left");
} else {
Main.Ninja0.gotoAndStop("run_left");
}
Ninjat[0][3] = "left";
Ninjat[0][8] = -20;
} else {
Ninjat[0][8] = 0;
}
if ((Key.isDown(32) && (!Key.isDown(39))) && (!Key.isDown(37))) {
if ((!Ninjat[0][4]) && (releaseSpace)) {
Ninjat[0][4] = true;
Ninjat[0][7] = 5;
if (Ninjat[0][0]) {
Main.Ninja0.gotoAndStop("jumpattack_" + Ninjat[0][3]);
} else {
Main.Ninja0.gotoAndStop("melee_" + Ninjat[0][3]);
}
Ninjat[8][0] = 0;
aSwing.start(0, 1);
releaseSpace = false;
}
} else if ((Key.isDown(32) && (Key.isDown(39))) || (Key.isDown(32) && (Key.isDown(37)))) {
if ((!Ninjat[0][4]) && (releaseSpace)) {
Ninjat[0][4] = true;
Ninjat[0][7] = 5;
if (Ninjat[0][3] == "right") {
Ninjat[0][13] = 50;
} else {
Ninjat[0][13] = -50;
}
aSwing.start(0, 1);
Main.Ninja0.gotoAndStop("runattack_" + Ninjat[0][3]);
releaseSpace = false;
}
} else {
releaseSpace = true;
}
if (Key.isDown(38)) {
if (!Ninjat[0][0]) {
Ninjat[0][0] = true;
Ninjat[0][1] = 20;
Main.Ninja0.gotoAndStop("jump_" + Ninjat[0][3]);
aHaja.start(0.3, 1);
}
}
}
function ninjaAI(ninjaName, i) {
if (Ninjat[i][9]) {
if ((Ninjat[i][6] <= 0) && (!Ninjat[i][4])) {
Ninjat[i][8] = 0;
if (Main[ninjaName]._x > Main.Ninja0._x) {
Ninjat[i][3] = "left";
}
if (Main[ninjaName]._x < Main.Ninja0._x) {
Ninjat[i][3] = "right";
}
if ((Main[ninjaName]._x - 90) > Main.Ninja0._x) {
if (Ninjat[i][0]) {
Main[ninjaName].gotoAndStop("jump_left");
} else {
Main[ninjaName].gotoAndStop("run_left");
}
Ninjat[i][3] = "left";
Ninjat[i][8] = -20;
} else if ((Main[ninjaName]._x + 90) < Main.Ninja0._x) {
if (Ninjat[i][0]) {
Main[ninjaName].gotoAndStop("jump_right");
} else {
Main[ninjaName].gotoAndStop("run_right");
}
Ninjat[i][3] = "right";
Ninjat[i][8] = 20;
} else if (!Ninjat[i][4]) {
Ninjat[i][4] = true;
Ninjat[i][7] = 5;
if (Ninjat[i][0]) {
Main[ninjaName].gotoAndStop("jumpattack_" + Ninjat[i][3]);
} else {
Main[ninjaName].gotoAndStop("melee_" + Ninjat[i][3]);
}
aSwing.start(0, 1);
}
if (Main[ninjaName]._y > Main.Ninja0._y) {
if (!Ninjat[i][0]) {
Ninjat[i][0] = true;
Ninjat[i][1] = 20;
Main[ninjaName].gotoAndStop("jump_" + Ninjat[i][3]);
}
}
Ninjat[i][6] = Math.round((Math.random() * 5) + 5);
} else {
Ninjat[i][6]--;
}
}
}
function osumaTarkistus(ninjaName, i) {
n = 0;
while (n <= Ninjat.length) {
if ((i == 0) && (n != 0)) {
if (Ninjat[n][9]) {
if (Main[ninjaName].hitTest(Main["Ninja" + n])) {
Ninjat[n][10] = Ninjat[n][10] - Ninjat[0][11];
if (Main.Ninja0._x > Main["Ninja" + n]._x) {
Ninjat[n][13] = -50;
} else {
Ninjat[n][13] = 50;
}
aHit.start(0.1, 1);
if (Ninjat[n][10] <= 0) {
pisteet = pisteet + 100;
Ninjat[n][9] = false;
Ninjat[n][8] = 0;
Main["Ninja" + n].gotoAndStop("death_" + Ninjat[n][3]);
} else {
Ninjat[n][12] = 5;
Ninjat[n][8] = 0;
Main["Ninja" + n].gotoAndStop("hurt_" + Ninjat[n][3]);
aHit.start(0.1, 1);
momentti = momentti + 10;
}
}
}
}
n++;
}
if (i >= 1) {
if (Main[ninjaName].hitTest(Main.Ninja0)) {
Ninjat[0][10] = Ninjat[0][10] - Ninjat[i][11];
if (Main.Ninja0._x < Main[ninjaName]._x) {
Ninjat[0][13] = -50;
} else {
Ninjat[0][13] = 50;
}
aHit.start(0.1, 1);
if (Ninjat[0][10] <= 0) {
Ninjat[0][9] = false;
Ninjat[n][8] = 0;
Main.Ninja0.gotoAndStop("death_" + Ninjat[0][3]);
} else {
Ninjat[0][12] = 5;
Ninjat[0][8] = 0;
Main.Ninja0.gotoAndStop("hurt_" + Ninjat[0][3]);
}
}
}
}
function nuoli() {
Main.Nuoli._x = Main.Ninja0._x;
Main.Nuoli._y = Main.Ninja0._y - 20;
}
function gameOver() {
if ((!Ninjat[0][9]) || (numberOfEnemies >= maxNumberOfEnemies)) {
gotoAndStop (3);
}
}
onEnterFrame = function () {
if (Reset) {
resetAll();
}
gameOver();
if (waitingTime <= 0) {
newWaitingTime = newWaitingTime - 1;
waitingTime = newWaitingTime;
if (numberOfEnemies < maxNumberOfEnemies) {
createEnemy();
}
numberOfEnemies++;
} else {
waitingTime--;
}
nuoli();
kake();
i = 1;
while (i <= (Ninjat.length - 1)) {
ninjaName = "Ninja" + i;
ninjaAI(ninjaName, i);
i++;
}
i = 0;
while (i <= (Ninjat.length - 1)) {
ninjaName = "Ninja" + i;
physics(ninjaName, i);
if (Ninjat[i][12] > 0) {
Ninjat[i][12]--;
} else {
controls(ninjaName, i);
}
i++;
}
mittarit();
};
Frame 3
pisteMittari.text = pisteet;
Symbol 62 Button
on (release) {
gotoAndStop (2);
}
Symbol 71 Button
on (release) {
gotoAndStop (1);
}