Guest User

Untitled

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