Section 1
//MainTimeline (brick_fla.MainTimeline)
package brick_fla {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import tetris.*;
public dynamic class MainTimeline extends MovieClip {
public var next:MovieClip;
public var Tet:Game;
public var level:TextField;
public var playbt:SimpleButton;
public var M:MovieClip;
public var cores:Array;
public var pontuacao:TextField;
public var pecas:Array;
public function MainTimeline(){
addFrameScript(0, frame1, 1, frame2, 2, frame3, 3, frame4);
}
public function playgame(_arg1:MouseEvent){
play();
}
function frame3(){
playbt.addEventListener("click", playgame);
stop();
}
function frame1(){
if (framesLoaded == totalFrames){
gotoAndPlay(1, "menu");
};
}
function frame4(){
M = new MovieClip();
addChild(M);
pecas = [[[[1, 1], [1, 1]]], [[[0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 1, 1]]], [[[1, 0], [1, 1], [0, 1]], [[0, 0, 0], [0, 1, 1], [1, 1, 0]]], [[[0, 1], [1, 1], [1, 0]], [[0, 0, 0], [1, 1, 0], [0, 1, 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, 1, 0], [0, 1, 0], [1, 1, 0]], [[1, 0, 0], [1, 1, 1]], [[0, 1, 1], [0, 1, 0], [0, 1, 0]], [[0, 0, 0], [1, 1, 1], [0, 0, 1]]], [[[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], [1, 1, 1]]]];
cores = [65331, 16777062, 13395711, 0xFF0000];
Tet = new Game(M, pecas, cores);
Tet.setDisplays(pontuacao, level, next);
Tet.init();
stop();
}
function frame2(){
gotoAndPlay(1);
}
}
}//package brick_fla
Section 2
//next_6 (brick_fla.next_6)
package brick_fla {
import flash.display.*;
public dynamic class next_6 extends MovieClip {
public function next_6(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package brick_fla
Section 3
//againbtn (tetris.againbtn)
package tetris {
import flash.display.*;
import flash.events.*;
public class againbtn extends SimpleButton {
private var reference:Game;
public function againbtn(_arg1:Game){
this.addEventListener("click", replay);
reference = _arg1;
}
private function replay(_arg1:MouseEvent):void{
reference.retry();
}
}
}//package tetris
Section 4
//Controller (tetris.Controller)
package tetris {
import flash.display.*;
import flash.events.*;
public class Controller extends Sprite {
public var pressed:uint;
public function Controller(){
pressed = 0;
addEventListener(KeyboardEvent.KEY_DOWN, setPressed);
addEventListener(KeyboardEvent.KEY_UP, unpress);
}
public function unpress(_arg1:KeyboardEvent):void{
pressed = 0;
}
public function setPressed(_arg1:KeyboardEvent):void{
pressed = _arg1.keyCode;
}
public function update():uint{
return (pressed);
}
}
}//package tetris
Section 5
//Game (tetris.Game)
package tetris {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.geom.*;
import Tiles.*;
import flash.utils.*;
import flash.media.*;
import flash.ui.*;
public class Game {
private var current:piece;
public var level:uint;
private var Colors:Array;
private var Keys:Controller;
private var clear_count:uint;
private var Display:CircleMap;
private var next_x:uint;
private var NextDisplay:MovieClip;
private var PointDisplay:TextField;
private var cur_x;
private var cur_y:uint;
private var LevelDisplay:TextField;
private var endClip:over;
private var Holder:MovieClip;
private var clock1;
private var clock2:Timer;
private var Pieces:Array;
public var points:uint;
private var SFX:Sound;
public var next:piece;
public function Game(_arg1:MovieClip, _arg2:Array, _arg3:Array){
var _local4:Point;
super();
Pieces = _arg2;
this.Colors = _arg3;
Holder = _arg1;
_local4 = new Point(264, 264);
Display = new CircleMap(_local4, 15, 20, 250, _arg1);
Keys = new Controller();
}
public function init(){
points = 0;
level = 0;
clear_count = 0;
setNext();
addpiece();
clock1 = new Timer(100, 0);
clock2 = new Timer(600, 0);
clock1.addEventListener("timer", update);
clock2.addEventListener("timer", down);
clock1.start();
clock2.start();
Holder.addChild(Keys);
}
private function finishGame():void{
clock1.stop();
clock2.stop();
endClip = new over();
endClip.x = 168;
endClip.y = 233;
Holder.addChild(endClip);
clock1.delay = 3900;
clock1.addEventListener("timer", addAgainbtn);
clock1.start();
}
private function down(_arg1:TimerEvent):void{
var _local2:uint;
if (Display.end()){
SFX = new sfx_exp();
SFX.play();
finishGame();
} else {
if (!Display.hit(current, cur_x, cur_y, 0)){
Display.clear(current, cur_x, cur_y);
cur_y++;
Display.print(current, cur_x, cur_y);
} else {
SFX = new sfx_hit();
SFX.play(0, 0);
_local2 = 0;
Display.print(current, cur_x, cur_y);
Display.update_top(cur_y);
_local2 = Display.check_clear();
points = (points + ((_local2 * 50) * (level + 1)));
clear_count = (clear_count + _local2);
if ((((clock2.delay >= 100)) && ((clear_count >= 6)))){
level++;
SFX = new sfx_levelup();
SFX.play(0, 0);
LevelDisplay.text = level.toString(10);
clear_count = (clear_count - 6);
clock2.delay = (clock2.delay - 30);
};
PointDisplay.text = points.toString(10);
addpiece();
};
Display.draw();
};
}
public function retry():void{
Display.destroy();
Holder.removeChild(endClip);
init();
PointDisplay.text = points.toString(10);
LevelDisplay.text = level.toString(10);
}
private function addAgainbtn(_arg1:TimerEvent):void{
var _local2:againbtn;
clock1.stop();
_local2 = new againbtn(this);
_local2.x = 145;
_local2.y = 122;
endClip.addChild(_local2);
}
public function update(_arg1:TimerEvent):void{
Holder.stage.focus = Keys;
switch (Keys.pressed){
case Keyboard.DOWN:
if (!Display.hit(current, cur_x, cur_y, 0)){
SFX = new sfx_move();
SFX.play(0, 0);
Display.clear(current, cur_x, cur_y);
cur_y++;
Display.print(current, cur_x, cur_y);
Display.draw();
points++;
};
break;
case Keyboard.LEFT:
if (!Display.hit(current, cur_x, cur_y, 1)){
SFX = new sfx_move();
SFX.play(0, 0);
Display.clear(current, cur_x, cur_y);
cur_x = Display.move(cur_x, -1);
Display.print(current, cur_x, cur_y);
Display.draw();
};
break;
case Keyboard.RIGHT:
if (!Display.hit(current, cur_x, cur_y, 2)){
SFX = new sfx_move();
SFX.play(0, 0);
Display.clear(current, cur_x, cur_y);
cur_x = Display.move(cur_x, 1);
Display.print(current, cur_x, cur_y);
Display.draw();
};
break;
case Keyboard.CONTROL:
if (!Display.hitroll(current, cur_x, cur_y)){
SFX = new sfx_rot();
SFX.play(0, 0);
Display.clear(current, cur_x, cur_y);
current.rotate();
Display.print(current, cur_x, cur_y);
Display.draw();
};
};
}
private function addpiece():void{
current = next;
cur_x = next_x;
cur_y = 0;
setNext();
}
public function setDisplays(_arg1:TextField, _arg2:TextField, _arg3:MovieClip){
this.PointDisplay = _arg1;
this.LevelDisplay = _arg2;
this.NextDisplay = _arg3;
PointDisplay.text = points.toString(10);
LevelDisplay.text = level.toString(10);
}
private function setNext():void{
var _local1:uint;
var _local2:uint;
var _local3:piece;
_local1 = Math.floor((Pieces.length * Math.random()));
_local2 = Math.floor((Colors.length * Math.random()));
_local3 = new piece(Pieces[_local1], Colors[_local2]);
next = _local3;
switch (Math.floor((4 * Math.random()))){
case 0:
next_x = 0;
break;
case 1:
cur_x = 5;
break;
case 2:
cur_x = 10;
break;
case 3:
cur_x = 15;
};
NextDisplay.gotoAndStop((_local1 + 1));
}
}
}//package tetris
Section 6
//piece (tetris.piece)
package tetris {
public class piece {
private var cur:uint;
public var width:uint;
public var left;
private var rot:Array;
public var right:Array;
public var shape:Array;
public var color:uint;
public var height:uint;
public var bottom:Array;
public function piece(_arg1:Array, _arg2:uint){
rot = _arg1;
cur = 0;
color = _arg2;
shape = rot[0];
height = shape.length;
width = shape[0].length;
bottom = new Array(width);
left = new Array(height);
right = new Array(height);
calc_bounds();
}
public function extend():Boolean{
var _local1:uint;
_local1 = cur;
if (cur == (rot.length - 1)){
_local1 = 0;
} else {
_local1++;
};
return ((rot[_local1].length > rot[cur].length));
}
public function rotate():void{
cur++;
if (cur == rot.length){
cur = 0;
};
shape = rot[cur];
height = shape.length;
width = shape[0].length;
calc_bounds();
}
private function calc_bounds():void{
var _local1:int;
var _local2:int;
_local1 = 0;
while (_local1 < width) {
bottom[_local1] = -1;
_local1++;
};
_local1 = 0;
while (_local1 < height) {
left[_local1] = width;
right[_local1] = -1;
_local2 = 0;
while (_local2 < width) {
if (shape[_local1][_local2] == 1){
if (bottom[_local2] < _local1){
bottom[_local2] = _local1;
};
if (left[_local1] > _local2){
left[_local1] = _local2;
};
if (right[_local1] < _local2){
right[_local1] = _local2;
};
};
_local2++;
};
if (left[_local1] == width){
left[_local1] = -1;
};
_local1++;
};
}
public function rotateBack():void{
if (cur == 0){
cur = (rot.length - 1);
} else {
cur--;
};
shape = rot[cur];
height = shape.length;
width = shape[0].length;
calc_bounds();
}
}
}//package tetris
Section 7
//CircleMap (Tiles.CircleMap)
package Tiles {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import tetris.*;
import flash.utils.*;
import flash.media.*;
public class CircleMap {
private var width:uint;
private var Holder:MovieClip;
private var Background:Shape;
private var ClearSound:Sound;
private var top:int;
private var height:uint;
private var lock:Boolean;
private var animations:Array;
private var Map:Array;
public function CircleMap(_arg1:Point, _arg2:uint, _arg3:uint, _arg4:int, _arg5:MovieClip){
var _local6:Number;
var _local7:uint;
var _local8:uint;
var _local9:uint;
var _local10:Number;
var _local11:Number;
var _local12:uint;
var _local13:uint;
var _local14:Number;
var _local15:Number;
var _local16:uint;
super();
_local6 = ((Math.PI * 2) / _arg3);
_local7 = _arg4;
_local8 = (_local7 / _arg2);
height = _arg2;
width = _arg3;
Background = new Shape();
Map = new Array(_arg2);
_local9 = 0;
while (_local9 < _arg2) {
_local15 = 0;
Map[_local9] = new Array(_arg3);
_local14 = (_local7 * (Math.sin(_local6) / Math.cos((_local6 / 2))));
_local16 = 0;
while (_local16 < _arg3) {
_local10 = ((_local7 * Math.cos(_local15)) + _arg1.x);
_local11 = ((_local7 * Math.sin(_local15)) + _arg1.y);
Map[_local9][_local16] = new Tile(_local10, _local11, _local15, _local14);
Map[_local9][_local16].left = Map[_local9][(_local16 - 1)];
if (_local16 > 0){
Map[_local9][(_local16 - 1)].right = Map[_local9][_local16];
};
if (_local9 > 0){
Map[(_local9 - 1)][_local16].down = Map[_local9][_local16];
};
Background.graphics.lineStyle(1, 0xFFFF, 1);
Background.graphics.drawCircle(_arg1.x, _arg1.y, _local7);
_local15 = (_local15 + _local6);
_local16++;
};
Map[_local9][0].left = Map[_local9][(width - 1)];
Map[_local9][(width - 1)].right = Map[_local9][0];
_local7 = (_local7 - _local8);
_local9++;
};
Holder = _arg5;
top = (_arg2 - 1);
_local9 = 0;
while (_local9 < Map[0].length) {
Background.graphics.moveTo(Map[0][_local9].xp, Map[0][_local9].yp);
Background.graphics.lineTo(Map[(height - 1)][_local9].xp, Map[(height - 1)][_local9].yp);
_local9++;
};
Holder.addChild(Background);
animations = new Array();
ClearSound = new sfx_clear();
lock = false;
}
private function adjust_rows(_arg1:uint){
var _local2:uint;
var _local3:uint;
_local2 = _arg1;
while (_local2 >= top) {
_local3 = 0;
while (_local3 < width) {
Map[_local2][_local3].type = Map[(_local2 - 1)][_local3].type;
Map[_local2][_local3].color = Map[(_local2 - 1)][_local3].color;
_local3++;
};
_local2--;
};
top++;
}
public function draw():void{
var _local1:uint;
var _local2:uint;
if (!lock){
_local1 = 0;
while (_local1 < height) {
_local2 = 0;
while (_local2 < width) {
if (Map[_local1][_local2].type == 1){
Map[_local1][_local2].draw(Holder);
} else {
Map[_local1][_local2].erase(Holder);
};
_local2++;
};
_local1++;
};
};
}
public function clear(_arg1:piece, _arg2:uint, _arg3:uint):void{
var _local4:uint;
var _local5:uint;
var _local6:uint;
if (!lock){
_local5 = _arg3;
while (_local5 < (_arg1.shape.length + _arg3)) {
_local6 = _arg2;
while (_local6 < (_arg1.shape[0].length + _arg2)) {
_local4 = _local6;
if (_local4 >= width){
_local4 = (_local4 - width);
};
if ((((_arg1.shape[(_local5 - _arg3)][(_local6 - _arg2)] == 1)) && ((Map[_local5][_local4].type == 1)))){
Map[_local5][_local4].type = 0;
Map[_local5][_local4].erase(Holder);
};
_local6++;
};
_local5++;
};
};
}
public function hitroll(_arg1:piece, _arg2:uint, _arg3:uint):Boolean{
var _local4:uint;
var _local5:uint;
var _local6:Tile;
_local4 = 0;
while (_local4 < _arg1.height) {
_local6 = Map[(_arg3 + _local4)][_arg2];
_local5 = 0;
while (_local5 < _arg1.width) {
if ((((_arg1.shape[_local4][_local5] == 0)) && ((_local6.type == 1)))){
return (true);
};
_local6 = _local6.right;
_local5++;
};
_local4++;
};
if (_arg1.extend()){
_local6 = Map[((_arg3 + _arg1.height) + 1)][_arg2];
_local4 = 0;
while (_local4 < _arg1.width) {
if (_local6.type == 1){
return (true);
};
_local6 = _local6.right;
_local4++;
};
};
return (false);
}
public function move(_arg1:int, _arg2:int):uint{
_arg1 = (_arg1 + _arg2);
if (_arg1 < 0){
return ((width - 1));
};
if (_arg1 >= width){
return (0);
};
return (_arg1);
}
public function destroy():void{
var _local1:uint;
var _local2:uint;
lock = false;
top = (height - 1);
_local1 = 0;
while (_local1 < Map.length) {
_local2 = 0;
while (_local2 < Map[_local1].length) {
Map[_local1][_local2].type = 0;
Map[_local1][_local2].erase(Holder);
_local2++;
};
_local1++;
};
draw();
}
public function hit(_arg1:piece, _arg2:uint, _arg3:uint, _arg4:uint):Boolean{
var _local5:uint;
var _local6:uint;
switch (_arg4){
case 0:
if ((_arg3 + _arg1.height) == (height - 1)){
return (true);
};
_local5 = 0;
while (_local5 < _arg1.width) {
if (_arg1.bottom[_local5] < 0){
} else {
_local6 = (_arg2 + _local5);
if (_local6 >= width){
_local6 = (_local6 - width);
};
if (Map[((_arg3 + _arg1.bottom[_local5]) + 1)][_local6].type != 0){
return (true);
};
};
_local5++;
};
return (false);
case 1:
_local5 = 0;
while (_local5 < _arg1.height) {
if (_arg1.left[_local5] < 0){
} else {
_local6 = (_arg2 + _arg1.left[_local5]);
if (_local6 >= width){
_local6 = (_local6 - width);
};
if (Map[(_arg3 + _local5)][_local6].left.type != 0){
return (true);
};
};
_local5++;
};
return (false);
case 2:
_local5 = 0;
while (_local5 < _arg1.height) {
if (_arg1.right[_local5] < 0){
} else {
_local6 = (_arg2 + _arg1.right[_local5]);
if (_local6 >= width){
_local6 = (_local6 - width);
};
if (Map[(_arg3 + _local5)][_local6].right.type != 0){
return (true);
};
};
_local5++;
};
return (false);
};
return (false);
}
public function end():Boolean{
return ((top <= 1));
}
public function check_clear():uint{
var _local1:uint;
var _local2:uint;
var _local3:int;
_local2 = 0;
_local3 = (Map.length - 1);
while (_local3 > top) {
_local1 = 0;
while (_local1 < Map[_local3].length) {
if (Map[_local3][_local1].type == 0){
break;
};
_local1++;
};
if (_local1 == Map[_local3].length){
white_row(_local3);
_local2++;
};
_local3--;
};
return (_local2);
}
public function update_top(_arg1:uint):void{
if (_arg1 < top){
top = _arg1;
};
}
private function white_row(_arg1:uint){
var _local2:Object;
var _local3:Timer;
var _local4:uint;
_local2 = new Object();
_local3 = new Timer(100, 1);
_local4 = 0;
while (_local4 < Map[_arg1].length) {
Map[_arg1][_local4].erase(Holder);
Map[_arg1][_local4].color = 0xFFFFFF;
_local4++;
};
this.draw();
_local3.addEventListener("timer", clear_adj);
_local3.start();
_local2.clock = _local3;
_local2.id = _arg1;
animations.push(_local2);
lock = true;
}
private function clear_row(_arg1:uint){
var _local2:uint;
_local2 = 0;
while (_local2 < Map[_arg1].length) {
Map[_arg1][_local2].type = 0;
Map[_arg1][_local2].erase(Holder);
_local2++;
};
}
public function print(_arg1:piece, _arg2:uint, _arg3:uint):void{
var _local4:uint;
var _local5:uint;
var _local6:uint;
var _local7:uint;
_local4 = 0;
_local5 = 0;
if (!lock){
_local6 = _arg3;
while (_local6 < (_arg1.shape.length + _arg3)) {
_local7 = _arg2;
while (_local7 < (_arg1.shape[0].length + _arg2)) {
if (_arg1.shape[_local4][_local5] == 1){
if (_local7 >= width){
Map[_local6][(_local7 - width)].type = _arg1.shape[_local4][_local5];
Map[_local6][(_local7 - width)].color = _arg1.color;
} else {
Map[_local6][_local7].type = _arg1.shape[_local4][_local5];
Map[_local6][_local7].color = _arg1.color;
};
};
_local5++;
_local7++;
};
_local4++;
_local5 = 0;
_local6++;
};
};
}
private function clear_adj(_arg1:TimerEvent):void{
var _local2:Object;
_local2 = animations.pop();
clear_row(_local2.id);
ClearSound.play(0, 0);
adjust_rows(_local2.id);
if (animations.length == 0){
lock = false;
};
}
}
}//package Tiles
Section 8
//Tile (Tiles.Tile)
package Tiles {
import flash.display.*;
public class Tile extends MovieClip {
public var left;
public var yp:Number;
public var right;
public var color:uint;
public var type:uint;
public var down:Tile;
private var drawn:Boolean;
public var xp;
public function Tile(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number){
this.type = 0;
this.drawn = false;
xp = _arg1;
yp = _arg2;
}
public function set_type(_arg1:uint):void{
this.type = _arg1;
}
public function draw(_arg1:MovieClip){
if (!drawn){
this.graphics.lineStyle(1, 0, 1);
this.graphics.moveTo(xp, yp);
this.graphics.beginFill(color);
this.graphics.lineTo(right.xp, right.yp);
this.graphics.lineTo(right.down.xp, right.down.yp);
this.graphics.lineTo(down.xp, down.yp);
this.graphics.lineTo(xp, yp);
_arg1.addChild(this);
drawn = true;
};
}
public function erase(_arg1:MovieClip){
if (drawn){
_arg1.removeChild(this);
drawn = false;
};
}
}
}//package Tiles
Section 9
//background (background)
package {
import flash.display.*;
public dynamic class background extends MovieClip {
}
}//package
Section 10
//over (over)
package {
import flash.display.*;
public dynamic class over extends MovieClip {
public function over(){
addFrameScript(39, frame40);
}
function frame40(){
stop();
}
}
}//package
Section 11
//ponto (ponto)
package {
import flash.display.*;
public dynamic class ponto extends MovieClip {
}
}//package
Section 12
//sfx_clear (sfx_clear)
package {
import flash.media.*;
public dynamic class sfx_clear extends Sound {
}
}//package
Section 13
//sfx_exp (sfx_exp)
package {
import flash.media.*;
public dynamic class sfx_exp extends Sound {
}
}//package
Section 14
//sfx_hit (sfx_hit)
package {
import flash.media.*;
public dynamic class sfx_hit extends Sound {
}
}//package
Section 15
//sfx_levelup (sfx_levelup)
package {
import flash.media.*;
public dynamic class sfx_levelup extends Sound {
}
}//package
Section 16
//sfx_move (sfx_move)
package {
import flash.media.*;
public dynamic class sfx_move extends Sound {
}
}//package
Section 17
//sfx_rot (sfx_rot)
package {
import flash.media.*;
public dynamic class sfx_rot extends Sound {
}
}//package