title: Breaking bricks with chain reaction
body: <p>I am developing a game in java just for fun. It is a ball brick breaking game of some sort.</p>
  
  <p><img src="https://i.stack.imgur.com/W9iyN.png" alt="enter image description here"></p>
  
  <p>Here is a level, when the ball hits one of the Orange bricks I would like to create a chain reaction to explode all other bricks that are NOT gray(unbreakable) and are within reach of the brick being exploded.</p>
  
  <p>So it would clear out everything in this level without the gray bricks.</p>
  
  <p>I am thinking I should ask the brick that is being exploded for other bricks to the LEFT, RIGHT, UP, and DOWN of that brick then start the same process with those cells.</p>
  
  <hr>
  
  <p>//NOTE TO SELF: read up on Enums and List</p>
  
  <p>When a explosive cell is hit with the ball it calls the explodeMyAdjecentCells();</p>
  
  <p>//This is in the Cell class</p>
  
  <pre><code>public void explodeMyAdjecentCells() {
  
      exploded = true;
  
      ballGame.breakCell(x, y, imageURL[thickness - 1][0]);
  
      cellBlocks.explodeCell(getX() - getWidth(),getY());
      cellBlocks.explodeCell(getX() + getWidth(),getY());
      cellBlocks.explodeCell(getX(),getY() - getHeight());
      cellBlocks.explodeCell(getX(),getY() + getHeight());
  
      remove();
  
      ballGame.playSound("src\\ballgame\\Sound\\cellBrakes.wav", 100.0f, 0.0f, false, 0.0d);
  
  }
  </code></pre>
  
  <p>//This is the CellHandler->(CellBlocks)</p>
  
  <pre><code>public void explodeCell(int _X, int _Y) {
  
  
      for(int c = 0; c &lt; cells.length; c++){
  
          if(cells[c] != null &amp;&amp; !cells[c].hasExploded()) {
  
              if(cells[c].getX() == _X &amp;&amp; cells[c].getY() == _Y) {
  
                  int type = cells[c].getThickness();
  
                  if(type != 7 &amp;&amp; type != 6 &amp;&amp; type != 2) {
  
                      cells[c].explodeMyAdjecentCells();
                  }
  
  
              }
          }
      }
  
  }
  </code></pre>
  
  <p>It successfully removes my all adjacent cells,</p>
  
  <p>But in the explodeMyAdjecentCells() method, I have this line of code</p>
  
  <pre><code>ballGame.breakCell(x, y, imageURL[thickness - 1][0]);
  </code></pre>
  
  <p>//</p>
  
  <p>This line tells the ParticleHandler to create 25 small images(particles) of the exploded cell.</p>
  
  <p>Tough all my cells are removed the particleHandler do not create particles for all the removed cells.</p>
  
  <hr>
  
  <p><strong>The problem was solved youst now, its really stupid.
  I had set particleHandler to create max 1500 particles. My god how did i not see that!</strong></p>
  
  <pre><code>private int particleCellsMax = 1500;
  private int particleCellsMax = 2500;
  </code></pre>
  
  <p>thx for all the help people, I will upload the source for creating the particles youst for fun if anyone needs it.</p>
  
  <p>The source code for splitting image into parts was taken from:
  <a href="http://kalanir.blogspot.com/2010/02/how-to-split-image-into-chunks-java.html" rel="nofollow noreferrer">Kalani's Tech Blog</a></p>
  
  <p>//Particle Handler</p>
  
  <pre><code>public void breakCell(int _X, int _Y, String URL) {
  
      File file = new File(URL);
  
      try {
  
          FileInputStream fis = new FileInputStream(file);
          BufferedImage image = ImageIO.read(fis);
  
      int rows = 5;
      int colums = 5;
  
      int parts = rows * colums;
  
      int partWidth = image.getWidth() / colums;
      int partHeight = image.getHeight() / rows;
  
      int count = 0;
  
      BufferedImage imgs[] = new BufferedImage[parts];
  
      for(int x = 0; x &lt; colums; x++) {
  
          for(int y = 0; y &lt; rows; y++) {
  
              imgs[count] = new BufferedImage(partWidth, partHeight, image.getType());
  
              Graphics2D g = imgs[count++].createGraphics();
  
              g.drawImage(image, 0, 0, partWidth, partHeight, partWidth * y, partHeight * x, partWidth * y + partWidth, partHeight * x + partHeight, null);
              g.dispose();
          }
      }
  
      int numParts = imgs.length;
      int c = 0;
  
      for(int iy = 0; iy &lt; rows; iy ++) {
  
          for(int ix = 0; ix &lt; colums; ix++) {
  
              if(c &lt; numParts) {
  
                  Image imagePart = Toolkit.getDefaultToolkit().createImage(imgs[c].getSource());
                  createCellPart(_X + ((image.getWidth() / colums) * ix), _Y + ((image.getHeight() / rows) * iy), c, imagePart);
  
                  c++;
  
              } else {
  
                  break;
              }
          }
      }
  
  
      } catch(IOException io) {}
  }
  </code></pre>