示例#1
0
        public int toucheBlock(Block block,bool haut, bool bas,bool gauche,bool droite)
        {
            int xBalle = Location.X, yBalle = Location.Y ,
               xBlock = block.Location.X, yBlock = block.Location.Y,
               hBlock = block.Size.Height, wBlock=block.Size.Width;

               int pointBrique = 0;

               if (block.Visible == true)
               {
               //il faut que la balle ne soit entrée en collision qu'avec un seul côté du block
               if (CompteTouches(xBalle, yBalle, xBlock, yBlock, hBlock, wBlock, haut, bas, gauche, droite) > 1)
               {
                   int i = 0;
                   int x = xBalle, y = yBalle;
                   //On fait progressivement reculer la balle pour voir quel est le premier côté du block qu'elle a touché
                   while (CompteTouches(x, y, xBlock, yBlock, hBlock, wBlock, haut, bas, gauche, droite) > 0)
                   {

                       i++;
                       xBalle = x;
                       yBalle = y;
                       if (Math.Abs(x - Location.X) <= Math.Abs(deplacementX))
                           x -= 1 * Math.Sign(deplacementX);

                       if (Math.Abs(y - Location.Y) <= Math.Abs(deplacementY))
                           y -= 1 * Math.Sign(deplacementY);
                   }
               }

               /*On détermine si la bille a touché un block en fonction des coordonnées de la balle et du block courant, des blocks voisins au block courant et du sens de déplacement de la balle */
               /* par le bas  */
               if (xBalle + this.Size.Width > xBlock &&
                 xBalle < xBlock + wBlock &&
                 yBalle + this.Size.Height > yBlock + hBlock &&
                 yBalle < yBlock + hBlock && !bas && Math.Sign(deplacementY)== -1)
               {
                   Console.Beep(220, 10);
                   deplacementY = -1 * deplacementY;

                   block.Visible = false;
                   pointBrique += SCORE_BRIQUE;
                   toucheBl = true;
               }
               else
               {
                   /* par la droite */
                   if (xBalle + this.Size.Width > xBlock + wBlock &&
                       xBalle < xBlock + wBlock &&
                       yBalle + this.Size.Height > yBlock &&
                       yBalle < yBlock + hBlock && !droite && Math.Sign(deplacementX)== -1)
                   {
                       Console.Beep(220, 10);
                       deplacementX = -1 * deplacementX;
                       block.Visible = false;
                       pointBrique += SCORE_BRIQUE;
                       toucheBl = true;

                   }

                   else
                   {
                       /* par la gauche */
                       if (xBalle + this.Size.Width > xBlock &&
                           xBalle < xBlock &&
                           yBalle + this.Size.Height > yBlock &&
                           yBalle < yBlock + hBlock && !gauche && Math.Sign(deplacementX)== 1)
                       {
                           Console.Beep(220, 10);
                           deplacementX = -1 * deplacementX;
                           block.Visible = false;
                           pointBrique += SCORE_BRIQUE;
                           toucheBl = true;

                       }
                       else
                       {
                           /* par le haut */
                           if (xBalle + this.Size.Width > xBlock &&
                            xBalle < xBlock + wBlock &&
                            yBalle + this.Size.Height > yBlock &&
                            yBalle < yBlock && !haut && Math.Sign(deplacementY)== 1)
                           {
                               Console.Beep(220, 10);
                               deplacementY = -1 * deplacementY;
                               block.Visible = false;

                               pointBrique += SCORE_BRIQUE;
                               toucheBl = true;
                           }
                       }
                   }
               }
               }
               else if (block.Visible == false && block.getVar() == true)
                block.Visible = true;

               return pointBrique;
        }
示例#2
0
        //Cette fonction initialise nos blocks
        private void InitializeBlock()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Arkanoid));
            int absX = (this.Size.Width-1) / 10;

            // CONSTRUCTION DE TOUS LES BLOCS SUR UNE GRILLE DE 10 X 5
            // I REPRESENTE L'INDICE DES LIGNES
            // J REPRESENTE L'INDICE DES COLONNES
            for (int i = 0; i < 10; i++)
            {
                blocks[i] = new Block[5];//Tableau de blocks
                for (int j = 0; j < 5; j++)
                {
                    this.blocks[i][j] = new Block(i, j, absX, BarreDoutil.Size.Height, resources);   //on ajoute un nouveau block au tableau de Block en indiquant la taille de la barre d'outil
                    this.blocks[i][j].BorderStyle = BorderStyle.Fixed3D;       // modifie le style des block
                    this.Controls.Add(this.blocks[i][j]); // on ajoute le block aux composants ("contrôles") de la fenetre
                }
            }
        }