0

So I just want to be able to check if two images have collided. I am currently looping through every single image object in the world, then looping through every pixel in each one of those images and checking to see if one of them has the same coordinates as one of the pixels in the current image I am testing for collision. To me, this seems highly inefficient. It would be nice if someone could point out an easier, and less intensive way of doing this, if there is one. Here is my code:

for (int i = 0; i < picture_list.size(); i++)
    {
        if (picture_list.get(i) != this)
        {
            if (picture_list.get(i).isCollidable() == true)
            {
                Pixel[][] these_pixels = this.getPixels2D();
                Pixel[][] other_pixels = picture_list.get(i).getPixels2D();
                for (int this_row = 0; this_row < these_pixels.length; this_row++)
                {
                    for (int this_col = 0; this_col < these_pixels[this_row].length; this_col++)
                    {
                        for (int row = 0; row < other_pixels.length; row++)
                        {
                            for (int col = 0; col < other_pixels[row].length; col++)
                            {
                                if (these_pixels[this_row][this_col].getWorld_x() == other_pixels[row][col].getWorld_x()
                                        || these_pixels[this_row][this_col].getWorld_y() == other_pixels[row][col].getWorld_y())
                                {
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return false;

Sorry about how messy it is.

Hobbs2000
  • 311
  • 1
  • 6
  • 19

0 Answers0