Frame 1
_global.stage_mc = this;
_global.preloader = function () {
bytesTotal = _root.getBytesTotal();
bytesLoaded = _root.getBytesLoaded();
if (bytesLoaded >= bytesTotal) {
gotoAndStop ("start");
} else {
percent_mc.percentBar_mc._width = (bytesLoaded / bytesTotal) * 100;
gotoAndPlay ("preload");
}
};
_global.preloader2 = function () {
if (percent_mc.percentBar_mc._width >= 100) {
gotoAndStop ("start");
} else {
percent_mc.percentBar_mc._width = percent_mc.percentBar_mc._width + 1;
gotoAndPlay ("preload");
}
};
_global.preloader();
var MochiAd = {getVersion:function () {
return("2.3");
}, showPreGameAd:function (options) {
var _local27 = {clip:_root, ad_timeout:3000, fadeout_time:250, regpt:"o", method:"showPreloaderAd", color:16747008, background:16777161, outline:13994812, ad_started:function () {
this.clip.stop();
}, ad_finished:function () {
this.clip.play();
}, ad_failed:function () {
trace("[MochAd] Couldn't load an ad, make sure that your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_loaded:function (width, height) {
}};
options = MochiAd._parseOptions(options, _local27);
if ("5cc6f7dfb67f2f08341c831480f7c2a7".length == 0) {
options.ad_started();
options.ad_finished();
return(undefined);
}
var clip = options.clip;
var _local23 = 11000;
var _local26 = options.ad_timeout;
delete options.ad_timeout;
var fadeout_time = options.fadeout_time;
delete options.fadeout_time;
if (!MochiAd.load(options)) {
options.ad_failed();
options.ad_finished();
return(undefined);
}
options.ad_started();
var mc = clip._mochiad;
mc.onUnload = function () {
options.ad_finished();
};
var _local14 = MochiAd._getRes(options);
var _local4 = _local14[0];
var _local13 = _local14[1];
mc._x = _local4 * 0.5;
mc._y = _local13 * 0.5;
var chk = mc.createEmptyMovieClip("_mochiad_wait", 3);
chk._x = _local4 * -0.5;
chk._y = _local13 * -0.5;
var _local7 = chk.createEmptyMovieClip("_mochiad_bar", 4);
_local7._x = 10;
_local7._y = _local13 - 20;
var _local22 = options.color;
delete options.color;
var _local19 = options.background;
delete options.background;
var _local24 = options.outline;
delete options.outline;
var _local5 = _local7.createEmptyMovieClip("_outline", 1);
_local5.beginFill(_local19);
_local5.moveTo(0, 0);
_local5.lineTo(_local4 - 20, 0);
_local5.lineTo(_local4 - 20, 10);
_local5.lineTo(0, 10);
_local5.lineTo(0, 0);
_local5.endFill();
var _local3 = _local7.createEmptyMovieClip("_inside", 2);
_local3.beginFill(_local22);
_local3.moveTo(0, 0);
_local3.lineTo(_local4 - 20, 0);
_local3.lineTo(_local4 - 20, 10);
_local3.lineTo(0, 10);
_local3.lineTo(0, 0);
_local3.endFill();
_local3._xscale = 0;
var _local6 = _local7.createEmptyMovieClip("_outline", 3);
_local6.lineStyle(0, _local24, 100);
_local6.moveTo(0, 0);
_local6.lineTo(_local4 - 20, 0);
_local6.lineTo(_local4 - 20, 10);
_local6.lineTo(0, 10);
_local6.lineTo(0, 0);
chk.ad_msec = _local23;
chk.ad_timeout = _local26;
chk.started = getTimer();
chk.showing = false;
chk.last_pcnt = 0;
chk.fadeout_time = fadeout_time;
chk.fadeFunction = function () {
var _local2 = 100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time));
if (_local2 > 0) {
this._parent._alpha = _local2;
} else {
var _local3 = this._parent._parent;
MochiAd.unload(_local3);
delete this.onEnterFrame;
}
};
mc.lc.adLoaded = options.ad_loaded;
mc.lc.adjustProgress = function (msec) {
var _local2 = this.mc._mochiad_wait;
_local2.server_control = true;
_local2.started = getTimer();
_local2.ad_msec = msec;
};
chk.onEnterFrame = function () {
var _local6 = this._parent._parent;
var _local12 = this._parent._mochiad_ctr;
var _local5 = getTimer() - this.started;
var _local3 = false;
var _local4 = _local6.getBytesTotal();
var _local8 = _local6.getBytesLoaded();
var _local10 = (100 * _local8) / _local4;
var _local11 = (100 * _local5) / chk.ad_msec;
var _local9 = this._mochiad_bar._inside;
var _local2 = Math.min(100, Math.min(_local10 || 0, _local11));
_local2 = Math.max(this.last_pcnt, _local2);
this.last_pcnt = _local2;
_local9._xscale = _local2;
if (!chk.showing) {
var _local7 = _local12.getBytesTotal();
if ((_local7 > 0) || (typeof(_local7) == "undefined")) {
chk.showing = true;
chk.started = getTimer();
} else if (_local5 > chk.ad_timeout) {
options.ad_failed();
_local3 = true;
}
}
if (_local5 > chk.ad_msec) {
_local3 = true;
}
if (((_local4 > 0) && (_local8 >= _local4)) && (_local3)) {
if (this.server_control) {
delete this.onEnterFrame;
} else {
this.fadeout_start = getTimer();
this.onEnterFrame = chk.fadeFunction;
}
}
};
}, showInterLevelAd:function (options) {
var _local13 = {clip:_root, ad_timeout:2000, fadeout_time:250, regpt:"o", method:"showTimedAd", ad_started:function () {
this.clip.stop();
}, ad_finished:function () {
this.clip.play();
}, ad_failed:function () {
trace("[MochAd] Couldn't load an ad, make sure that your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_loaded:function (width, height) {
}};
options = MochiAd._parseOptions(options, _local13);
var clip = options.clip;
var _local10 = 11000;
var _local12 = options.ad_timeout;
delete options.ad_timeout;
var fadeout_time = options.fadeout_time;
delete options.fadeout_time;
if (!MochiAd.load(options)) {
options.ad_failed();
options.ad_finished();
return(undefined);
}
options.ad_started();
var mc = clip._mochiad;
mc.onUnload = function () {
options.ad_finished();
};
var _local5 = MochiAd._getRes(options);
var _local14 = _local5[0];
var _local11 = _local5[1];
mc._x = _local14 * 0.5;
mc._y = _local11 * 0.5;
var chk = mc.createEmptyMovieClip("_mochiad_wait", 3);
chk.ad_msec = _local10;
chk.ad_timeout = _local12;
chk.started = getTimer();
chk.showing = false;
chk.fadeout_time = fadeout_time;
chk.fadeFunction = function () {
var _local2 = 100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time));
if (_local2 > 0) {
this._parent._alpha = _local2;
} else {
var _local3 = this._parent._parent;
MochiAd.unload(_local3);
delete this.onEnterFrame;
}
};
mc.lc.adLoaded = options.ad_loaded;
mc.lc.adjustProgress = function (msec) {
var _local2 = this.mc._mochiad_wait;
_local2.server_control = true;
_local2.started = getTimer();
_local2.ad_msec = msec - 250;
};
chk.onEnterFrame = function () {
var _local5 = this._parent._mochiad_ctr;
var _local4 = getTimer() - this.started;
var _local2 = false;
if (!chk.showing) {
var _local3 = _local5.getBytesTotal();
if ((_local3 > 0) || (typeof(_local3) == "undefined")) {
chk.showing = true;
chk.started = getTimer();
} else if (_local4 > chk.ad_timeout) {
options.ad_failed();
_local2 = true;
}
}
if (_local4 > chk.ad_msec) {
_local2 = true;
}
if (_local2) {
if (this.server_control) {
delete this.onEnterFrame;
} else {
this.fadeout_start = getTimer();
this.onEnterFrame = this.fadeFunction;
}
}
};
}, showTimedAd:function (options) {
trace("[MochiAd] DEPRECATED: showTimedAd was renamed to showInterLevelAd in 2.0");
MochiAd.showInterLevelAd(options);
}, showPreloaderAd:function (options) {
trace("[MochiAd] DEPRECATED: showPreloaderAd was renamed to showPreGameAd in 2.0");
MochiAd.showPreGameAd(options);
}, _allowDomains:function (server) {
var _local1 = server.split("/")[2].split(":")[0];
if (System.security) {
if (System.security.allowDomain) {
System.security.allowDomain("*");
System.security.allowDomain(_local1);
}
if (System.security.allowInsecureDomain) {
System.security.allowInsecureDomain("*");
System.security.allowInsecureDomain(_local1);
}
}
return(_local1);
}, _loadCommunicator:function (options) {
var _local26 = {clip:_root, com_server:"http://x.mochiads.com/com/1/", method:"loadCommunicator", depth:10337, id:"_UNKNOWN_"};
options = MochiAd._parseOptions(options, _local26);
options.swfv = options.clip.getSWFVersion() || 6;
options.mav = MochiAd.getVersion();
var _local18 = options.clip;
var _local20 = "_mochiad_com_" + options.id;
if (!MochiAd._isNetworkAvailable()) {
return(null);
}
if (_local18[_local20]) {
return(_local18[_local20].lc);
}
var _local21 = options.com_server + options.id;
MochiAd._allowDomains(_local21);
delete options.id;
delete options.com_server;
var _local25 = options.depth;
delete options.depth;
var _local17 = _local18.createEmptyMovieClip(_local20, _local25);
var _local11 = _local17.createEmptyMovieClip("_mochiad_com", 1);
for (var _local15 in options) {
_local11[_local15] = options[_local15];
}
var _local6 = new LocalConnection();
var _local16 = ["", Math.floor(new Date().getTime()), random(999999)].join("_");
_local6.mc = _local17;
_local6.name = _local16;
_local6.allowDomain = function (d) {
return(true);
};
_local6.allowInsecureDomain = _local6.allowDomain;
_local6.connect(_local16);
_local17.lc = _local6;
_local11.lc = _local16;
_local6._id = 0;
_local6._queue = [];
_local6.rpcResult = function (cb_arg) {
var _local8 = parseInt(cb_arg);
var _local4 = this._callbacks[_local8];
if (!_local4) {
return(undefined);
}
delete this._callbacks[_local8];
var _local5 = [];
var _local3 = 2;
while (_local3 < _local4.length) {
_local5.push(_local4[_local3]);
_local3++;
}
_local3 = 1;
while (_local3 < arguments.length) {
_local5.push(arguments[_local3]);
_local3++;
}
var _local6 = _local4[1];
var _local7 = _local4[0];
if (_local7 && (typeof(_local6) == "string")) {
_local6 = _local7[_local6];
}
if (_local6) {
_local6.apply(_local7, _local5);
}
};
_local6._didConnect = function (endpoint) {
this._endpoint = endpoint;
var _local4 = this._queue;
delete this._queue;
var _local5 = this.doSend;
var _local2 = 0;
while (_local2 < _local4.length) {
var _local3 = _local4[_local2];
_local5.apply(this, _local3);
_local2++;
}
};
_local6.doSend = function (args, cbobj, cbfn) {
if (this._endpoint == null) {
var _local4 = [];
var _local3 = 0;
while (_local3 < arguments.length) {
_local4.push(arguments[_local3]);
_local3++;
}
this._queue.push(_local4);
return(undefined);
}
this._id = this._id + 1;
var _local5 = this._id;
if ((cbfn === undefined) || (cbfn === null)) {
cbfn = cbobj;
}
this._callbacks[_local5] = [cbobj, cbfn];
var _local7 = new LocalConnection();
var _local9 = _local7.send(this._endpoint, "rpc", _local5, args);
};
_local6._callbacks = {};
_local6._callbacks[0] = [_local6, "_didConnect"];
_local11.st = getTimer();
_local11.loadMovie(_local21 + ".swf", "POST");
return(_local6);
}, fetchHighScores:function (options, callbackObj, callbackMethod) {
var _local1 = MochiAd._loadCommunicator({id:options.id});
if (!_local1) {
return(false);
}
var _local4 = ["fetchHighScores", options];
_local1.doSend(["fetchHighScores", options], callbackObj, callbackMethod);
return(true);
}, sendHighScore:function (options, callbackObj, callbackMethod) {
var _local1 = MochiAd._loadCommunicator({id:options.id});
if (!_local1) {
return(false);
}
var _local4 = ["sendHighScore", options];
_local1.doSend(["sendHighScore", options], callbackObj, callbackMethod);
return(true);
}, load:function (options) {
var _local13 = {clip:_root, server:"http://x.mochiads.com/srv/1/", method:"load", depth:10333, id:"_UNKNOWN_"};
options = MochiAd._parseOptions(options, _local13);
options.swfv = options.clip.getSWFVersion() || 6;
options.mav = MochiAd.getVersion();
var _local9 = options.clip;
if (!MochiAd._isNetworkAvailable()) {
return(null);
}
if (_local9._mochiad_loaded) {
return(null);
}
var _local12 = options.depth;
delete options.depth;
var _local6 = _local9.createEmptyMovieClip("_mochiad", _local12);
var _local11 = MochiAd._getRes(options);
options.res = (_local11[0] + "x") + _local11[1];
options.server = options.server + options.id;
delete options.id;
_local9._mochiad_loaded = true;
var _local4 = _local6.createEmptyMovieClip("_mochiad_ctr", 1);
for (var _local7 in options) {
_local4[_local7] = options[_local7];
}
var _local10 = _local4.server;
delete _local4.server;
var _local14 = MochiAd._allowDomains(_local10);
_local6.onEnterFrame = function () {
if (this._mochiad_ctr._url != this._url) {
this.onEnterFrame = function () {
if (!this._mochiad_ctr) {
delete this.onEnterFrame;
MochiAd.unload(this._parent);
}
};
}
};
var _local5 = new LocalConnection();
var _local8 = ["", Math.floor(new Date().getTime()), random(999999)].join("_");
_local5.mc = _local6;
_local5.name = _local8;
_local5.hostname = _local14;
_local5.allowDomain = function (d) {
return(true);
};
_local5.allowInsecureDomain = _local5.allowDomain;
_local5.connect(_local8);
_local6.lc = _local5;
_local4.lc = _local8;
_local4.st = getTimer();
_local4.loadMovie(_local10 + ".swf", "POST");
return(_local6);
}, unload:function (clip) {
if (typeof(clip) == "undefined") {
clip = _root;
}
if (clip.clip && (clip.clip._mochiad)) {
clip = clip.clip;
}
if (!clip._mochiad) {
return(false);
}
clip._mochiad.removeMovieClip();
delete clip._mochiad_loaded;
delete clip._mochiad;
return(true);
}, _isNetworkAvailable:function () {
if (System.security) {
var _local1 = System.security;
if (_local1.sandboxType == "localWithFile") {
return(false);
}
}
return(true);
}, _getRes:function (options) {
var _local3 = options.clip.getBounds();
var _local2 = 0;
var _local1 = 0;
if (typeof(options.res) != "undefined") {
var _local4 = options.res.split("x");
_local2 = parseFloat(_local4[0]);
_local1 = parseFloat(_local4[1]);
} else {
_local2 = _local3.xMax - _local3.xMin;
_local1 = _local3.yMax - _local3.yMin;
}
if ((_local2 == 0) || (_local1 == 0)) {
_local2 = Stage.width;
_local1 = Stage.height;
}
return([_local2, _local1]);
}, _parseOptions:function (options, defaults) {
var _local4 = {};
for (var _local8 in defaults) {
_local4[_local8] = defaults[_local8];
}
if (options) {
for (var _local8 in options) {
_local4[_local8] = options[_local8];
}
}
if (_root.mochiad_options) {
var _local5 = _root.mochiad_options.split("&");
var _local2 = 0;
while (_local2 < _local5.length) {
var _local3 = _local5[_local2].split("=");
_local4[unescape(_local3[0])] = unescape(_local3[1]);
_local2++;
}
}
if (_local4.id == "test") {
trace("[MochiAd] WARNING: Using the MochiAds test identifier, make sure to use the code from your dashboard, not this example!");
}
return(_local4);
}, _:null};
MochiAd.showPreGameAd({id:"4f5e07523a0273a5", res:"640x480"});
Frame 2
_global.preloader();
Frame 21
function checkStage() {
rowBonus = 0;
row = 19;
while (row >= 0) {
if (((((((((_global.stage_array[row][0] && (_global.stage_array[row][1])) && (_global.stage_array[row][2])) && (_global.stage_array[row][3])) && (_global.stage_array[row][4])) && (_global.stage_array[row][5])) && (_global.stage_array[row][6])) && (_global.stage_array[row][7])) && (_global.stage_array[row][8])) && (_global.stage_array[row][9])) {
_global.score = _global.score + 10;
_global.clearedLines++;
rowBonus++;
inCol = 0;
while (inCol < 10) {
mainWindow_mc[(("tile" + row.toString()) + "|") + inCol.toString()].removeMovieClip();
inCol++;
}
inRow = row;
while (inRow >= 0) {
inCol = 0;
while (inCol < 10) {
_global.stage_array[inRow][inCol] = _global.stage_array[inRow - 1][inCol];
if (_global.stage_array[inRow - 1][inCol]) {
mainWindow_mc.attachMovie("tile" + mainWindow_mc[(("tile" + (inRow - 1).toString()) + "|") + inCol.toString()].saveColor, (("tile" + inRow.toString()) + "|") + inCol.toString(), _global.depth++);
mainWindow_mc[(("tile" + inRow.toString()) + "|") + inCol.toString()].saveColor = mainWindow_mc[(("tile" + (inRow - 1).toString()) + "|") + inCol.toString()].saveColor;
mainWindow_mc[(("tile" + inRow.toString()) + "|") + inCol.toString()]._x = mainWindow_mc[(("tile" + (inRow - 1).toString()) + "|") + inCol.toString()]._x;
mainWindow_mc[(("tile" + inRow.toString()) + "|") + inCol.toString()]._y = mainWindow_mc[(("tile" + (inRow - 1).toString()) + "|") + inCol.toString()]._y + 20;
mainWindow_mc[(("tile" + (inRow - 1).toString()) + "|") + inCol.toString()].removeMovieClip();
}
inCol++;
}
inRow--;
}
col = 0;
while (col < 10) {
_global.stage_array[0][col] = 0;
col++;
}
row++;
}
row--;
}
if (rowBonus > 1) {
_global.score = _global.score + (rowBonus * 5);
}
if (rowBonus == 1) {
line1_sound.start();
} else if (rowBonus == 2) {
line2_sound.start();
} else if (rowBonus == 3) {
line3_sound.start();
} else if (rowBonus == 4) {
line4_sound.start();
}
}
function changePiece() {
if (_global.currentPiece != null) {
pieces[_global.currentPiece].setNext();
change_sound.start();
for (piece in mainWindow_mc) {
if (piece.toString().substr(0, 5) == "piece") {
mainWindow_mc[piece].removeMovieClip();
}
}
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
if (pieces[_global.currentPiece].getArray()[row][col]) {
mainWindow_mc.attachMovie("tile" + _global.lastColor, (("piece" + row.toString()) + "|") + col.toString(), _global.depth++);
mainWindow_mc[(("piece" + row.toString()) + "|") + col.toString()].saveColor = pieceColor;
mainWindow_mc[(("piece" + row.toString()) + "|") + col.toString()]._x = (col + _global.currentPiece_col) * 20;
mainWindow_mc[(("piece" + row.toString()) + "|") + col.toString()]._y = (row + _global.currentPiece_row) * 20;
}
col++;
}
row++;
}
}
updateHelpBar();
}
function drawPiece(moveDiag) {
if (_global.currentPiece == null) {
if (_global.nextPiece == null) {
_global.currentPiece = Math.floor(Math.random() * 7);
_global.nextPiece = Math.floor(Math.random() * 7);
pieceColor = Number(Math.floor(Math.random() * 5) + 1);
_global.lastColor = pieceColor;
do {
_global.nextPieceColor = Number(Math.floor(Math.random() * 5) + 1);
} while (_global.nextPieceColor == pieceColor);
updatePreview();
} else {
_global.currentPiece = _global.nextPiece;
pieceColor = (_global.lastColor = _global.nextPieceColor);
_global.nextPiece = Math.floor(Math.random() * 7);
do {
_global.nextPieceColor = Number(Math.floor(Math.random() * 5) + 1);
} while (_global.nextPieceColor == pieceColor);
updatePreview();
}
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
if (pieces[_global.currentPiece].getArray()[row][col] && (_global.stage_array[_global.currentPiece_row + row][_global.currentPiece_col + col])) {
_global.runGame = false;
_global.gameOver = true;
showGameOverWindow();
}
col++;
}
row++;
}
if (_global.runGame) {
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
if (pieces[_global.currentPiece].getArray()[row][col]) {
mainWindow_mc.attachMovie("tile" + pieceColor, (("piece" + row.toString()) + "|") + col.toString(), _global.depth++);
mainWindow_mc[(("piece" + row.toString()) + "|") + col.toString()].saveColor = pieceColor;
mainWindow_mc[(("piece" + row.toString()) + "|") + col.toString()]._x = (col + _global.currentPiece_col) * 20;
mainWindow_mc[(("piece" + row.toString()) + "|") + col.toString()]._y = (row + _global.currentPiece_row) * 20;
}
col++;
}
row++;
}
updateHelpBar();
}
} else if ((_global.speedCnt >= _global.speed) || (moveDiag)) {
if (moveDownCheck()) {
if (!moveDiag) {
_global.currentPiece_row++;
_global.speedCnt = 0;
}
for (piece in mainWindow_mc) {
if (piece.toString().substr(0, 5) == "piece") {
mainWindow_mc[piece]._x = (Number(piece.toString().substr(7, 1)) * 20) + (_global.currentPiece_col * 20);
mainWindow_mc[piece]._y = (Number(piece.toString().substr(5, 1)) * 20) + (_global.currentPiece_row * 20);
}
}
} else {
_global.score = _global.score + 2;
drop_sound.start();
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
if (pieces[_global.currentPiece].getArray()[row][col]) {
_global.stage_array[_global.currentPiece_row + row][col + _global.currentPiece_col] = pieces[_global.currentPiece].getArray()[row][col];
}
col++;
}
row++;
}
for (piece in mainWindow_mc) {
if (piece.toString().substr(0, 5) == "piece") {
mainWindow_mc[piece]._x = (Number(piece.toString().substr(7, 1)) * 20) + (_global.currentPiece_col * 20);
mainWindow_mc[piece]._y = (Number(piece.toString().substr(5, 1)) * 20) + (_global.currentPiece_row * 20);
}
}
_global.currentPiece = null;
_global.currentPiece_row = 0;
_global.currentPiece_col = 4;
for (piece in mainWindow_mc) {
if (piece.toString().substr(0, 5) == "piece") {
tempRow = mainWindow_mc[piece]._y / 20;
tempCol = mainWindow_mc[piece]._x / 20;
mainWindow_mc.attachMovie("tile" + mainWindow_mc[piece].saveColor, (("tile" + tempRow) + "|") + tempCol, _global.depth++);
mainWindow_mc[(("tile" + tempRow) + "|") + tempCol]._x = mainWindow_mc[piece]._x;
mainWindow_mc[(("tile" + tempRow) + "|") + tempCol]._y = mainWindow_mc[piece]._y;
mainWindow_mc[(("tile" + tempRow) + "|") + tempCol].saveColor = mainWindow_mc[piece].saveColor;
mainWindow_mc[piece].removeMovieClip();
}
}
updateHelpBar();
}
} else {
_global.speedCnt++;
}
}
function updateHelpBar() {
farCol = 0;
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
if (pieces[_global.currentPiece].getArray()[row][col] && (farCol < col)) {
farCol = col;
}
col++;
}
row++;
}
helpBarWindow_mc.helpBar_mc._x = _global.currentPiece_col * 20;
helpBarWindow_mc.helpBar_mc._width = (farCol + 1) * 20;
}
function updatePreview() {
for (piece_mc in previewWindow_mc) {
previewWindow_mc[piece_mc].removeMovieClip();
}
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
if (pieces[_global.nextPiece].getArray()[row][col]) {
previewWindow_mc.attachMovie("tile" + _global.nextPieceColor, (("piece" + row.toString()) + "|") + col.toString(), _global.depth++);
previewWindow_mc[(("piece" + row.toString()) + "|") + col.toString()].saveColor = pieceColor;
previewWindow_mc[(("piece" + row.toString()) + "|") + col.toString()]._x = col * 20;
previewWindow_mc[(("piece" + row.toString()) + "|") + col.toString()]._y = row * 20;
}
col++;
}
row++;
}
}
function dropPiece() {
while (moveDownCheck()) {
_global.currentPiece_row++;
for (piece in mainWindow_mc) {
if (piece.toString().substr(0, 5) == "piece") {
mainWindow_mc[piece]._x = (Number(piece.toString().substr(7, 1)) * 20) + (_global.currentPiece_col * 20);
mainWindow_mc[piece]._y = (Number(piece.toString().substr(5, 1)) * 20) + (_global.currentPiece_row * 20);
}
}
}
_global.speedCnt = 0;
drawPiece();
}
function moveDownCheck() {
var _local2 = true;
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
if ((pieces[_global.currentPiece].getArray()[row][col] && (_global.stage_array[(_global.currentPiece_row + row) + 1][col + _global.currentPiece_col])) || (pieces[_global.currentPiece].getArray()[row][col] && (((_global.currentPiece_row + row) + 1) >= 20))) {
_local2 = false;
}
col++;
}
row++;
}
return(_local2);
}
function moveLeftCheck() {
var _local2 = true;
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
if ((pieces[_global.currentPiece].getArray()[row][col] && (_global.stage_array[_global.currentPiece_row + row][(col + _global.currentPiece_col) - 1])) || (_global.currentPiece_col <= 0)) {
_local2 = false;
}
col++;
}
row++;
}
return(_local2);
}
function moveRightCheck() {
var _local2 = true;
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
if ((pieces[_global.currentPiece].getArray()[row][col] && (_global.stage_array[_global.currentPiece_row + row][(col + _global.currentPiece_col) + 1])) || (pieces[_global.currentPiece].getArray()[row][col] && (((col + _global.currentPiece_col) + 1) > 9))) {
_local2 = false;
}
col++;
}
row++;
}
return(_local2);
}
function pauseGame() {
if ((_global.currentPiece != null) && (!_global.gameOver)) {
_global.runGame = !_global.runGame;
pause_sound.start();
if (_global.runGame) {
stage_mc.pauseSign_mc.removeMovieClip();
} else {
stage_mc.attachMovie("pauseSign", "pauseSign_mc", depth++);
stage_mc.pauseSign_mc._x = 275;
stage_mc.pauseSign_mc._y = 200;
}
}
}
function playMusic() {
stage_mc.title_mc.removeMovieClip();
stage_mc.attachMovie("title" + _global.currentMusic, "title_mc", depth++);
stage_mc.title_mc._x = 12;
stage_mc.title_mc._y = 420;
if (_global.currentMusic == 1) {
music1_sound.start();
music1_sound.onSoundComplete = function () {
music1_sound.start();
};
} else if (_global.currentMusic == 2) {
music2_sound.start();
music2_sound.onSoundComplete = function () {
music2_sound.start();
};
} else if (_global.currentMusic == 3) {
music3_sound.start();
music3_sound.onSoundComplete = function () {
music3_sound.start();
};
}
}
function showGameOverWindow() {
if (!_global.windowUp) {
stage_mc.attachMovie("gameOverWindow", "gameOverWindow_mc", depth++);
stage_mc.gameOverWindow_mc._x = 175;
stage_mc.gameOverWindow_mc._y = 100;
_global.windowUp = true;
}
}
function stopMusic() {
if (_global.currentMusic == 1) {
music1_sound.stop("music1.wav");
} else if (_global.currentMusic == 2) {
music2_sound.stop("music2.wav");
} else if (_global.currentMusic == 3) {
music3_sound.stop("music3.wav");
}
}
_global.highScoresScript = "http://www.unf.edu/~voli0001/flash/tetris/tetris.php";
change_sound = new Sound();
change_sound.attachSound("change.wav");
drop_sound = new Sound();
drop_sound.attachSound("drop.wav");
pause_sound = new Sound();
pause_sound.attachSound("pause.wav");
start_sound = new Sound();
start_sound.attachSound("start.wav");
levelUp_sound = new Sound();
levelUp_sound.attachSound("levelUp.wav");
line1_sound = new Sound();
line1_sound.attachSound("line1.wav");
line2_sound = new Sound();
line2_sound.attachSound("line2.wav");
line3_sound = new Sound();
line3_sound.attachSound("line3.wav");
line4_sound = new Sound();
line4_sound.attachSound("line4.wav");
music1_sound = new Sound();
music1_sound.attachSound("music1.wav");
music2_sound = new Sound();
music2_sound.attachSound("music2.wav");
music3_sound = new Sound();
music3_sound.attachSound("music3.wav");
_global.currentMusic = 2;
_global.depth = 0;
_global.runGame = false;
_global.gameOver = false;
_global.score = 0;
_global.level = 0;
_global.levelChange = 20;
_global.clearedLines = 0;
_global.speed = 18;
_global.speedCnt = 0;
_global.currentPiece = null;
_global.nextPiece = null;
_global.nextPieceColor = 0;
_global.currentPiece_row = 0;
_global.currentPiece_col = 4;
_global.lastColor = 0;
_global.windowUp = false;
_global.stage_array = new Array();
_global.stage_array = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
Piece = function (newPiece) {
this.piece_array = newPiece;
};
Piece.prototype.setNext = function () {
temp_array = new Array();
temp_array = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
temp_array[col][3 - row] = this.piece_array[row][col];
col++;
}
row++;
}
this.piece_array = temp_array;
while (!(((this.piece_array[0][0] || (this.piece_array[1][0])) || (this.piece_array[2][0])) || (this.piece_array[3][0]))) {
row = 0;
while (row < 4) {
col = 1;
while (col < 4) {
this.piece_array[row][col - 1] = this.piece_array[row][col];
col++;
}
row++;
}
this.piece_array[0][3] = 0;
this.piece_array[1][3] = 0;
this.piece_array[2][3] = 0;
this.piece_array[3][3] = 0;
}
};
Piece.prototype.testNext = function () {
returnBool = true;
temp_array = new Array();
temp_array = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
temp_array[col][3 - row] = this.piece_array[row][col];
col++;
}
row++;
}
while (!(((temp_array[0][0] || (temp_array[1][0])) || (temp_array[2][0])) || (temp_array[3][0]))) {
row = 0;
while (row < 4) {
col = 1;
while (col < 4) {
temp_array[row][col - 1] = temp_array[row][col];
col++;
}
row++;
}
temp_array[0][3] = 0;
temp_array[1][3] = 0;
temp_array[2][3] = 0;
temp_array[3][3] = 0;
}
row = 0;
while (row < 4) {
col = 0;
while (col < 4) {
if (((temp_array[row][col] && (_global.stage_array[row + _global.currentPiece_row][col + _global.currentPiece_col])) || (temp_array[row][col] && ((col + _global.currentPiece_col) > 9))) || (temp_array[row][col] && ((row + _global.currentPiece_row) > 19))) {
returnBool = false;
}
col++;
}
row++;
}
return(returnBool);
};
Piece.prototype.getArray = function () {
return(this.piece_array);
};
pieces = new Array();
pieces.push(new Piece([[1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]));
pieces.push(new Piece([[1, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]]));
pieces.push(new Piece([[0, 0, 1, 0], [1, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]]));
pieces.push(new Piece([[0, 1, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]]));
pieces.push(new Piece([[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]));
pieces.push(new Piece([[1, 0, 0, 0], [1, 1, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0]]));
pieces.push(new Piece([[0, 1, 0, 0], [1, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0]]));
keyListener = new Object();
keyListener.onKeyDown = function () {
if (_global.runGame && (_global.currentPiece != null)) {
if (Key.isDown(37)) {
if (moveLeftCheck()) {
_global.currentPiece_col--;
}
drawPiece(true);
updateHelpBar();
} else if (Key.isDown(39)) {
if (moveRightCheck()) {
_global.currentPiece_col++;
}
drawPiece(true);
updateHelpBar();
} else if (Key.isDown(38)) {
if (pieces[_global.currentPiece].testNext()) {
changePiece();
}
} else if (Key.isDown(40)) {
dropPiece();
}
}
};
Key.addListener(keyListener);
playMusic();
stage_mc.createEmptyMovieClip("scoreWindow_mc", depth++);
stage_mc.scoreWindow_mc._x = 105;
stage_mc.scoreWindow_mc._y = 182;
stage_mc.scoreWindow_mc.score = -1;
stage_mc.createEmptyMovieClip("levelWindow_mc", depth++);
stage_mc.levelWindow_mc._x = 20;
stage_mc.levelWindow_mc._y = 182;
stage_mc.scoreWindow_mc.onEnterFrame = function () {
if (stage_mc.scoreWindow_mc.score < _global.score) {
stage_mc.scoreWindow_mc.score++;
for (num in stage_mc.scoreWindow_mc) {
stage_mc.scoreWindow_mc[num].removeMovieClip();
}
newNumString = "000000".concat(stage_mc.scoreWindow_mc.score.toString()).substring(stage_mc.scoreWindow_mc.score.toString().length + 1, stage_mc.scoreWindow_mc.score.toString().length + 6);
pos = 0;
while (pos < newNumString.length) {
stage_mc.scoreWindow_mc.attachMovie("num" + newNumString.substr(pos, 1), "num" + pos, depth++);
stage_mc.scoreWindow_mc["num" + pos]._x = pos * 25;
stage_mc.scoreWindow_mc["num" + pos]._y = 0;
pos++;
}
if ((_global.clearedLines >= _global.levelChange) || (_global.level == 0)) {
for (num in stage_mc.levelWindow_mc) {
stage_mc.levelWindow_mc[num].removeMovieClip();
}
_global.level++;
if (_global.level != 1) {
levelUp_sound.start();
}
_global.clearedLines = 0;
if (_global.speed >= 0) {
_global.speed--;
}
newNumString = "00".concat(_global.level.toString()).substring(_global.level.toString().length, _global.level.toString().length + 2);
pos = 0;
while (pos < newNumString.length) {
stage_mc.levelWindow_mc.attachMovie("num" + newNumString.substr(pos, 1), "num" + pos, depth++);
stage_mc.levelWindow_mc["num" + pos]._x = pos * 25;
stage_mc.levelWindow_mc["num" + pos]._y = 0;
pos++;
}
}
}
};
stage_mc.pauseGame_btn.onPress = function () {
if (!_global.windowUp) {
pauseGame();
}
};
stage_mc.pause_mc.onPress = function () {
stopMusic();
};
stage_mc.play_mc.onPress = function () {
playMusic();
};
stage_mc.ff_mc.onPress = function () {
stopMusic();
if ((++_global.currentMusic) > 3) {
_global.currentMusic = 1;
}
playMusic();
};
stage_mc.rewind_mc.onPress = function () {
stopMusic();
if ((--_global.currentMusic) < 1) {
_global.currentMusic = 3;
}
playMusic();
};
stage_mc.highScores_btn.onPress = function () {
if (_global.runGame) {
pauseGame();
}
if (!_global.windowUp) {
stage_mc.attachMovie("highScoresWindow", "highScoresWindow_mc", depth++);
stage_mc.highScoresWindow_mc._x = 175;
stage_mc.highScoresWindow_mc._y = 100;
_global.windowUp = true;
}
};
stage_mc.newGame_btn.onPress = function () {
if (!_global.windowUp) {
start_sound.start();
_global.runGame = true;
_global.gameOver = false;
_global.score = 0;
_global.level = 0;
_global.clearedLines = 0;
_global.speed = 18;
_global.speedCnt = 0;
stage_mc.scoreWindow_mc.score = -1;
for (piece in mainWindow_mc) {
mainWindow_mc[piece].removeMovieClip();
}
_global.currentPiece = null;
_global.currentPiece_row = 0;
_global.currentPiece_col = 4;
stage_mc.pauseSign_mc.removeMovieClip();
_global.stage_array = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
}
};
stage_mc.onEnterFrame = function () {
if (_global.runGame) {
checkStage();
drawPiece();
}
};
Symbol 56 MovieClip [gameOverWindow] Frame 1
function order(a, b) {
if (Number(a.score) < Number(b.score)) {
return(-1);
}
if (Number(a.score) > Number(b.score)) {
return(1);
}
return(0);
}
gameOver_mc = this;
depth = 0;
dataSender = new LoadVars();
dataReceiver = new LoadVars();
dataReceiver.onLoad = function () {
gameOver_mc.gotoAndStop("loaded");
gameOver_mc.highScores_array = new Array();
gameOver_mc.highScores_array.push({name:this.name1, score:this.score1});
gameOver_mc.highScores_array.push({name:this.name2, score:this.score2});
gameOver_mc.highScores_array.push({name:this.name3, score:this.score3});
gameOver_mc.highScores_array.push({name:this.name4, score:this.score4});
gameOver_mc.highScores_array.push({name:this.name5, score:this.score5});
gameOver_mc.highScores_array.push({name:"enter your name", score:_global.score});
gameOver_mc.highScores_array.sort(order);
if (gameOver_mc.highScores_array[0].name != "enter your name") {
gameOver_mc.desc = "Congratulations! You have reached a high score!";
gameOver_mc.attachMovie("newName", "inName_mc", depth++);
gameOver_mc.inName_mc._x = 45;
gameOver_mc.inName_mc._y = 145;
gameOver_mc.inName_mc.inName = "enter your name";
Selection.setFocus("gameOver_mc.inName_mc.inName_txt");
} else {
gameOver_mc.desc = "Good try, but you did not get a high score.";
gameOver_mc.gotoAndStop("lowScore");
}
};
dataSender.cacheKiller = new Date().getTime();
dataSender.action = "getScores";
dataSender.sendAndLoad(_global.highScoresScript, dataReceiver, "GET");
gameOver_mc.gotoAndStop("loading");
Symbol 56 MovieClip [gameOverWindow] Frame 5
dataSender = new LoadVars();
dataReceiver = new LoadVars();
dataReceiver.onLoad = function () {
_global.windowUp = false;
gameOver_mc.removeMovieClip();
};
gameOver_mc.save_btn.onRelease = function () {
counter = 1;
while (counter <= 5) {
if (gameOver_mc.highScores_array[counter].name == "enter your name") {
if (gameOver_mc.inName_mc.inName == "enter your name") {
gameOver_mc.highScores_array[counter].name = "Anonymous";
} else {
gameOver_mc.highScores_array[counter].name = gameOver_mc.inName_mc.inName;
}
}
counter++;
}
dataSender.cacheKiller = new Date().getTime();
dataSender.action = "saveScores";
dataSender.name1 = gameOver_mc.highScores_array[5].name;
dataSender.name2 = gameOver_mc.highScores_array[4].name;
dataSender.name3 = gameOver_mc.highScores_array[3].name;
dataSender.name4 = gameOver_mc.highScores_array[2].name;
dataSender.name5 = gameOver_mc.highScores_array[1].name;
dataSender.score1 = gameOver_mc.highScores_array[5].score;
dataSender.score2 = gameOver_mc.highScores_array[4].score;
dataSender.score3 = gameOver_mc.highScores_array[3].score;
dataSender.score4 = gameOver_mc.highScores_array[2].score;
dataSender.score5 = gameOver_mc.highScores_array[1].score;
dataSender.sendAndLoad(_global.highScoresScript, dataReceiver, "GET");
gameOver_mc.gotoAndStop("saving");
};
stop();
Symbol 56 MovieClip [gameOverWindow] Frame 15
gameOver_mc.close_btn.onRelease = function () {
_global.windowUp = false;
gameOver_mc.removeMovieClip();
};
Symbol 73 MovieClip [highScoresWindow] Frame 1
highScores_mc = this;
highScores_mc.close_btn.onRelease = function () {
_global.windowUp = false;
highScores_mc.removeMovieClip();
};
dataSender = new LoadVars();
dataReceiver = new LoadVars();
dataReceiver.onLoad = function () {
highScores_mc.gotoAndStop("loaded");
highScores_mc.name1 = this.name1;
highScores_mc.name2 = this.name2;
highScores_mc.name3 = this.name3;
highScores_mc.name4 = this.name4;
highScores_mc.name5 = this.name5;
highScores_mc.score1 = this.score1;
highScores_mc.score2 = this.score2;
highScores_mc.score3 = this.score3;
highScores_mc.score4 = this.score4;
highScores_mc.score5 = this.score5;
};
dataSender.cacheKiller = new Date().getTime();
dataSender.action = "getScores";
dataSender.sendAndLoad(_global.highScoresScript, dataReceiver, "GET");
highScores_mc.gotoAndStop("loading");