Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ox=110;
- oy=25;
- bz=20;
- slowcd=8;
- fastcd=2;
- maxcd=slowcd;
- cd=maxcd;
- Xvals = new Array();
- Yvals = new Array();
- emptyGrid = new Array(0,0,0,0,0,0,0,0,0,0);
- fullGrid = new Array(1,1,1,1,1,1,1,1,1,1);
- coreGrid = new Array();
- coreGrid[0]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[1]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[2]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[3]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[4]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[5]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[6]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[7]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[8]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[9]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[10]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[11]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[12]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[13]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[14]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[15]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[16]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[17]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[18]=new Array (0,0,0,0,0,0,0,0,0,0);
- coreGrid[19]=new Array (0,0,0,0,0,0,0,0,0,0);
- createGrid = function(){
- _root.createEmptyMovieClip("grid",200);
- y=0;
- x=0;
- for(y>0;y<20;y++){
- for(x>0;x<10;x++){
- newBlock = grid.attachMovie("block","block_"+x+10*y,x+10*y,{IDx:x,IDy:y});
- with(newBlock){
- _x=_root.ox+(x*_root.bz);
- _y=_root.oy+(y*_root.bz);
- _width=_root.bz-1;
- _height=_root.bz-1;
- }
- newBlock.onEnterFrame=function(){
- this.gotoAndStop(_root.coreGrid[this.IDy][this.IDx]+1);
- }
- }x=0;
- }y=0;
- }
- createGrid();
- createBlock = function(){
- w=0;
- for(w>0;w<4;w++){
- trace(w);
- //check for completed lines and move values accordingly (tetris rules)
- c=19;
- for(c<20;c>-1;c--){
- //trace(c);
- if(_root.coreGrid[c].toString()==_root.fullGrid.toString()){
- _root.q=c;
- //trace("row "+c+" is complete!");
- d=_root.q;
- for(d<20;d>2;d--){
- o=0;
- for(o>1;o<10;o++){
- //_root.coreGrid[0]=
- _root.coreGrid[d][o]=_root.coreGrid[d-1][o];
- }
- o=0;
- }
- d=_root.q;
- }
- }
- }
- //create new block
- _root.blockchooser=(int(Math.random()*2)+1);
- //trace(_root.blockchooser);
- //_root.blockchooser=2;
- //trace(_root.blockchooser);
- if(_root.blockchooser==1){
- _root.currentblock="i";
- //B1
- _root.BX1=4;
- _root.BY1=0;
- _root.coreGrid[_root.BY1][_root.BX1]=1;
- //B2
- _root.BX2=5;
- _root.BY2=0;
- _root.coreGrid[_root.BY2][_root.BX2]=1;
- //B3
- _root.BX3=6;
- _root.BY3=0;
- _root.coreGrid[_root.BY3][_root.BX3]=1;
- //B4
- _root.BX4=7;
- _root.BY4=0;
- _root.coreGrid[_root.BY4][_root.BX4]=1;
- }
- if(_root.blockchooser==2){
- _root.currentblock="o";
- //B1
- _root.BX1=4;
- _root.BY1=0;
- _root.coreGrid[_root.BY1][_root.BX1]=1;
- //B2
- _root.BX2=5;
- _root.BY2=0;
- _root.coreGrid[_root.BY2][_root.BX2]=1;
- //B3
- _root.BX3=4;
- _root.BY3=1;
- _root.coreGrid[_root.BY3][_root.BX3]=1;
- //B4
- _root.BX4=5;
- _root.BY4=1;
- _root.coreGrid[_root.BY4][_root.BX4]=1;
- }
- }
- createBlock();
- onEnterFrame=function(){
- if(Key.isDown(Key.SPACE)){
- trace(_root.coreGrid[0][0]);
- }
- if(Key.isDown(Key.DOWN)){
- _root.maxcd=_root.fastcd;
- } else{
- _root.maxcd=_root.slowcd;
- }
- if(Key.isDown(Key.RIGHT)){
- if((_root.BX2+1!=10)and(_root.BX4+1!=10)){
- if(((((((_root.coreGrid[_root.BY1][_root.BX1+1]==0)or(_root.BX1+1==_root.BX2)and(_root.BY1==_root.BY2)or(_root.BX1+1==_root.BX3)and(_root.BY1==_root.BY3)or(_root.BX1+1==_root.BX4)and(_root.BY1==_root.BY4))))))){
- if(((((((_root.coreGrid[_root.BY2][_root.BX2+1]==0)or(_root.BX2+1==_root.BX1)and(_root.BY2==_root.BY1)or(_root.BX2+1==_root.BX3)and(_root.BY2==_root.BY3)or(_root.BX2+1==_root.BX4)and(_root.BY2==_root.BY4))))))){
- if(((((((_root.coreGrid[_root.BY3][_root.BX3+1]==0)or(_root.BX3+1==_root.BX4)and(_root.BY3==_root.BY4)or(_root.BX3+1==_root.BX2)and(_root.BY3==_root.BY2)or(_root.BX3+1==_root.BX1)and(_root.BY3==_root.BY1))))))){
- if(((((((_root.coreGrid[_root.BY4][_root.BX4+1]==0)or(_root.BX4+1==_root.BX1)and(_root.BY4==_root.BY1)or(_root.BX4+1==_root.BX2)and(_root.BY4==_root.BY2)or(_root.BX4+1==_root.BX3)and(_root.BY4==_root.BY3))))))){
- _root.Xvals.push(_root.BX1,_root.BX2,_root.BX3,_root.BX4);
- _root.Xvals.sort();
- x=3;
- for(x<4;x>-1;x--){
- //trace(x);
- if(_root.BX1==_root.Xvals[x]){
- _root.coreGrid[_root.BY1][_root.BX1]=0;
- _root.BX1++;
- _root.coreGrid[_root.BY1][_root.BX1]=1;
- }
- if(_root.BX2==_root.Xvals[x]){
- _root.coreGrid[_root.BY2][_root.BX2]=0;
- _root.BX2++;
- _root.coreGrid[_root.BY2][_root.BX2]=1;
- }
- if(_root.BX3==_root.Xvals[x]){
- _root.coreGrid[_root.BY3][_root.BX3]=0;
- _root.BX3++;
- _root.coreGrid[_root.BY3][_root.BX3]=1;
- }
- if(_root.BX4==_root.Xvals[x]){
- _root.coreGrid[_root.BY4][_root.BX4]=0;
- _root.BX4++;
- _root.coreGrid[_root.BY4][_root.BX4]=1;
- }
- }
- x=3;
- //resets Xvals array
- _root.Xvals = new Array();
- }
- }
- }
- }
- }
- }
- if(Key.isDown(Key.LEFT)){
- if((_root.BX3-1!=-1)and(_root.BX1-1!=-1)){
- if((((_root.coreGrid[_root.BY1][_root.BX1-1]==0)or(_root.BX1-1==_root.BX2)or(_root.BX1-1==_root.BX3)or(_root.BX1-1==_root.BX4)))){
- if((((_root.coreGrid[_root.BY2][_root.BX2-1]==0)or(_root.BX2-1==_root.BX1)or(_root.BX2-1==_root.BX3)or(_root.BX2-1==_root.BX4)))){
- if((((_root.coreGrid[_root.BY3][_root.BX3-1]==0)or(_root.BX3-1==_root.BX4)or(_root.BX3-1==_root.BX2)or(_root.BX3-1==_root.BX1)))){
- if((((_root.coreGrid[_root.BY4][_root.BX4-1]==0)or(_root.BX4-1==_root.BX1)or(_root.BX4-1==_root.BX2)or(_root.BX4-1==_root.BX3)))){
- _root.Xvals.push(_root.BX1,_root.BX2,_root.BX3,_root.BX4);
- _root.Xvals.sort();
- x=0;
- for(x>0;x<4;x++){
- //trace(x);
- if(_root.BX1==_root.Xvals[x]){
- _root.coreGrid[_root.BY1][_root.BX1]=0;
- _root.BX1--;
- _root.coreGrid[_root.BY1][_root.BX1]=1;
- }
- if(_root.BX2==_root.Xvals[x]){
- _root.coreGrid[_root.BY2][_root.BX2]=0;
- _root.BX2--;
- _root.coreGrid[_root.BY2][_root.BX2]=1;
- }
- if(_root.BX3==_root.Xvals[x]){
- _root.coreGrid[_root.BY3][_root.BX3]=0;
- _root.BX3--;
- _root.coreGrid[_root.BY3][_root.BX3]=1;
- }
- if(_root.BX4==_root.Xvals[x]){
- _root.coreGrid[_root.BY4][_root.BX4]=0;
- _root.BX4--;
- _root.coreGrid[_root.BY4][_root.BX4]=1;
- }
- }
- x=0;
- //resets Xvals array
- _root.Xvals = new Array();
- }
- }
- }
- }
- }
- }
- _root.cd--;
- if(_root.cd==0){
- if((((_root.BY1+1!=20)and(_root.BY2+1!=20)and(_root.BY3+1!=20)and(_root.BY4+1!=20)))){
- if(((((((_root.coreGrid[_root.BY1+1][_root.BX1]==0)or(_root.BY1+1==_root.BY2)and(_root.BX1==_root.BX2)or(_root.BY1+1==_root.BY3)and(_root.BX1==_root.BX3)or(_root.BY1+1==_root.BY4)and(_root.BX1==_root.BX4))))))){
- if(((((((_root.coreGrid[_root.BY2+1][_root.BX2]==0)or(_root.BY2+1==_root.BY1)and(_root.BX2==_root.BX1)or(_root.BY2+1==_root.BY3)and(_root.BX2==_root.BX3)or(_root.BY2+1==_root.BY4)and(_root.BX2==_root.BX4))))))){
- if(((((((_root.coreGrid[_root.BY3+1][_root.BX3]==0)or(_root.BY3+1==_root.BY1)and(_root.BX3==_root.BX1)or(_root.BY3+1==_root.BY2)and(_root.BX3==_root.BX2)or(_root.BY3+1==_root.BY4)and(_root.BX3==_root.BX4))))))){
- if(((((((_root.coreGrid[_root.BY4+1][_root.BX4]==0)or(_root.BY4+1==_root.BY1)and(_root.BX4==_root.BX1)or(_root.BY4+1==_root.BY2)and(_root.BX4==_root.BX2)or(_root.BY4+1==_root.BY3)and(_root.BX4==_root.BX3))))))){
- _root.Yvals.push(_root.BY1,_root.BY2,_root.BY3,_root.BY4);
- //trace(_root.Yvals);
- //_root.Yvals.sort();
- //trace(_root.Yvals);
- y=3;
- for(y<4;y>-1;y--){
- //trace("y: "+y);
- if(_root.BY1==_root.Yvals[y]){
- _root.coreGrid[_root.BY1][_root.BX1]=0;
- _root.BY1++;
- _root.coreGrid[_root.BY1][_root.BX1]=1;
- }
- if(_root.BY2==_root.Yvals[y]){
- _root.coreGrid[_root.BY2][_root.BX2]=0;
- _root.BY2++;
- _root.coreGrid[_root.BY2][_root.BX2]=1;
- }
- if(_root.BY3==_root.Yvals[y]){
- _root.coreGrid[_root.BY3][_root.BX3]=0;
- _root.BY3++;
- _root.coreGrid[_root.BY3][_root.BX3]=1;
- }
- if(_root.BY4==_root.Yvals[y]){
- _root.coreGrid[_root.BY4][_root.BX4]=0;
- _root.BY4++;
- _root.coreGrid[_root.BY4][_root.BX4]=1;
- }
- }
- y=3;
- _root.coreGrid[_root.BY1][_root.BX1]=1;
- //resets Yvals array
- _root.Yvals = new Array();
- }else{
- createBlock();
- }
- }else{
- createBlock();
- }
- }else{
- createBlock();
- }
- }else{
- createBlock();
- }
- }else{
- createBlock();
- }
- _root.cd=_root.maxcd;
- }
- }
- /*
- gamemusic=new Sound;
- gamemusic.attachSound("theme");
- gamemusic.start(0,99);
- */
Add Comment
Please, Sign In to add comment