Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7673843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:36:20+00:00 2026-05-31T16:36:20+00:00

I am developing a game in java just for fun. It is a ball

  • 0

I am developing a game in java just for fun. It is a ball brick breaking game of some sort.

enter image description here

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.

So it would clear out everything in this level without the gray bricks.

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.


//NOTE TO SELF: read up on Enums and List

When a explosive cell is hit with the ball it calls the explodeMyAdjecentCells();

//This is in the Cell class

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);

}

//This is the CellHandler->(CellBlocks)

public void explodeCell(int _X, int _Y) {


    for(int c = 0; c < cells.length; c++){

        if(cells[c] != null && !cells[c].hasExploded()) {

            if(cells[c].getX() == _X && cells[c].getY() == _Y) {

                int type = cells[c].getThickness();

                if(type != 7 && type != 6 && type != 2) {

                    cells[c].explodeMyAdjecentCells();
                }


            }
        }
    }

}

It successfully removes my all adjacent cells,

But in the explodeMyAdjecentCells() method, I have this line of code

ballGame.breakCell(x, y, imageURL[thickness - 1][0]);

//

This line tells the ParticleHandler to create 25 small images(particles) of the exploded cell.

Tough all my cells are removed the particleHandler do not create particles for all the removed cells.


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!

private int particleCellsMax = 1500;
private int particleCellsMax = 2500;

thx for all the help people, I will upload the source for creating the particles youst for fun if anyone needs it.

The source code for splitting image into parts was taken from:
Kalani’s Tech Blog

//Particle Handler

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 < colums; x++) {

        for(int y = 0; y < 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 < rows; iy ++) {

        for(int ix = 0; ix < colums; ix++) {

            if(c < 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) {}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:36:22+00:00Added an answer on May 31, 2026 at 4:36 pm

    I would imagine a method that would recursively get all touching cells of a similar color.
    Then you can operate on that list (of all touching blocks) pretty easily and break all the ones are haven’t been broken.

    Also note that your getAdjentCell() method has side effects (it does the breaking) which isn’t very intuitive based on the name.

    // I agree with Matt that color (or type) should probably be an enum, 
    // or at least a class.  int isn't very descriptive
    public enum CellType { GRAY, RED, ORANGE }
    
    public class Cell{
    ....
        public final CellType type;
    
        /**
         * Recursively find all adjacent cells that have the same type as this one.
         */
        public List<Cell> getTouchingSimilarCells() {
            List<Cell> result = new ArrayList<Cell>();
            result.add(this);
            for (Cell c : getAdjecentCells()) {
                if (c != null && c.type == this.type) {
                    result.addAll(c.getTouchingSimilarCells());
                }
            }
            return result;
        }
    
        /**
         * Get the 4 adjacent cells (above, below, left and right).<br/>
         * NOTE: a cell may be null in the list if it does not exist.
         */
        public List<Cell> getAdjecentCells() {
            List<Cell> result = new ArrayList<Cell>();
            result.add(cellBlock(this.getX() + 1, this.getY()));
            result.add(cellBlock(this.getX() - 1, this.getY()));
            result.add(cellBlock(this.getX(), this.getY() + 1));
            result.add(cellBlock(this.getX(), this.getY() - 1));
            return result;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just added some computationally expensive code to an Android game I am developing.
Here is my situation: I am developing a java typing game, and I need
I am developing a Java game, and am currently writing a map maker. I
Can anyone recommend a good Java game engine for developing simple tile-based games? I'm
The game I'm developing renders perfectly on the Java backend and on IE 10.
I'm developing a real time strategy game clone on the Java platform and I
Hi i am developing game level editor.Currently I am using win32 with directX.But with
I am developing a game with dozens of levels and each level has a
I'm developing a Java game and want to bundle and play a number of
I'm developing a small game in Java and I have run into a problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.