Frame 1
function playRandomSound() {
if (sound_is_on) {
sound_array[random(sound_array.length) + 1].start();
}
}
function setup() {
cells = array();
var i = 0;
while (i < size) {
cells[i] = array();
var j = 0;
while (j < size) {
cell = this.attachMovie("cell", (("cell_" + i) + "_") + j, (i * size) + j);
cell._x = ((cell._width + padding) * j) + 20;
cell._y = ((cell._height + padding) * i) + 20;
cell._rotation = random(4) * 90;
cell.rot = cell._rotation;
cell.onPress = cellClick;
cell.runFunction = cellRun;
cell.i = i;
cell.j = j;
cell.run = false;
cells[i][j] = cell;
j++;
}
i++;
}
ready = true;
}
function cellClick() {
if (ready) {
if (score > max) {
max = score;
}
score = 1;
this.onEnterFrame = cellThink;
this.gotoAndPlay(2);
playRandomSound();
this.rot = this._rotation + 90;
while (this.rot > 180) {
this.rot = this.rot - 360;
}
}
}
function cellRun() {
if (ready) {
score++;
this.onEnterFrame = cellThink;
this.gotoAndPlay(2);
playRandomSound();
this.rot = this.rot + 90;
while (this.rot > 180) {
this.rot = this.rot - 360;
}
}
}
function cellThink() {
ready = false;
this._rotation = this._rotation + speed;
if ((this._rotation - this.rot) == 0) {
ready = true;
this.onEnterFrame = null;
if (this.rot == n_e) {
if ((cells[this.i - 1][this.j].rot == s_w) || (cells[this.i - 1][this.j].rot == s_e)) {
cells[this.i - 1][this.j].runFunction();
this.arrow2.gotoAndPlay(2);
}
if ((cells[this.i][this.j + 1].rot == s_w) || (cells[this.i][this.j + 1].rot == n_w)) {
cells[this.i][this.j + 1].runFunction();
this.arrow1.gotoAndPlay(2);
}
} else if (this.rot == s_e) {
if ((cells[this.i + 1][this.j].rot == n_w) || (cells[this.i + 1][this.j].rot == n_e)) {
cells[this.i + 1][this.j].runFunction();
this.arrow1.gotoAndPlay(2);
}
if ((cells[this.i][this.j + 1].rot == s_w) || (cells[this.i][this.j + 1].rot == n_w)) {
cells[this.i][this.j + 1].runFunction();
this.arrow2.gotoAndPlay(2);
}
} else if (this.rot == s_w) {
if ((cells[this.i + 1][this.j].rot == n_w) || (cells[this.i + 1][this.j].rot == n_e)) {
cells[this.i + 1][this.j].runFunction();
this.arrow1.gotoAndPlay(2);
}
if ((cells[this.i][this.j - 1].rot == s_e) || (cells[this.i][this.j - 1].rot == n_e)) {
cells[this.i][this.j - 1].runFunction();
this.arrow1.gotoAndPlay(1);
}
} else if (this.rot == n_w) {
if ((cells[this.i - 1][this.j].rot == s_w) || (cells[this.i - 1][this.j].rot == s_e)) {
cells[this.i - 1][this.j].runFunction();
this.arrow1.gotoAndPlay(1);
}
if ((cells[this.i][this.j - 1].rot == s_e) || (cells[this.i][this.j - 1].rot == n_e)) {
cells[this.i][this.j - 1].runFunction();
this.arrow1.gotoAndPlay(2);
}
}
}
}
var size = 16;
var padding = 0;
var ready = false;
var speed = 10;
var score = 0;
var max = 0;
var n_e = -90;
var s_e = 0;
var s_w = 90;
var n_w = 180;
sound_is_on = true;
sound_mc._visible = false;
sound1 = new Sound(this);
sound1.attachSound("sound1");
sound1.setVolume(50);
sound2 = new Sound(this);
sound2.attachSound("sound2");
sound2.setVolume(50);
sound3 = new Sound(this);
sound3.attachSound("sound3");
sound3.setVolume(50);
sound4 = new Sound(this);
sound4.attachSound("sound4");
sound4.setVolume(50);
sound5 = new Sound(this);
sound5.attachSound("sound5");
sound5.setVolume(50);
sound6 = new Sound(this);
sound6.attachSound("sound6");
sound6.setVolume(50);
sound7 = new Sound(this);
sound7.attachSound("sound7");
sound7.setVolume(50);
sound_array = new array(sound1, sound2, sound3, sound4, sound5, sound6, sound7);
sound_btn.onPress = function () {
if (!sound_is_on) {
sound_mc._visible = false;
sound_is_on = true;
} else {
sound_mc._visible = true;
sound_is_on = false;
}
};
reset_btn.onPress = function () {
if (ready) {
setup();
}
};
setup();
Symbol 10 MovieClip Frame 1
stop();
Symbol 11 MovieClip [cell] Frame 1
stop();