Frame 1
this.createEmptyMovieClip("lp", 999);
lp.loop = new Sound(lp);
lp.loop.attachSound("loop");
lp.loop.onSoundComplete = function () {
_root.startBtn.gotoAndPlay(1);
this.start();
};
lp.loop.start();
blocks = [[[[0, 1, 0], [1, 1, 1], [0, 0, 0]], [[0, 1, 0], [0, 1, 1], [0, 1, 0]], [[0, 0, 0], [1, 1, 1], [0, 1, 0]], [[0, 1, 0], [1, 1, 0], [0, 1, 0]]], [[[0, 1, 0], [0, 1, 0], [1, 1, 0]], [[1, 0, 0], [1, 1, 1], [0, 0, 0]], [[0, 1, 1], [0, 1, 0], [0, 1, 0]], [[0, 0, 0], [1, 1, 1], [0, 0, 1]]], [[[0, 1, 0], [0, 1, 0], [0, 1, 1]], [[0, 0, 0], [1, 1, 1], [1, 0, 0]], [[1, 1, 0], [0, 1, 0], [0, 1, 0]], [[0, 0, 1], [1, 1, 1], [0, 0, 0]]], [[[0, 0, 0], [0, 1, 1], [1, 1, 0]], [[1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1, 1], [1, 1, 0], [0, 0, 0]], [[0, 1, 0], [0, 1, 1], [0, 0, 1]]], [[[0, 0, 0], [1, 1, 0], [0, 1, 1]], [[0, 1, 0], [1, 1, 0], [1, 0, 0]], [[1, 1, 0], [0, 1, 1], [0, 0, 0]], [[0, 0, 1], [0, 1, 1], [0, 1, 0]]], [[[1, 1], [1, 1]], [[1, 1], [1, 1]], [[1, 1], [1, 1]], [[1, 1], [1, 1]]], [[[0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]], [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0]], [[0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]]]];
goMC = this.createEmptyMovieClip("goMC_", 100);
goMC.s = new Sound(goMC);
goMC.s.attachSound("go");
rotateMC = this.createEmptyMovieClip("rotateMC_", 101);
rotateMC.s = new Sound(rotateMC);
rotateMC.s.attachSound("rotate");
rotateMC.s.setVolume(10);
fullMC = this.createEmptyMovieClip("fullMC_", 102);
fullMC.s = new Sound(fullMC);
fullMC.s.attachSound("full");
Screen = function (tetris) {
this.tetris = tetris;
this.colors = [{top:11195581, front:5415542, right:1650723, left:2839870}, {top:14080449, front:10068581, right:3027230, left:5330484}, {top:14443609, front:10694179, right:3149323, left:5642515}, {top:8228036, front:4214925, right:1251369, left:2239050}, {top:14124465, front:11024244, right:3281187, left:5840189}, {top:13556161, front:8888933, right:3228464, left:4675124}, {top:15851150, front:14267419, right:2699550, left:7495439}];
this.tetris.colors = this.colors;
this.fieldsize = 20;
this.gridcolor = 6776679 /* 0x676767 */;
this.loc = _root.scene;
this.init();
this.update();
};
Screen.prototype.init = function () {
var num = 0;
var x;
var y;
this.grid = [];
var k = 0;
while (k < this.tetris.rows) {
this.grid[k] = [];
var i = (this.tetris.cols - 1);
while (i > -1) {
var field = [];
x = (i * this.fieldsize) - (((this.tetris.cols - 1) / 2) * this.fieldsize);
y = (k * this.fieldsize) - (((this.tetris.rows - 1) / 2) * this.fieldsize);
field[0] = [x - (this.fieldsize / 2), 0, y - (this.fieldsize / 2)].rotate();
field[1] = [x + (this.fieldsize / 2), 0, y - (this.fieldsize / 2)].rotate();
field[2] = [x + (this.fieldsize / 2), 0, y + (this.fieldsize / 2)].rotate();
field[3] = [x - (this.fieldsize / 2), 0, y + (this.fieldsize / 2)].rotate();
field[4] = [x - (this.fieldsize / 2), -this.fieldsize, y - (this.fieldsize / 2)].rotate();
field[5] = [x + (this.fieldsize / 2), -this.fieldsize, y - (this.fieldsize / 2)].rotate();
field[6] = [x + (this.fieldsize / 2), -this.fieldsize, y + (this.fieldsize / 2)].rotate();
field[7] = [x - (this.fieldsize / 2), -this.fieldsize, y + (this.fieldsize / 2)].rotate();
field = this.to3d(field);
this.grid[k][i] = field;
i--;
}
k++;
}
};
Screen.prototype.to3d = function (field) {
var eyeAngle = 250;
var CamDist = 300;
var i = 0;
while (i < 8) {
var pers = (eyeAngle / (field[i][2] + camDist));
field[i][0] = field[i][0] * pers;
field[i][1] = field[i][1] * pers;
i++;
}
return(field);
};
Array.prototype.rotate = function () {
var xa = -150;
var ya = 15;
var rad = (Math.PI/180);
var cosYangle = Math.cos(ya * rad);
var sinYangle = Math.sin(ya * rad);
var cosXangle = Math.cos(xa * rad);
var sinXangle = Math.sin(xa * rad);
var tempz = ((this[2] * cosYangle) - (this[0] * sinYangle));
var tmpx = ((this[2] * sinYangle) + (this[0] * cosYangle));
var tmpz = (((-this[1]) * sinXangle) + (tempz * cosXangle));
var tmpy = (((-this[1]) * cosXangle) - (tempz * sinXangle));
this[0] = tmpx;
this[1] = tmpy;
this[2] = tmpz;
return(this);
};
Screen.prototype.update = function (occupied) {
var loc = this.loc;
loc.clear();
var field;
var p0x;
var p0y;
var p1x;
var p1y;
var p2x;
var p2y;
var p3x;
var p3y;
var p4x;
var p4y;
var p5x;
var p5y;
var p6x;
var p6y;
var p7x;
var p7y;
var tetris = this.tetris;
var k = 0;
while (k < tetris.currentBlock[tetris.currentRotate].length) {
var i = 0;
while (i < tetris.currentBlock[tetris.currentRotate][0].length) {
if (tetris.currentBlock[tetris.currentRotate][k][i] == 1) {
tetris.map[k + tetris.currentBlock.y][i + tetris.currentBlock.x] = this.colors[tetris.currentIndex];
}
i++;
}
k++;
}
var k = 0;
while (k < tetris.rows) {
var i = 0;
while (i < tetris.cols) {
field = this.grid[k][i];
if (tetris.map[k][i] != null) {
(p0x = field[0][0]);
(p0y = field[0][1]);
(p1x = field[1][0]);
(p1y = field[1][1]);
(p2x = field[2][0]);
(p2y = field[2][1]);
(p3x = field[3][0]);
(p3y = field[3][1]);
(p4x = field[4][0]);
(p4y = field[4][1]);
(p5x = field[5][0]);
(p5y = field[5][1]);
(p6x = field[6][0]);
(p6y = field[6][1]);
(p7x = field[7][0]);
(p7y = field[7][1]);
var z = (((p5x - p1x) * (p6y - p1y)) - ((p5y - p1y) * (p6x - p1x)));
if ((z < 0) && (tetris.map[k][i + 1] == null)) {
loc.beginFill(tetris.map[k][i].right, 100);
loc.moveTo(p2x, p2y);
loc.lineTo(p1x, p1y);
loc.lineTo(p5x, p5y);
loc.lineTo(p6x, p6y);
loc.lineTo(p2x, p2y);
loc.endFill();
}
if ((z > 0) && (tetris.map[k][i - 1] == null)) {
loc.beginFill(this.tetris.map[k][i].left);
loc.moveTo(p0x, p0y);
loc.lineTo(p3x, p3y);
loc.lineTo(p7x, p7y);
loc.lineTo(p4x, p4y);
loc.lineTo(p0x, p0y);
loc.endFill();
}
if (tetris.map[k + 1][i] == null) {
loc.beginFill(tetris.map[k][i].front, 100);
loc.moveTo(p3x, p3y);
loc.lineTo(p2x, p2y);
loc.lineTo(p6x, p6y);
loc.lineTo(p7x, p7y);
loc.lineTo(p3x, p3y);
loc.endFill();
}
loc.lineStyle();
loc.beginFill(tetris.map[k][i].top);
loc.moveTo(p4x, p4y);
loc.lineTo(p5x, p5y);
loc.lineTo(p6x, p6y);
loc.lineTo(p7x, p7y);
loc.lineTo(p4x, p4y);
loc.endFill();
}
i++;
}
k++;
}
updateAfterEvent();
if (occupied) {
return(undefined);
}
var k = 0;
while (k < tetris.currentBlock[tetris.currentRotate].length) {
var i = 0;
while (i < tetris.currentBlock[tetris.currentRotate][0].length) {
if (tetris.currentBlock[tetris.currentRotate][k][i] == 1) {
tetris.map[k + tetris.currentBlock.y][i + tetris.currentBlock.x] = null;
}
i++;
}
k++;
}
};
Tetris = function (rows, cols, blocks) {
this.rows = rows;
this.cols = cols;
this.blocks = blocks;
this.buildMap();
this.nextIndex = random(7);
this.nextRotate = random(4);
this.screen = new Screen(this);
updateAfterEvent();
};
Tetris.prototype.buildMap = function () {
this.map = [];
var k = 0;
while (k < this.rows) {
this.map[k] = [];
var i = 0;
while (i < this.cols) {
this.map[k][i] = null;
i++;
}
k++;
}
};
Tetris.prototype.createBlock = function () {
this.currentRotate = this.nextRotate;
this.currentIndex = this.nextIndex;
this.nextIndex = random(7);
this.nextRotate = random(4);
_root.display.stone._rotation = this.nextRotate * 90;
_root.display.stone.gotoAndStop(this.nextIndex + 1);
_root.display.shadow._rotation = this.nextRotate * 90;
_root.display.shadow.gotoAndStop(this.nextIndex + 1);
this.currentBlock = this.blocks[this.currentIndex];
Key.addListener(this.currentBlock);
this.currentBlock.x = 4;
this.currentBlock.y = 0;
this.currentBlock.obj = this;
this.currentBlock.onKeyDown = function () {
if (Key.isDown(39)) {
this.obj.checkMove({x:1, y:0});
} else if (Key.isDown(37)) {
this.obj.checkMove({x:-1, y:0});
}
if (Key.isDown(40)) {
clearInterval(this.obj.whileBlock);
this.obj.whileBlock = setInterval(this.obj, "checkMove", 10, {x:0, y:1});
}
if (Key.isDown(32)) {
this.obj.rotateBlock();
}
};
this.currentBlock.onKeyUp = function () {
if (Key.getCode() == 40) {
clearInterval(this.obj.whileBlock);
this.obj.whileBlock = setInterval(this.obj, "checkMove", 1000, {x:0, y:1});
}
};
this.whileBlock = setInterval(this, "checkMove", 1000, {x:0, y:1});
this.checkMove({x:0, y:0});
};
Tetris.prototype.checkMove = function (vec) {
var k = 0;
while (k < this.currentBlock[this.currentRotate].length) {
var i = 0;
while (i < this.currentBlock[this.currentRotate][0].length) {
var solid = (this.currentBlock[this.currentRotate][k][i] != 0);
var occupied = (this.map[(k + this.currentBlock.y) + vec.y][(i + this.currentBlock.x) + vec.x] != null);
var bottom = (((k + this.currentBlock.y) + vec.y) == this.rows);
var right = (((i + this.currentBlock.x) + vec.x) == this.cols);
var left = (((i + this.currentBlock.x) + vec.x) == -1);
if (((solid && (occupied)) && (vec.x == 0)) && (vec.y == 0)) {
trace("gameover");
clearInterval(this.whileBlock);
Key.removeListener(this.currentBlock);
delete _root.Game;
trace("Game noch da");
return(undefined);
}
if (solid && (right || (left))) {
return(undefined);
}
if ((solid && (occupied)) && (vec.x != 0)) {
return(undefined);
}
if (solid && (occupied || (bottom))) {
this.occupyMap();
return(undefined);
}
i++;
}
k++;
}
_root.goMC.s.setVolume(this.currentBlock.y * 2);
_root.goMC.s.start();
this.currentBlock.x = this.currentBlock.x + vec.x;
this.currentBlock.y = this.currentBlock.y + vec.y;
this.screen.update();
};
Tetris.prototype.rotateBlock = function () {
var copy = this.currentRotate;
this.currentRotate = this.currentRotate + ((this.currentRotate < 3) ? 1 : -3);
var k = 0;
while (k < this.currentBlock[this.currentRotate].length) {
var i = 0;
while (i < this.currentBlock[this.currentRotate][0].length) {
var solid = (this.currentBlock[this.currentRotate][k][i] != 0);
var occupied = (this.map[k + this.currentBlock.y][i + this.currentBlock.x] != null);
var bottom = ((k + this.currentBlock.y) == this.rows);
var right = ((i + this.currentBlock.x) == this.cols);
var left = ((i + this.currentBlock.x) == -1);
if (solid && (((right || (left)) || (occupied)) || (bottom))) {
this.currentRotate = copy;
return(undefined);
}
i++;
}
k++;
}
rotateMC.s.start();
this.screen.update();
};
Tetris.prototype.occupyMap = function () {
var k = 0;
while (k < this.currentBlock[this.currentRotate].length) {
var i = 0;
while (i < this.currentBlock[this.currentRotate][0].length) {
if (this.currentBlock[this.currentRotate][k][i] == 1) {
this.map[k + this.currentBlock.y][i + this.currentBlock.x] = this.colors[this.currentIndex];
}
i++;
}
k++;
}
clearInterval(this.whileBlock);
Key.removeListener(this.currentBlock);
this.screen.update(true);
this.checkFullLines();
this.createBlock();
};
Tetris.prototype.checkFullLines = function () {
var full;
var k = 0;
while (k < this.rows) {
full = true;
var i = 0;
while (i < this.cols) {
if (this.map[k][i] == null) {
full = false;
}
i++;
}
if (full) {
fullMC.s.start();
this.map.splice(k, 1);
var emptyLine = [];
i = 0;
while (i < this.cols) {
emptyLine[i] = null;
i++;
}
this.map.unshift(emptyLine);
}
k++;
}
};
myTetris = new Tetris(20, 10, blocks);
stop();
Instance of Symbol 24 MovieClip "display" in Frame 1
/* no clip actions */
Instance of Symbol 32 MovieClip "startBtn" in Frame 1
/* no clip actions */
Frame 7
myTetris.createBlock();
stop();
Symbol 6 MovieClip [field] Frame 1
stop();
Symbol 23 MovieClip Frame 1
stop();
Symbol 30 Button
on (press) {
_root.lp.loop.onSoundComplete = function () {
_root.play();
this.attachSound("gameloop");
delete this.onSoundComplete;
this.start(0, 9999);
};
}
Symbol 32 MovieClip Frame 1
stop();