Frame 1
stop();
linesa = 0;
scorea = 0;
musicabc = 1;
backgroundabc = 11;
rotationabc = 1;
pausedabc = 1;
highscoreabc = 0;
Frame 2
Controller = function (obj) {
var _local2 = this;
_local2.overObj = obj;
_local2.holder = Params.attachMC.createEmptyMovieClip("holder", Params.attachLevel);
var p = {x:0, y:0};
_local2.holder.localToGlobal(p);
_local2.holder._x = -p.x;
_local2.holder._y = -p.y;
var _local3 = 1;
_local2.cells = new Array();
var _loc1;
var _local1;
var _loc1 = 0;
while (_loc1 < Params.playWidth) {
_local2.cells[_loc1] = new Array();
_local1 = 0;
while (_local1 < Params.playHeight) {
_local2.cells[_loc1][_local1] = _local2.holder.attachMovie("block", "block" + _local3, _local3++);
_local2.cells[_loc1][_local1]._x = ((Params.blockSize * _loc1) + Params.playLeft) + (Params.blocksize / 2);
_local2.cells[_loc1][_local1]._y = ((Params.blockSize * _local1) + Params.playTop) + (Params.blocksize / 2);
_local1++;
}
_loc1++;
}
_local2.nextCells = new Array();
var _loc1 = 0;
while (_loc1 < 4) {
_local2.nextCells[_loc1] = Params.attachMC.attachMovie("block", "block" + _local3, _local3++);
_local2.nextCells[_loc1]._visible = false;
_loc1++;
}
_local2.game = new Tetris(_local2, Params.playWidth, Params.playHeight);
_local2.initSounds();
};
Controller.prototype.initSounds = function () {
var _local1 = this;
_local1.sounds = new Object();
_local1.sounds.vol = new Sound(_local1.holder);
_local1.sounds.lineClear = new Sound(_local1.holder);
_local1.sounds.lineClear.attachSound("lineClear");
_local1.sounds.atBottom = new Sound(_local1.holder);
_local1.sounds.atBottom.attachSound("atBottom");
};
Controller.prototype.startGame = function () {
var _local1 = this;
_local1.score = 0;
Params.scoreTextField.text = _local1.score;
_local1.clearCells();
_local1.speed = Params.startSpeed;
_local1.game.restart();
_local1.updateNext();
_local1.gamePlay();
};
Controller.prototype.resetInterval = function (interval) {
var _local1 = interval;
if (_local1 != undefined) {
clearInterval(_local1);
}
};
Controller.prototype.gamePlay = function () {
var _local1 = this;
_local1.resetInterval(_local1.playInterval);
_local1.resetInterval(_local1.keyInterval);
_local1.playInterval = setInterval(_local1, "stepGame", _local1.speed);
_local1.keyInterval = setInterval(_local1, "testKeys", _local1.speed / 5);
Key.removeListener(_local1);
Key.addListener(_local1);
};
Controller.prototype.gamePause = function () {
var _local1 = this;
_local1.resetInterval(_local1.playInterval);
_local1.resetInterval(_local1.keyInterval);
Key.removeListener(_local1);
};
Controller.prototype.soundOn = function () {
this.sounds.vol.setVolume(100);
};
Controller.prototype.soundOff = function () {
this.sounds.vol.setVolume(0);
};
Controller.prototype.onKeyDown = function () {
var _local1 = this;
switch (Key.getCode()) {
case Params.rotLeftKey :
_local1.game.rotLeft();
break;
case Params.rotRightKey :
_local1.game.rotRight();
break;
case Params.leftKey :
_local1.game.shiftLeft();
break;
case Params.rightKey :
_local1.game.shiftRight();
}
updateAfterEvent();
};
Controller.prototype.testKeys = function () {
if (Key.isDown(Params.dropKey)) {
this.game.drop();
}
};
Controller.prototype.clearCells = function () {
var _local3 = this;
var _local2;
var _local1;
_local2 = 0;
while (_local2 < Params.playWidth) {
_local1 = 0;
while (_local1 < Params.playHeight) {
_local3.cells[_local2][_local1].gotoAndStop("CLEAR0");
_local1++;
}
_local2++;
}
_local2 = 0;
while (_local2 < 4) {
_local3.nextCells[_local2]._visible = false;
_local2++;
}
};
Controller.prototype.stepGame = function () {
this.game.stepGame();
updateAfterEvent();
};
Controller.prototype.tetradMoved = function () {
};
Controller.prototype.tetradLanded = function () {
this.sounds.atBottom.start();
};
Controller.prototype.updateCells = function (update) {
var _local3 = this;
var max = update.length;
var _local2;
var _local1;
_local2 = 0;
while (_local2 < max) {
_local1 = update[_local2];
_local3.cells[_local1.x][_local1.y].gotoAndStop(_local1.s.shape + _local1.s.number);
_local3.cells[_local1.x][_local1.y]._rotation = _local1.s.rotation;
_local2++;
}
};
Controller.prototype.linesRemoved = function (numlines) {
var _local1 = this;
var _local2 = numlines;
if (_local2) {
_local1.sounds.lineClear.start(0, _local2);
_local1.score = _local1.score + (_local2 * Params.scorePerLine);
Params.scoreTextField.text = _local1.score;
_local1.speed = _local1.speed * Math.pow(Params.accelerate, _local2);
_local1.gamePlay();
}
_local1.game.newTetrad();
_local1.updateNext();
};
Controller.prototype.updateNext = function () {
var _local3 = this.game.getNextTetrad();
var minx = _local3[0].x;
var miny = _local3[0].y;
var maxx = _local3[0].x;
var maxy = _local3[0].y;
var _loc3;
for (var _loc3 in _local3) {
var _local1 = _local3[_loc3];
minx = Math.min(minx, _local1.x);
maxx = Math.max(maxx, _local1.x);
miny = Math.min(miny, _local1.y);
maxy = Math.max(maxy, _local1.y);
}
var cx = (((maxx + minx) + 1) * 0.5);
var cy = (((maxy + miny) + 1) * 0.5);
var _local2;
for (var _loc3 in _local3) {
var _local1 = _local3[_loc3];
_local2 = this.nextCells[_loc3];
_local2.gotoAndStop(_local1.s.shape + _local1.s.number);
_local2._x = (((_local1.x - cx) * Params.blockSize) + Params.nextX) + (Params.blockSize / 2);
_local2._y = (((_local1.y - cy) * Params.blockSize) + Params.nextY) + (Params.blockSize / 2);
_local2._visible = true;
}
};
Controller.prototype.gameOver = function () {
this.gamePause();
this.overObj.gameOver();
};
Tetris = function (control, width, height) {
var _local2 = this;
_local2.control = control;
_local2.width = width;
_local2.height = height;
_local2.tetradstartx = Math.floor((_local2.width - 1) / 2);
_local2.board = new Array();
var _local3;
var _local1;
_local3 = 0;
while (_local3 < _local2.width) {
_local2.board[_local3] = new Array();
_local1 = 0;
while (_local1 < _local2.height) {
_local2.board[_local3][_local1] = new CellState("CLEAR", 0, 0);
_local1++;
}
_local3++;
}
_local2.tetrad = new Tetrad(_local2);
_local2.nexttetrad = new Tetrad(_local2);
};
Tetris.prototype.reset = function () {
var _local3 = this;
var _local2;
var _local1;
_local2 = 0;
while (_local2 < _local3.width) {
_local1 = 0;
while (_local1 < _local3.height) {
_local3.board[_local2][_local1] = new CellState("CLEAR", 0, 0);
_local1++;
}
_local2++;
}
_local3.tetrad.reset();
_local3.nexttetrad.reset();
};
Tetris.prototype.restart = function () {
this.reset();
this.newTetrad();
};
Tetris.prototype.stepGame = function () {
this.drop();
};
Tetris.prototype.shiftLeft = function () {
this.tetrad.shiftLeft();
};
Tetris.prototype.shiftRight = function () {
this.tetrad.shiftRight();
};
Tetris.prototype.rotLeft = function () {
this.tetrad.rotLeft();
};
Tetris.prototype.rotRight = function () {
this.tetrad.rotRight();
};
Tetris.prototype.drop = function () {
this.tetrad.drop();
};
Tetris.prototype.getCellstate = function (x, y) {
var _local3 = this;
var _local2 = y;
var _local1 = x;
if ((((_local1 < 0) || (_local1 >= _local3.width)) || (_local2 < 0)) || (_local2 >= _local3.height)) {
return("OUT");
}
return(_local3.board[_local1][_local2].shape);
};
Tetris.prototype.getNextTetrad = function () {
var _local1 = this.nexttetrad.getCells();
var _local2 = this.nexttetrad.getShape();
var _local3;
for (_local3 in _local1) {
_local1[_local3].s.shape = _local2;
}
return(_local1);
};
Tetris.prototype.newTetrad = function () {
var _local1 = this;
_root.scorea = _root.scorea + 5;
_local1.tetrad.reset(_local1.nexttetrad.getShape());
_local1.nexttetrad.reset();
_local1.moveTetradToStart();
};
Tetris.prototype.isCellClear = function (x, y) {
var _local1 = this.getCellstate(x, y);
return((_local1 == "CLEAR") || (_local1 == "CURRENT"));
};
Tetris.prototype.moveTetradToStart = function () {
var _local1 = this;
if (!_local1.tetrad.setPos(_local1.tetradstartx, 0)) {
_local1.control.gameOver();
}
};
Tetris.prototype.removeLines = function () {
var _local1 = this;
var remove;
var linestoremove = new Array();
var _local3;
var _loc2;
var _loc2 = (_local1.height - 1);
while (_loc2 >= 0) {
remove = true;
_local3 = 0;
while (_local3 < _local1.width) {
if (_local1.isCellClear(_local3, _loc2)) {
remove = false;
break;
}
_local3++;
}
if (remove) {
linestoremove.push(_loc2);
_root.sound.gotoAndPlay(2);
_root.linesa = _root.linesa + 1;
_root.scorea = _root.scorea + 40;
}
_loc2--;
}
var numlines = linestoremove.length;
if (numlines) {
var min;
var max;
var _local2;
var update = new Array();
_local3 = 1;
while (_local3 <= numlines) {
max = linestoremove[_local3 - 1] - 1;
min = ((_local3 == numlines) ? 0 : (linestoremove[_local3] + 1));
var _loc2 = max;
while (_loc2 >= min) {
_local2 = 0;
while (_local2 < _local1.width) {
update.push({x:_local2, y:_loc2 + _local3, s:_local1.board[_local2][_loc2]});
_local2++;
}
_loc2--;
}
_local3++;
}
var _loc2 = (numlines - 1);
while (_loc2 >= 0) {
_local2 = 0;
while (_local2 < _local1.width) {
if (_local1.board[_local2][_loc2] != "CLEAR") {
update.push({x:_local2, y:_loc2, s:new CellState("CLEAR", 0, 0)});
}
_local2++;
}
_loc2--;
}
_local1.updateCells(update);
}
_local1.control.linesRemoved(numlines);
};
Tetris.prototype.updateCells = function (update) {
var _local2 = update;
var _local3 = this;
var _local1;
_local1 = 0;
while (_local1 < _local2.length) {
_local3.board[_local2[_local1].x][_local2[_local1].y] = _local2[_local1].s;
if (_local2[_local1].s.shape == "CURRENT") {
_local2[_local1].s = new CellState(_local3.tetrad.getShape(), _local2[_local1].s.number, _local2[_local1].s.rotation);
}
_local1++;
}
_local3.control.updateCells(_local2);
};
Tetris.prototype.tetradLanded = function () {
var _local2 = this;
var _local1 = _local2.tetrad.getCells();
var _local3 = _local2.tetrad.getShape();
var max = _local1.length;
var _loc2;
for (var _loc2 in _local1) {
_local1[_loc2].s.shape = _local3;
_local2.board[_local1[_loc2].x][_local1[_loc2].y] = _local1[_loc2].s;
}
_local2.control.tetradLanded();
_local2.removeLines();
};
Tetris.prototype.tetradMoved = function (update) {
this.updateCells(update);
this.control.tetradMoved();
};
Tetrad = function (game, s) {
var _local1 = this;
_local1.game = game;
_local1.points = new Array();
if (arguments.length >= 2) {
_local1.reset(s);
} else {
_local1.reset();
}
};
Tetrad.prototype.reset = function (s) {
var _local1 = this;
if (arguments.length) {
_local1.shape = s;
} else {
_local1.shape = _local1.getRandomShape();
}
_local1[_local1.shape]();
_local1.x = (_local1.y = 0);
_local1.rotation = 0;
_local1.points.length = 0;
switch (_local1.shape) {
case "I" :
_local1.points.push({x:-1, y:0}, {x:0, y:0}, {x:1, y:0}, {x:2, y:0});
return;
case "O" :
_local1.points.push({x:0, y:0}, {x:1, y:0}, {x:0, y:1}, {x:1, y:1});
return;
case "T" :
_local1.points.push({x:-1, y:0}, {x:0, y:0}, {x:1, y:0}, {x:0, y:1});
return;
case "S" :
_local1.points.push({x:0, y:0}, {x:1, y:0}, {x:-1, y:1}, {x:0, y:1});
return;
case "Z" :
_local1.points.push({x:-1, y:0}, {x:0, y:0}, {x:0, y:1}, {x:1, y:1});
return;
case "L" :
_local1.points.push({x:-1, y:0}, {x:0, y:0}, {x:1, y:0}, {x:-1, y:1});
return;
case "F" :
_local1.points.push({x:-1, y:0}, {x:0, y:0}, {x:1, y:0}, {x:1, y:1});
}
};
Tetrad.prototype.getRandomShape = function () {
return(["I", "O", "T", "Z", "S", "L", "F"][Math.floor(7 * Math.random())]);
};
Tetrad.prototype.setPos = function (x, y) {
var _local1 = this;
if (!_local1.canMoveTo(x, y, _local1.points)) {
return(false);
}
_local1.x = x;
_local1.y = y;
_local1.game.tetradMoved(_local1.getCells());
return(true);
};
Tetrad.prototype.moveTo = function (newx, newy, newpoints, newrotation) {
var _local3 = this;
if (!_local3.canMoveTo(newx, newy, newpoints)) {
return(false);
}
var _local2 = new Array();
_local2 = _local2.concat(_local3.getCells());
var _local1;
_local1 = 0;
while (_local1 < 4) {
_local2[_local1].s.shape = "CLEAR";
_local2[_local1].s.number = 0;
_local1++;
}
_local3.x = newx;
_local3.y = newy;
_local3.points = newpoints;
_local3.rotation = newrotation;
_local2 = _local2.concat(_local3.getCells());
_local3.game.tetradMoved(_local2);
return(true);
};
Tetrad.prototype.canMoveTo = function (newx, newy, newpoints) {
var _local2 = newpoints;
var _local3 = newy;
var _local1;
_local1 = 0;
while (_local1 < 4) {
if (!this.game.isCellClear(_local2[_local1].x + newx, _local2[_local1].y + _local3)) {
return(false);
}
_local1++;
}
return(true);
};
Tetrad.prototype.shiftLeft = function () {
var _local1 = this;
_local1.moveTo(_local1.x - 1, _local1.y, _local1.points, _local1.rotation);
};
Tetrad.prototype.shiftRight = function () {
var _local1 = this;
_local1.moveTo(_local1.x + 1, _local1.y, _local1.points, _local1.rotation);
};
Tetrad.prototype.rotLeft = function () {
var _local2 = this;
var _local3 = new Array();
var _local1;
if (_local2.shape != "O") {
_local1 = 0;
while (_local1 < 4) {
_local3.push({x:_local2.points[_local1].y, y:-_local2.points[_local1].x});
_local1++;
}
} else {
_local1 = 0;
while (_local1 < 4) {
_local3.push({x:_local2.points[_local1].y, y:1 - _local2.points[_local1].x});
_local1++;
}
}
_local2.moveTo(_local2.x, _local2.y, _local3, _local2.rotation - 90);
};
Tetrad.prototype.rotRight = function () {
var _local2 = this;
temp = new Array();
var _local1;
_local1 = 0;
while (_local1 < 4) {
temp.push({x:-_local2.points[_local1].y, y:_local2.points[_local1].x});
_local1++;
}
_local2.moveTo(_local2.x, _local2.y, temp, _local2.rotation + 90);
};
Tetrad.prototype.drop = function () {
var _local1 = this;
if (!_local1.moveTo(_local1.x, _local1.y + 1, _local1.points, _local1.rotation)) {
_local1.atBottom();
}
};
Tetrad.prototype.atBottom = function () {
this.game.tetradLanded();
};
Tetrad.prototype.getShape = function () {
return(this.shape);
};
Tetrad.prototype.getRotation = function () {
return(this.rotation);
};
Tetrad.prototype.getCells = function () {
var _local2 = this;
var temp = new Array();
var _local1;
_local1 = 0;
while (_local1 < 4) {
temp.push({x:_local2.x + _local2.points[_local1].x, y:_local2.y + _local2.points[_local1].y, s:new CellState("CURRENT", _local1 + 1, _local2.rotation)});
_local1++;
}
return(temp);
};
Tetrad.prototype.sortCells = function (arr) {
arr.sort(function (a, b) {
xret = a.x - b.x;
if (xret) {
return(xret);
}
return(a.y - b.y);
});
};
CellState = function (s, n, r) {
var _local1 = this;
_local1.shape = s;
_local1.number = n;
_local1.rotation = r;
};
var Params = new Object();
Params.leftKey = 37;
Params.rightKey = 39;
if (_root.rotationabc == 1) {
Params.rotLeftKey = 38;
Params.rotRightKey = 0;
} else {
Params.rotLeftKey = 0;
Params.rotRightKey = 38;
}
Params.dropKey = 40;
Params.blockSize = 19;
Params.playTop = 108;
Params.playLeft = 76;
Params.playWidth = 10;
Params.playHeight = 18;
Params.nextX = 325;
Params.nextY = 128.5;
Params.scorePerLine = 25;
Params.scoreTextField = this.score_txt;
Params.startSpeed = 400;
Params.accelerate = 0.985;
Params.attachMC = this.background_mc;
Params.attachLevel = 10;
Instance of Symbol 52 MovieClip in Frame 2
onClipEvent (load) {
this.gotoAndStop(_root.backgroundabc);
}
onClipEvent (enterFrame) {
this.gotoAndStop(_root.backgroundabc);
}
Instance of Symbol 88 MovieClip in Frame 2
onClipEvent (load) {
this.gotoAndStop(_root.musicabc);
}
onClipEvent (enterFrame) {
this.gotoAndStop(_root.musicabc);
}
Frame 3
this.gameOver = function () {
this.gotoAndStop("gameover");
};
Control = new Controller(this);
stop();
Frame 4
Control.startGame();
stop();
Instance of Symbol 120 MovieClip in Frame 4
onClipEvent (enterFrame) {
this.gotoAndStop(_root.pausedabc);
}
Frame 5
stop();
Instance of Symbol 132 MovieClip in Frame 5
onClipEvent (load) {
if (_root.scorea >= _root.highscoreabc) {
_root.highscoreabc = _root.scorea;
}
}
Frame 36
stop();
Instance of Symbol 52 MovieClip in Frame 36
onClipEvent (load) {
this.gotoAndStop(_root.backgroundabc);
}
onClipEvent (enterFrame) {
this.gotoAndStop(_root.backgroundabc);
}
Instance of Symbol 155 MovieClip in Frame 39
onClipEvent (enterFrame) {
this.gotoAndStop(_root.rotationabc);
}
Symbol 9 MovieClip [block] Frame 1
stop();
Symbol 19 MovieClip Frame 34
stop();
Symbol 23 MovieClip Frame 1
this._width = 0;
this.onEnterFrame = function () {
var _local1 = _parent;
var _local2 = _local1.getBytesTotal();
if (_local2 > 4) {
var _local3 = _local1.getBytesLoaded();
if (_local3 == _local2) {
_local1.gotoAndPlay(6);
} else {
this._width = (_local3 / _local2) * 200;
}
}
};
Symbol 52 MovieClip Frame 1
stop();
Symbol 62 Button
on (keyPress "<Space>") {
_root.pausedabc = 2;
_parent.Control.gamePause();
this.gotoAndStop("play");
}
Symbol 65 Button
on (keyPress "<Space>") {
_root.pausedabc = 1;
_parent.Control.gamePlay();
this.gotoAndStop("pause");
}
Symbol 66 MovieClip Frame 1
stop();
this.useHandCursor = true;
this.onRelease = function () {
_parent.Control.gamePause();
this.gotoAndStop("play");
};
Symbol 66 MovieClip Frame 2
stop();
this.onRelease = function () {
_parent.Control.gamePlay();
_root.pausedabc = 2;
this.gotoAndStop("pause");
};
Symbol 88 MovieClip Frame 1
stop();
stopAllSounds();
Symbol 93 Button
on (release) {
stopAllSounds();
_root.musicabc = _root.musicabc + 1;
if (_root.musicabc == 9) {
_root.musicabc = 1;
}
}
Symbol 94 Button
on (release) {
stopAllSounds();
_root.musicabc = _root.musicabc - 1;
if (_root.musicabc == 0) {
_root.musicabc = 8;
}
}
Symbol 95 Button
on (release) {
_root.backgroundabc = _root.backgroundabc + 1;
if (_root.backgroundabc == 15) {
_root.backgroundabc = 1;
}
}
Symbol 96 Button
on (release) {
_root.backgroundabc = _root.backgroundabc - 1;
if (_root.backgroundabc == 0) {
_root.backgroundabc = 14;
}
}
Symbol 103 Button
on (release) {
getURL ("http://www.imperfectsystems.net/", "_blank");
}
Symbol 104 Button
on (release) {
getURL ("http://www.myspace.com/ischris", "_blank");
}
Symbol 105 Button
on (release) {
getURL ("http://z9.invisionfree.com/Imperfect_Systems", "_blank");
}
Symbol 109 MovieClip Frame 1
stop();
this.useHandCursor = true;
this.onRelease = function () {
_root.scorea = -5;
_parent.gotoAndStop("play");
};
Symbol 113 MovieClip Frame 1
stop();
Symbol 119 MovieClip Frame 26
stop();
Symbol 120 MovieClip Frame 1
stop();
Symbol 122 MovieClip Frame 1
stop();
this.useHandCursor = true;
this.onRelease = function () {
_root.scorea = -5;
_root.linesa = 0;
_parent.gotoAndStop("play");
};
Symbol 132 MovieClip Frame 9
stop();
Symbol 139 Button
on (release) {
gotoAndStop (38);
}
Symbol 140 Button
on (release) {
stopAllSounds();
gotoAndPlay (2);
}
Symbol 146 Button
on (release) {
gotoAndStop (36);
}
Symbol 155 MovieClip Frame 1
stop();
Symbol 156 Button
on (release) {
if (_root.rotationabc == 1) {
_root.rotationabc = 2;
} else {
_root.rotationabc = 1;
}
}