Ejemplo n.º 1
0
  /**
   * Return the color at the center of the cell. To paint a color, you need to get the background
   * image for the world and paint on that.
   *
   * @see #getBackground()
   * @throws IndexOutOfBoundsException If the location is not within the world bounds. If there is
   *     no background image at the location it will return Color.WHITE.
   */
  public Color getColorAt(int x, int y) {
    ensureWithinXBounds(x);
    ensureWithinYBounds(y);

    int xPixel = (int) Math.floor(getCellCenter(x));
    int yPixel = (int) Math.floor(getCellCenter(y));

    // Take tiling into account
    if (isTiled()) {
      xPixel = xPixel % backgroundImage.getWidth();
      yPixel = yPixel % backgroundImage.getHeight();
    }

    // TODO if it is not tiled, and outside, what should be returned? BGcolor? Null?
    if (xPixel >= backgroundImage.getWidth()) {
      return Color.WHITE;
    }
    if (yPixel >= backgroundImage.getHeight()) {
      return Color.WHITE;
    }

    return backgroundImage.getColorAt(xPixel, yPixel);
  }