Frame 1
tone1 = new Sound();
tone1.attachSound("Tone1");
tone2 = new Sound();
tone2.attachSound("Tone2");
tone3 = new Sound();
tone3.attachSound("Tone3");
tone4 = new Sound();
tone4.attachSound("Tone4");
tone5 = new Sound();
tone5.attachSound("Tone5");
sndWrong = new Sound();
sndWrong.attachSound("Error");
tick = new Sound();
tick.attachSound("Tick");
claxon = new Sound();
claxon.attachSound("Claxon");
crunch = new Sound();
crunch.attachSound("crunch");
explode = new Sound();
explode.attachSound("explode");
Instance of Symbol 14 MovieClip "progress" in Frame 1
onClipEvent (enterFrame) {
percentLoaded = int((_root.getBytesLoaded() / _root.getBytesTotal()) * 100);
this.gotoAndStop(percentLoaded);
if (99 < percentLoaded) {
_root.gotoAndStop("ready");
}
}
Frame 5
stop();
Frame 8
stop();
Frame 11
function checkBoard() {
var i = 1;
while (i < tileCount) {
var name = ("tile" + i);
if (eval (name).locked) {
if (((1 < eval (name)._currentframe) && (eval (name)._currentframe < 8)) && (tiles[eval (name).y][eval (name).x] != eval (name).index)) {
eval (name).gotoAndStop(1);
freeTiles.push(eval (name).index);
}
}
i++;
}
scan = false;
}
function bombClicked(x, y) {
var name;
var index;
var removed = 0;
if (((0 < droppingTiles.length) || (0 < slidingTiles.length)) || (0 < slidingNewTiles.length)) {
return(undefined);
}
if (tiles[y][x] == 0) {
return(undefined);
}
explode.start();
var n = 0;
while (n < 10) {
if (tiles[y][n] != 0) {
name = "tile" + tiles[y][n];
eval (name).gotoAndPlay("zap" + eval (name)._currentframe);
freeTiles.push(eval (name).index);
removed++;
tiles[y][n] = 0;
board[y][n] = 0;
var i = (y - 1);
while (i >= 0) {
if (tiles[i][n] == 0) {
break;
}
name = "tile" + tiles[i][n];
eval (name).locked = false;
tiles[i][n] = 0;
board[i][n] = 0;
droppingTiles.push(name);
i--;
}
}
n++;
}
if (droppingTiles.length == 0) {
checkBaseRow();
} else {
checkBase = true;
}
calcScore(removed);
}
function initGame() {
freeTiles = new Array();
tileCount = 0;
level = startlevel;
score = 0;
makeTextScore();
initLevel();
}
function initLevel() {
level++;
checkBase = false;
txtLevel = String(level);
makeTextScore();
playing = true;
startTime = getTimer();
gameDuration = 80 + (level * 5);
board = new Array();
tiles = new Array();
var i = 0;
while (i < 12) {
board.push(new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
tiles.push(new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
i++;
}
var maxRows = (level + 4);
if (8 < maxRows) {
maxRows = 8;
}
var x = 0;
while (x < 10) {
var i = (10 - int(Math.random() * maxRows));
var y = 11;
while (i < y) {
if (0 < freeTiles.length) {
var index = freeTiles.pop();
var name = ("tile" + index);
} else {
tileCount++;
index = tileCount;
var name = ("tile" + index);
duplicateMovieClip ("tile", name, index);
}
eval (name).index = index;
eval (name)._x = (x * 30) + 240;
eval (name)._y = (y * 30) + 57;
eval (name).x = x;
eval (name).y = y;
eval (name).locked = true;
var diff = (level + 2);
if (5 < diff) {
diff = 5;
}
var n = (random(diff) + 2);
eval (name).gotoAndStop(n);
board[y][x] = n;
tiles[y][x] = index;
y--;
}
x++;
}
tileTime = getTimer();
newTileInterval = 0.5 - ((level + 2) * 0.12);
if (newTileInterval < 0.1) {
newTileInterval = 0.1;
}
buildRow = true;
clearedTiles = 0;
tileTarget = (level * 10) + 40;
newRow = new Array();
droppingTiles = new Array();
newTiles = new Array();
slidingTiles = new Array();
slidingNewTiles = new Array();
gameOver = false;
warn = true;
}
function checkBaseLandingTile(index) {
var name = ("tile" + index);
var curX = eval (name).x;
var count = 0;
var slide = 0;
var minCol = -1;
var maxCol = 11;
x = 0;
while (x < 10) {
if ((board[11][x] != 0) && (tiles[11][x] != index)) {
if (minCol == -1) {
minCol = x;
}
maxCol = x;
count++;
}
x++;
}
if (((count == 0) || ((0 < curX) && (board[11][curX - 1] != 0))) || ((curX < 9) && (board[11][curX + 1] != 0))) {
return(undefined);
}
switch (curX) {
case 0 :
x = 1;
while ((board[11][x] == 0) && (x < 10)) {
slide++;
x++;
}
if (x == 10) {
}
break;
case :
x = 8;
while ((board[11][x] == 0) && (x >= 0)) {
slide--;
x--;
}
if (x < 0) {
}
break;
default :
if (eval (name).x < minCol) {
slide = (minCol - eval (name).x) - 1;
} else {
if (maxCol >= eval (name).x) {
break;
}
slide = (maxCol - eval (name).x) + 1;
}
}
if (slide != 0) {
eval (name).slide = slide * 5;
board[11][eval (name).x + slide] = eval (name)._currentframe;
tiles[11][eval (name).x + slide] = eval (name).index;
board[11][eval (name).x] = 0;
tiles[11][eval (name).x] = 0;
eval (name).x = eval (name).x + slide;
slidingNewTiles.push(name);
}
}
function popBoard() {
tileCount = 1;
var y = 0;
while (y < 13) {
var offset = ((y == 0) ? -6 : 0);
var x = 0;
while (x < 10) {
name = "tile" + tileCount;
duplicateMovieClip ("tile", name, tileCount);
eval (name).gotoAndStop(random(5) + 2);
eval (name)._x = (x * 30) + 240;
eval (name)._y = ((y * 30) + 27) + offset;
tileCount++;
x++;
}
y++;
}
}
function makeTextScore() {
txtScore = String(int(score));
while (txtScore.length < 7) {
txtScore = "0" + txtScore;
}
}
function dropTiles() {
if (0 < droppingTiles.length) {
var i;
var name;
var target;
var temp = new Array();
i = 0;
while (i < droppingTiles.length) {
name = droppingTiles[i];
if ((1 < eval (name)._currentframe) && (0 < (!eval (name).locked))) {
eval (name).y = Math.floor((eval (name)._y - 57) / 30);
eval (name).y = checkDown(eval (name).x, eval (name).y);
target = (eval (name).y * 30) + 57;
if (target < (eval (name)._y + 6)) {
eval (name)._y = target;
eval (name).locked = true;
board[eval (name).y][eval (name).x] = eval (name)._currentframe;
tiles[eval (name).y][eval (name).x] = eval (name).index;
temp.push(i);
} else {
eval (name)._y = eval (name)._y + 6;
}
}
i++;
}
}
if (0 < temp.length) {
var a = new Array();
var i = 0;
while (i < droppingTiles.length) {
var found = false;
var j = 0;
while (j < temp.length) {
if (temp[j] == i) {
found = true;
break;
}
j++;
}
if (!found) {
a.push(droppingTiles[i]);
}
i++;
}
droppingTiles = new Array();
if (0 < a.length) {
i = 0;
while (i < a.length) {
droppingTiles.push(a[i]);
i++;
}
}
}
if (checkBase && (droppingTiles.length == 0)) {
checkBoard();
checkBaseRow();
}
}
function dropNewTiles() {
var landed = -1;
if (0 < newTiles.length) {
var i;
var name;
var target;
var temp = new Array();
var test = false;
i = 0;
while (i < newTiles.length) {
name = newTiles[i];
if ((1 < eval (name)._currentframe) && (0 < (!eval (name).locked))) {
eval (name).y = Math.floor((eval (name)._y - 57) / 30);
eval (name).y = checkDown(eval (name).x, eval (name).y);
if (eval (name).y == 0) {
gameOver = true;
return(undefined);
}
target = (eval (name).y * 30) + 57;
if (target < (eval (name)._y + 10)) {
eval (name)._y = target;
eval (name).locked = true;
if (eval (name).y == 11) {
test = true;
landed = eval (name).index;
}
board[eval (name).y][eval (name).x] = eval (name)._currentframe;
tiles[eval (name).y][eval (name).x] = eval (name).index;
temp.push(i);
} else {
eval (name)._y = eval (name)._y + 10;
}
}
i++;
}
}
if (0 < temp.length) {
var a = new Array();
var i = 0;
while (i < newTiles.length) {
var found = false;
var j = 0;
while (j < temp.length) {
if (temp[j] == i) {
found = true;
break;
}
j++;
}
if (!found) {
a.push(newTiles[i]);
}
i++;
}
newTiles = new Array();
if (0 < a.length) {
i = 0;
while (i < a.length) {
newTiles.push(a[i]);
i++;
}
}
}
if (test) {
checkBase = true;
}
}
function slideNewTiles() {
var i;
var name;
var target;
var temp = new Array();
i = 0;
while (i < slidingNewTiles.length) {
name = slidingNewTiles[i];
if (0 < eval (name).slide) {
eval (name)._x = eval (name)._x + 6;
eval (name).slide--;
} else if (eval (name).slide < 0) {
eval (name)._x = eval (name)._x - 6;
eval (name).slide++;
}
if (eval (name).slide == 0) {
eval (name).locked = true;
temp.push(i);
}
i++;
}
if (0 < temp.length) {
var a = new Array();
var i = 0;
while (i < slidingNewTiles.length) {
var found = false;
var j = 0;
while (j < temp.length) {
if (temp[j] == i) {
found = true;
break;
}
j++;
}
if (!found) {
a.push(slidingNewTiles[i]);
}
i++;
}
slidingNewTiles = new Array();
if (0 < a.length) {
i = 0;
while (i < a.length) {
slidingNewTiles.push(a[i]);
i++;
}
}
}
}
function dumpTiles() {
var i = 1;
while (tileCount >= i) {
var name = ("tile" + i);
if (eval (name)._currentframe != 1) {
var x = Math.floor((eval (name)._x - 240) / 30);
var y = Math.floor((eval (name)._x - 57) / 30);
}
i++;
}
}
function dumpBoard() {
var y = 0;
while (y < 12) {
var str = "";
var x = 0;
while (x < 10) {
str = str + (" " + board[y][x]);
x++;
}
str = str + " ";
var txt;
var x = 0;
while (x < 10) {
txt = String(tiles[y][x]);
while (txt.length < 2) {
txt = "0" + txt;
}
str = str + (" " + txt);
x++;
}
y++;
}
}
function createNewTile() {
var index;
if (0 < newTiles.length) {
return(undefined);
}
if (0 < freeTiles.length) {
index = freeTiles.pop();
name = "tile" + index;
} else {
tileCount++;
index = tileCount;
var name = ("tile" + index);
duplicateMovieClip ("tile", name, index);
}
var x = newRow.length;
var snd = ("Tone" + (Math.floor(x / 2) + 1));
eval (snd).start();
newRow.push(name);
if (9 < newRow.length) {
newTileInterval = newTileInterval * 0.9;
buildRow = false;
}
eval (name).x = x;
eval (name).y = 0;
eval (name).index = index;
eval (name).locked = false;
var found = false;
if ((28 < random(30)) && (1 < level)) {
var n = 7;
} else {
var diff = (2 + level);
if (5 < diff) {
diff = 5;
}
var n = (random(diff) + 2);
}
eval (name).gotoAndStop(n);
eval (name)._x = (x * 30) + 240;
eval (name)._y = 21;
tileTime = getTimer();
}
function checkLeft(x, y) {
var n = x;
while (0 < n) {
if (tiles[y][n - 1] != 0) {
break;
}
n--;
}
return(n);
}
function checkRight(x, y) {
var n = x;
while (n < 10) {
if (tiles[y][n + 1] != 0) {
break;
}
n++;
}
return(n);
}
function checkDown(x, y) {
if (y < 0) {
y = 0;
}
while (y < 12) {
if (tiles[y + 1][x] != 0) {
break;
}
y++;
}
return(y);
}
function tileClicked(x, y) {
if (((0 < droppingTiles.length) || (0 < slidingTiles.length)) || (0 < slidingNewTiles.length)) {
return(undefined);
}
var cur = board[y][x];
var connected = 0;
var left;
var right;
var above;
var below;
left = (right = (above = (below = false)));
removed = 0;
if (cur == 0) {
pauseGame();
return(undefined);
}
if ((0 < x) && (board[y][x - 1] == cur)) {
left = true;
connected++;
}
if ((x < 9) && (board[y][x + 1] == cur)) {
right = true;
connected++;
}
if ((0 < y) && (board[y - 1][x] == cur)) {
above = true;
connected++;
}
if ((y < 11) && (board[y + 1][x] == cur)) {
below = true;
connected++;
}
if (connected == 0) {
sndWrong.start();
return(false);
}
crunch.start();
var index = tiles[y][x];
var name = ("tile" + index);
eval (name).gotoAndPlay("zap" + eval (name)._currentframe);
tiles[y][x] = 0;
board[y][x] = 0;
freeTiles.push(index);
removed = 1;
if (left) {
removeTile(x - 1, y, 1);
}
if (right) {
removeTile(x + 1, y, 2);
}
if (above) {
removeTile(x, y - 1, 3);
}
if (below) {
removeTile(x, y + 1, 4);
}
x = 0;
while (x < 10) {
var gap = false;
y = 11;
while (y >= 0) {
if (board[y][x] == 0) {
gap = true;
} else if (gap) {
name = "tile" + tiles[y][x];
tiles[y][x] = 0;
board[y][x] = 0;
eval (name).locked = false;
droppingTiles.push(name);
}
y--;
}
x++;
}
if (droppingTiles.length == 0) {
checkBaseRow();
} else {
checkBase = true;
}
calcScore(removed);
checkBoard();
}
function calcScore(removed) {
score = score + Math.pow(2, removed);
var found = false;
var x = 0;
while (x < 10) {
var y = 11;
while (y >= 0) {
if (board[y][x] != 0) {
found = true;
break;
}
y--;
}
if (found) {
break;
}
x++;
}
if (!found) {
score = score + 2000;
}
makeTextScore();
clearedTiles = clearedTiles + removed;
if (tileTarget < clearedTiles) {
freeTiles = new Array();
var i = 1;
while (tileCount >= i) {
var name = ("tile" + i);
if (eval (name)._currentframe != 1) {
eval (name).gotoAndPlay("zap" + eval (name)._currentframe);
freeTiles.push(i);
}
i++;
}
gotoAndPlay ("endLevel");
}
}
function removeTile(x, y, dir) {
var cur = board[y][x];
var index = tiles[y][x];
var name = ("tile" + index);
if (cur == 0) {
return(undefined);
}
eval (name).gotoAndPlay("zap" + eval (name)._currentframe);
tiles[y][x] = 0;
board[y][x] = 0;
removed++;
freeTiles.push(index);
if (((0 < x) && (dir != 2)) && (board[y][x - 1] == cur)) {
removeTile(x - 1, y, 1);
}
if (((x < 9) && (dir != 1)) && (board[y][x + 1] == cur)) {
removeTile(x + 1, y, 2);
}
if (((0 < y) && (dir != 4)) && (board[y - 1][x] == cur)) {
removeTile(x, y - 1, 3);
}
if (((y < 11) && (dir != 3)) && (board[y + 1][x] == cur)) {
removeTile(x, y + 1, 4);
}
}
function checkBaseRow() {
if (0 < slidingTiles.length) {
checkBase = true;
return(undefined);
}
var slide = 0;
var mid = -1;
var i = 4;
var pos = true;
var count = 0;
var x = 0;
while (x < 10) {
if (board[11][x] != 0) {
count++;
}
x++;
}
if (count == 10) {
checkBase = false;
return(undefined);
}
var x = 0;
while (x < 10) {
if (board[11][i] != 0) {
mid = i;
break;
}
if (pos) {
i = i + x;
pos = false;
} else {
i = i - x;
pos = true;
}
x++;
}
if (!mid) {
return(false);
}
slide = 0;
var x = mid;
while (x < 10) {
if (board[11][x] != 0) {
if (slide != 0) {
var y = 11;
while (y >= 0) {
if (board[y][x] == 0) {
break;
}
var name = ("tile" + tiles[y][x]);
slidingTiles.push(name);
board[y][x + slide] = board[y][x];
tiles[y][x + slide] = tiles[y][x];
board[y][x] = 0;
tiles[y][x] = 0;
eval (name).x = eval (name).x + slide;
eval (name).slide = slide * 5;
eval (name).locked = false;
y--;
}
}
} else {
slide--;
}
x++;
}
slide = 0;
var x = (mid - 1);
while (x >= 0) {
if (board[11][x] != 0) {
if (slide != 0) {
var y = 11;
while (y >= 0) {
if (board[y][x] == 0) {
break;
}
var name = ("tile" + tiles[y][x]);
slidingTiles.push(name);
board[y][x + slide] = board[y][x];
tiles[y][x + slide] = tiles[y][x];
board[y][x] = 0;
tiles[y][x] = 0;
eval (name).x = eval (name).x + slide;
eval (name).slide = slide * 5;
eval (name).locked = false;
y--;
}
}
} else {
slide++;
}
x--;
}
checkBase = false;
}
function slideTiles() {
var i;
var name;
var target;
var temp = new Array();
i = 0;
while (i < slidingTiles.length) {
name = slidingTiles[i];
if (0 < eval (name).slide) {
eval (name)._x = eval (name)._x + 6;
eval (name).slide--;
} else if (eval (name).slide < 0) {
eval (name)._x = eval (name)._x - 6;
eval (name).slide++;
}
if (eval (name).slide == 0) {
eval (name).locked = true;
temp.push(i);
}
i++;
}
if (0 < temp.length) {
var a = new Array();
var i = 0;
while (i < slidingTiles.length) {
var found = false;
var j = 0;
while (j < temp.length) {
if (temp[j] == i) {
found = true;
break;
}
j++;
}
if (!found) {
a.push(slidingTiles[i]);
}
i++;
}
slidingTiles = new Array();
if (0 < a.length) {
i = 0;
while (i < a.length) {
slidingTiles.push(a[i]);
i++;
}
}
}
}
function pauseGame() {
pauseTime = getTimer();
playing = false;
gotoAndStop ("pause");
}
function restartGame() {
startTime = startTime + (getTimer - pauseTime);
playing = true;
gotoAndPlay ("game");
}
function endGame() {
gotoAndPlay ("endGame");
}
paused = false;
startlevel = 0;
Frame 13
initGame();
Frame 22
play();
Frame 23
if (0 < slidingTiles.length) {
scan = true;
slideTiles();
} else if (0 < droppingTiles.length) {
scan = true;
dropTiles();
} else {
checkBoard();
}
dropNewTiles();
if (0 < slidingNewTiles.length) {
slideNewTiles();
}
if (buildRow) {
var curTileTime = ((getTimer() - tileTime) / 1000);
if (newTileInterval < curTileTime) {
createNewTile();
}
dropInc = 0;
} else if (0 < newRow.length) {
if (4 < dropInc) {
dropInc = 0;
var index = random(newRow.length);
var name = newRow[index];
eval (name).locked = false;
newTiles.push(name);
newRow.splice(index, 1);
if (newRow.length == 0) {
buildRow = true;
}
}
dropInc++;
}
var curTime = int((getTimer() - startTime) / 1000);
if (gameDuration < curTime) {
gameOver = true;
} else {
var secs;
var mins;
secs = gameDuration - curTime;
if ((secs < 10) && (warn)) {
claxon.start();
warn = false;
}
mins = int(secs / 60);
secs = secs - (mins * 60);
txtTime = String(secs);
while (txtTime.length < 2) {
txtTime = "0" + txtTime;
}
txtTime = ":" + txtTime;
txtTime = mins + txtTime;
while (txtTime.length < 5) {
txtTime = "0" + txtTime;
}
var i = (tileTarget - clearedTiles);
if (i < 0) {
i = 0;
}
txtBlocks = String(i);
}
if (gameOver) {
var i = 1;
while (tileCount >= i) {
removeMovieClip("tile" + i);
i++;
}
if (gameDuration < curTime) {
gotoAndPlay ("timesUp");
} else {
gotoAndPlay ("endGame");
}
} else {
gotoAndPlay ("gameLoop");
}
Frame 30
var curTime = ((getTimer() - startTime) / 1000);
var levelBonus = int((level * 5000) * (curTime / gameDuration));
score = score + levelBonus;
makeTextScore();
txtLevelEnd = ("LEVEL " + txtLevel) + " COMPLETED!";
txtBlocks = "0";
Frame 45
stop();
Frame 59
stop();
Frame 73
stop();
Frame 74
dumpTiles();
dumpBoard();
paused = true;
Symbol 14 MovieClip Frame 1
stop();
Symbol 39 Button
on (release) {
play();
}
Symbol 55 Button
on (release) {
play();
}
Symbol 56 MovieClip Frame 45
stop();
Symbol 56 MovieClip Frame 100
stop();
Symbol 56 MovieClip Frame 209
stop();
Symbol 61 Button
on (release) {
gotoAndPlay (11);
}
Symbol 64 Button
on (release) {
if (_root.paused) {
var tX = Math.floor((_x - 240) / 30);
var tY = Math.floor((_y - 57) / 30);
} else if (locked) {
_root.tileClicked(x, y);
}
}
Symbol 68 Button
on (release) {
if (locked) {
_root.bombClicked(x, y);
}
}
Symbol 69 MovieClip Frame 1
stop();
Symbol 69 MovieClip Frame 17
gotoAndStop (1);
Symbol 69 MovieClip Frame 27
gotoAndStop (1);
Symbol 69 MovieClip Frame 37
gotoAndStop (1);
Symbol 69 MovieClip Frame 47
gotoAndStop (1);
Symbol 69 MovieClip Frame 57
gotoAndStop (1);
Symbol 69 MovieClip Frame 64
gotoAndStop (1);
Symbol 70 Button
on (release) {
gotoAndPlay ("setupGame");
}
Symbol 96 Button
on (release) {
initLevel();
gotoAndPlay ("game");
}
Symbol 118 Button
on (release) {
initGame();
gotoAndPlay ("gameLoop");
}