Guest User

Untitled

a guest
Jan 26th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ox=110;
  2. oy=25;
  3. bz=20;
  4. slowcd=8;
  5. fastcd=2;
  6. maxcd=slowcd;
  7. cd=maxcd;
  8.  
  9. Xvals = new Array();
  10. Yvals = new Array();
  11.  
  12. emptyGrid = new Array(0,0,0,0,0,0,0,0,0,0);
  13. fullGrid = new Array(1,1,1,1,1,1,1,1,1,1);
  14.  
  15. coreGrid = new Array();
  16. coreGrid[0]=new Array   (0,0,0,0,0,0,0,0,0,0);
  17. coreGrid[1]=new Array   (0,0,0,0,0,0,0,0,0,0);
  18. coreGrid[2]=new Array   (0,0,0,0,0,0,0,0,0,0);
  19. coreGrid[3]=new Array   (0,0,0,0,0,0,0,0,0,0);
  20. coreGrid[4]=new Array   (0,0,0,0,0,0,0,0,0,0);
  21. coreGrid[5]=new Array   (0,0,0,0,0,0,0,0,0,0);
  22. coreGrid[6]=new Array   (0,0,0,0,0,0,0,0,0,0);
  23. coreGrid[7]=new Array   (0,0,0,0,0,0,0,0,0,0);
  24. coreGrid[8]=new Array   (0,0,0,0,0,0,0,0,0,0);
  25. coreGrid[9]=new Array   (0,0,0,0,0,0,0,0,0,0);
  26. coreGrid[10]=new Array  (0,0,0,0,0,0,0,0,0,0);
  27. coreGrid[11]=new Array  (0,0,0,0,0,0,0,0,0,0);
  28. coreGrid[12]=new Array  (0,0,0,0,0,0,0,0,0,0);
  29. coreGrid[13]=new Array  (0,0,0,0,0,0,0,0,0,0);
  30. coreGrid[14]=new Array  (0,0,0,0,0,0,0,0,0,0);
  31. coreGrid[15]=new Array  (0,0,0,0,0,0,0,0,0,0);
  32. coreGrid[16]=new Array  (0,0,0,0,0,0,0,0,0,0);
  33. coreGrid[17]=new Array  (0,0,0,0,0,0,0,0,0,0);
  34. coreGrid[18]=new Array  (0,0,0,0,0,0,0,0,0,0);
  35. coreGrid[19]=new Array  (0,0,0,0,0,0,0,0,0,0);
  36.  
  37. createGrid = function(){
  38.         _root.createEmptyMovieClip("grid",200);
  39.         y=0;
  40.         x=0;
  41.         for(y>0;y<20;y++){
  42.                 for(x>0;x<10;x++){
  43.                         newBlock = grid.attachMovie("block","block_"+x+10*y,x+10*y,{IDx:x,IDy:y});
  44.                         with(newBlock){
  45.                                 _x=_root.ox+(x*_root.bz);
  46.                                 _y=_root.oy+(y*_root.bz);
  47.                                 _width=_root.bz-1;
  48.                                 _height=_root.bz-1;
  49.                         }
  50.                                 newBlock.onEnterFrame=function(){
  51.                                         this.gotoAndStop(_root.coreGrid[this.IDy][this.IDx]+1);
  52.                                 }
  53.                 }x=0;
  54.         }y=0;
  55. }
  56.         createGrid();
  57.  
  58. createBlock = function(){
  59.    
  60. w=0;
  61. for(w>0;w<4;w++){
  62.     trace(w);
  63.     //check for completed lines and move values accordingly (tetris rules)
  64.     c=19;
  65.     for(c<20;c>-1;c--){
  66.             //trace(c);
  67.         if(_root.coreGrid[c].toString()==_root.fullGrid.toString()){
  68.                 _root.q=c;
  69.                 //trace("row "+c+" is complete!");
  70.                     d=_root.q;
  71.                         for(d<20;d>2;d--){
  72.                                 o=0;
  73.                                 for(o>1;o<10;o++){
  74.                                     //_root.coreGrid[0]=
  75.                                     _root.coreGrid[d][o]=_root.coreGrid[d-1][o];
  76.                                 }
  77.                                 o=0;
  78.                         }
  79.                     d=_root.q;
  80.         }
  81.     }
  82. }
  83.    
  84.     //create new block
  85.         _root.blockchooser=(int(Math.random()*2)+1);
  86.         //trace(_root.blockchooser);
  87.         //_root.blockchooser=2;
  88.         //trace(_root.blockchooser);
  89.         if(_root.blockchooser==1){
  90.             _root.currentblock="i";
  91.             //B1
  92.             _root.BX1=4;
  93.             _root.BY1=0;
  94.             _root.coreGrid[_root.BY1][_root.BX1]=1;
  95.             //B2
  96.             _root.BX2=5;
  97.             _root.BY2=0;
  98.             _root.coreGrid[_root.BY2][_root.BX2]=1;
  99.             //B3
  100.             _root.BX3=6;
  101.             _root.BY3=0;
  102.             _root.coreGrid[_root.BY3][_root.BX3]=1;
  103.             //B4
  104.             _root.BX4=7;
  105.             _root.BY4=0;
  106.             _root.coreGrid[_root.BY4][_root.BX4]=1;
  107.         }
  108.         if(_root.blockchooser==2){
  109.             _root.currentblock="o";
  110.             //B1
  111.             _root.BX1=4;
  112.             _root.BY1=0;
  113.             _root.coreGrid[_root.BY1][_root.BX1]=1;
  114.             //B2
  115.             _root.BX2=5;
  116.             _root.BY2=0;
  117.             _root.coreGrid[_root.BY2][_root.BX2]=1;
  118.             //B3
  119.             _root.BX3=4;
  120.             _root.BY3=1;
  121.             _root.coreGrid[_root.BY3][_root.BX3]=1;
  122.             //B4
  123.             _root.BX4=5;
  124.             _root.BY4=1;
  125.             _root.coreGrid[_root.BY4][_root.BX4]=1;
  126.         }
  127. }
  128.         createBlock();
  129. onEnterFrame=function(){
  130.        
  131.        if(Key.isDown(Key.SPACE)){
  132.            trace(_root.coreGrid[0][0]);
  133.        }
  134.        
  135.        if(Key.isDown(Key.DOWN)){
  136.            _root.maxcd=_root.fastcd;
  137.        }    else{
  138.                 _root.maxcd=_root.slowcd;
  139.        }
  140.        
  141.         if(Key.isDown(Key.RIGHT)){
  142.                 if((_root.BX2+1!=10)and(_root.BX4+1!=10)){
  143.                         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))))))){
  144.                                 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))))))){
  145.                                         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))))))){
  146.                                                 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))))))){
  147.                                                        
  148.                                                         _root.Xvals.push(_root.BX1,_root.BX2,_root.BX3,_root.BX4);
  149.                                                         _root.Xvals.sort();
  150.                                                        
  151.                                                         x=3;
  152.                                                         for(x<4;x>-1;x--){
  153.                                                             //trace(x);
  154.                                                             if(_root.BX1==_root.Xvals[x]){
  155.                                                                 _root.coreGrid[_root.BY1][_root.BX1]=0;
  156.                                                                  _root.BX1++;
  157.                                                                 _root.coreGrid[_root.BY1][_root.BX1]=1;
  158.                                                             }
  159.                                                             if(_root.BX2==_root.Xvals[x]){
  160.                                                                 _root.coreGrid[_root.BY2][_root.BX2]=0;
  161.                                                                  _root.BX2++;
  162.                                                                 _root.coreGrid[_root.BY2][_root.BX2]=1;
  163.                                                             }
  164.                                                             if(_root.BX3==_root.Xvals[x]){
  165.                                                                 _root.coreGrid[_root.BY3][_root.BX3]=0;
  166.                                                                  _root.BX3++;
  167.                                                                 _root.coreGrid[_root.BY3][_root.BX3]=1;
  168.                                                             }
  169.                                                             if(_root.BX4==_root.Xvals[x]){
  170.                                                                 _root.coreGrid[_root.BY4][_root.BX4]=0;
  171.                                                                  _root.BX4++;
  172.                                                                 _root.coreGrid[_root.BY4][_root.BX4]=1;
  173.                                                             }
  174.                                                         }
  175.                                                         x=3;
  176.                                                        
  177.                                                         //resets Xvals array
  178.                                                         _root.Xvals = new Array();
  179.                                                 }
  180.                                         }
  181.                                 }
  182.                         }
  183.                 }
  184.         }      
  185.         if(Key.isDown(Key.LEFT)){
  186.                 if((_root.BX3-1!=-1)and(_root.BX1-1!=-1)){
  187.                         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)))){
  188.                                 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)))){
  189.                                         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)))){
  190.                                                 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)))){
  191.                                              
  192.                                                         _root.Xvals.push(_root.BX1,_root.BX2,_root.BX3,_root.BX4);
  193.                                                         _root.Xvals.sort();
  194.                                                        
  195.                                                         x=0;
  196.                                                         for(x>0;x<4;x++){
  197.                                                             //trace(x);
  198.                                                             if(_root.BX1==_root.Xvals[x]){
  199.                                                                 _root.coreGrid[_root.BY1][_root.BX1]=0;
  200.                                                                  _root.BX1--;
  201.                                                                 _root.coreGrid[_root.BY1][_root.BX1]=1;
  202.                                                             }
  203.                                                             if(_root.BX2==_root.Xvals[x]){
  204.                                                                 _root.coreGrid[_root.BY2][_root.BX2]=0;
  205.                                                                  _root.BX2--;
  206.                                                                 _root.coreGrid[_root.BY2][_root.BX2]=1;
  207.                                                             }
  208.                                                             if(_root.BX3==_root.Xvals[x]){
  209.                                                                 _root.coreGrid[_root.BY3][_root.BX3]=0;
  210.                                                                  _root.BX3--;
  211.                                                                 _root.coreGrid[_root.BY3][_root.BX3]=1;
  212.                                                             }
  213.                                                             if(_root.BX4==_root.Xvals[x]){
  214.                                                                 _root.coreGrid[_root.BY4][_root.BX4]=0;
  215.                                                                  _root.BX4--;
  216.                                                                 _root.coreGrid[_root.BY4][_root.BX4]=1;
  217.                                                             }
  218.                                                         }
  219.                                                         x=0;
  220.                                                        
  221.                                                         //resets Xvals array
  222.                                                         _root.Xvals = new Array();
  223.                                                 }
  224.                                         }
  225.                                 }
  226.                         }
  227.                 }
  228.         }
  229.        
  230.         _root.cd--;
  231.         if(_root.cd==0){
  232.                 if((((_root.BY1+1!=20)and(_root.BY2+1!=20)and(_root.BY3+1!=20)and(_root.BY4+1!=20)))){
  233.                         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))))))){
  234.                                 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))))))){
  235.                                         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))))))){
  236.                                                 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))))))){
  237.                                                        
  238.                                                         _root.Yvals.push(_root.BY1,_root.BY2,_root.BY3,_root.BY4);
  239.                                                         //trace(_root.Yvals);
  240.                                                         //_root.Yvals.sort();
  241.                                                         //trace(_root.Yvals);
  242.                                                        
  243.                                                         y=3;
  244.                                                         for(y<4;y>-1;y--){
  245.                                                             //trace("y: "+y);
  246.                                                             if(_root.BY1==_root.Yvals[y]){
  247.                                                                 _root.coreGrid[_root.BY1][_root.BX1]=0;
  248.                                                                  _root.BY1++;
  249.                                                                 _root.coreGrid[_root.BY1][_root.BX1]=1;
  250.                                                             }
  251.                                                             if(_root.BY2==_root.Yvals[y]){
  252.                                                                 _root.coreGrid[_root.BY2][_root.BX2]=0;
  253.                                                                  _root.BY2++;
  254.                                                                 _root.coreGrid[_root.BY2][_root.BX2]=1;
  255.                                                             }
  256.                                                             if(_root.BY3==_root.Yvals[y]){
  257.                                                                 _root.coreGrid[_root.BY3][_root.BX3]=0;
  258.                                                                  _root.BY3++;
  259.                                                                 _root.coreGrid[_root.BY3][_root.BX3]=1;
  260.                                                             }
  261.                                                             if(_root.BY4==_root.Yvals[y]){
  262.                                                                 _root.coreGrid[_root.BY4][_root.BX4]=0;
  263.                                                                  _root.BY4++;
  264.                                                                 _root.coreGrid[_root.BY4][_root.BX4]=1;
  265.                                                             }
  266.                                                         }
  267.                                                         y=3;
  268.                                                         _root.coreGrid[_root.BY1][_root.BX1]=1;
  269.                                                        
  270.                                                         //resets Yvals array
  271.                                                         _root.Yvals = new Array();
  272.                                                 }else{
  273.                                                         createBlock();
  274.                                                 }
  275.                                         }else{
  276.                                                 createBlock();
  277.                                         }
  278.                                 }else{
  279.                                         createBlock();
  280.                                 }
  281.                         }else{
  282.                                 createBlock();
  283.                         }
  284.                 }else{
  285.                         createBlock();
  286.                 }
  287.                 _root.cd=_root.maxcd;
  288.         }
  289. }
  290. /*
  291. gamemusic=new Sound;
  292. gamemusic.attachSound("theme");
  293. gamemusic.start(0,99);
  294. */
Add Comment
Please, Sign In to add comment