//COLUMNS par Walter Siracusa function setBag(){ bag_mc.next_mc1.gotoAndStop(Current1); bag_mc.next_mc2.gotoAndStop(Current2); bag_mc.next_mc3.gotoAndStop(Current3); } function initBag(){ bag_mc._y=-HT_BLK; //Démarre 1 case au dessus de la table bag_mc._x=0; Current1=Next1; Current2=Next2; Current3=Next3; Next1=(1+random(6))*10; //10(R),20(V),30(B),40(J),50(M),60(C) Next2=(1+random(6))*10; Next3=(1+random(6))*10; next1_mc.gotoAndStop(Current1); next2_mc.gotoAndStop(Current2); next3_mc.gotoAndStop(Current3); setBag(); } function putBlk(i_blk,j_blk,val){ if(j_blk>=0){ //N'écris pas hors de la table (cas ou bag_mc déborde) Tab[i_blk][j_blk]=val; _root["blk_mc"+(j_blk*LG_TAB+i_blk)].gotoAndStop(val); } } function bagMove(){ i_blk=Math.floor(bag_mc._x/LG_BLK); j_blk=Math.floor(bag_mc._y/HT_BLK); //= -1 au départ if(!Key.isDown(Key.UP)) keyup=false; //Autorise HAUT après chaque relâchement if(!Key.isDown(Key.DOWN)) bag_mc.vt=bag_mc.vt0; //Descent les 3 blocs de vt0 pixels if(Key.isDown(Key.LEFT) && bag_mc._x>0 && (Tab[i_blk-1][j_blk+1]==VIDE || arrow_mc._visible)){ bag_mc._x-=LG_BLK; }else if(Key.isDown(Key.RIGHT) && bag_mc._x<(LG_TAB-1)*LG_BLK && (Tab[i_blk+1][j_blk+1]==VIDE || arrow_mc._visible)){ bag_mc._x+=LG_BLK; }else if(Key.isDown(Key.UP) && !keyup){ keyup=true; tmp=Current3; Current3=Current2; Current2=Current1; Current1=tmp; setBag(); }else if(Key.isDown(Key.DOWN)) bag_mc.vt=bag_mc.vt_max; //Vitesse de descente maximale } function bagDown(){ if(getTimer()>timer0_arrow+1500){ //Temps passé => //Chute de bag_mc de vt pixels i_blk=Math.floor(bag_mc._x/LG_BLK); j_blk=Math.floor((bag_mc._y)/HT_BLK); //Ne touche pas le fond de la grille et pas de bloc dessous if(bag_mc._y<(HT_TAB-1)*HT_BLK && (Tab[i_blk][j_blk+1]==VIDE || arrow_mc._visible)){ next1_mc.gotoAndStop(Next1); //Affiche le bag suivant next2_mc.gotoAndStop(Next2); next3_mc.gotoAndStop(Next3); arrow_mc._visible=false; bag_mc._y+=bag_mc.vt; }else{ if(bag_mc._y==(-HT_BLK+bag_mc.vt)){ //Colonne pleine => GAME OVER _root.onEnterFrame=function(){}; zik_snd.stop(); _root.attachMovie("end_mc","end_mc",_root.getNextHighestDepth(),{_x:107,_y:91}); }else{ //Touche le fond ou un bloc => Modifie les blocs de la grille en rapport avec ceux de bag_mc putBlk(i_blk,j_blk,Current1); putBlk(i_blk,j_blk-1,Current2); putBlk(i_blk,j_blk-2,Current3); initBag(); //Nouveau bag_mc Mode=LINE; //3 blocs posés => De nouveaux alignements ? => Mode LINE } } }else{ //En attente du timer... arrow_mc._visible=true; arrow_mc._x=bag_mc._x; } } function blkLine(){ to_destroy=false; for(j=0;j=BLK_LINE){ //Alignement entre i1 et i2 to_destroy=true; if(i2==LG_TAB) i2--; for(i=i1;i<=i2;i++) Tab_bool[i][j]=true; Score+=(nb_blk*nb_blk); } i1=i2; } } } //Alignements verticaux for(i=0;i=BLK_LINE){ //Alignement entre j1 et j2 to_destroy=true; if(j2==HT_TAB) j2--; //On ne compte pas le bloc qui est différent for(j=j1;j<=j2;j++) Tab_bool[i][j]=true; Score+=(nb_blk*nb_blk); } j1=j2; } } } //Alignements diagonales (Gauche-Droite) for(j=0;j=BLK_LINE){ //Alignement entre (i1;j1) et (i2;j2) to_destroy=true; i2--; j2--; i1=i; j1=j; while(j1<=j2) Tab_bool[i1++][j1++]=true; Score+=(nb_blk*nb_blk)*2; } } } } //Alignements diagonales (Droite-Gauche) for(j=0;j=(BLK_LINE-1);i--){ i2=i; j2=j; val=Tab[i2][j2]; if(val!=VIDE){ nb_blk=0; while(i2>=0 && j2=BLK_LINE){ //Alignement entre (i2;j2) et (i1;j1) to_destroy=true; i2++; //i2>=i1 j2--; i1=i; j1=j; while(j1<=j2) Tab_bool[i1--][j1++]=true; Score+=(nb_blk*nb_blk)*2; } } } } //Parcours la table des booléens pour détruire les blocs alignés if(to_destroy){ //Des blocs sont à détruire for(j=0;j Mode FALL //Son disp_snd.start(); }else{ Mode=MOVE; //Pas ou plus de bloc détruit => pas de chute => Mode MOVE timer0_arrow=getTimer(); } } function blkFall(){ //Parcours la table de bas en haut (jusqu'à la ligne 1) to_fall=false; for(j=HT_TAB-1;j>0;j--) for(i=0;i De nouveaux alignements => Mode LINE } //-------------------------------- LG_TAB=6; //Largeur de la table (en cases) HT_TAB=13; //Hauteur LG_BLK=32; //Lageur d'un bloc (en pixels) HT_BLK=32; //Hauteur VIDE=1; //Constante de vide dans la table Tab associée à l'image clé 1 du clip blk_mc BLK_LINE=3; //Nb de blocs mininum pour valider un alignement //Les états du jeu MOVE=1; //Descente déplacement au clavier des 3 blocs LINE=2; //Détruit les blocs alignés FALL=3; //Chute de blocs au dessus du vide //-------------------------------- //Créer la table de base et une table booléene temporaire Tab=new Array(); Tab_bool=new Array(); for(i=0;itimer0_bag+50){ bagMove(); timer0_bag=getTimer(); } bagDown();break; case LINE: blkLine();break; case FALL: blkFall(); } } }