/** * Gets the distance of map coordinates to the center. * * @param x * The x coordinate. * @param y * The y coordinate * @return The distance to the center of this circle, so that the tiles around the center all have distance 1. */ public final float squaredDistanceToCenter(int x, int y) { return getSquaredDistance(x - centerX, y - centerY); }
public static final float getDistanceSquared(int x1, int y1, int x2, int y2) { int dx = x1 - x2; int dy = y1 - y2; return getSquaredDistance(dx, dy); }
public CachedViewCircle(int radius) { radius -= FogOfWar.PADDING / 2; MapCircle circle = new MapCircle(0, 0, radius + FogOfWar.PADDING); size = countElements(circle); x = new short[size]; y = new short[size]; sight = new byte[size]; MapCircleIterator iter = circle.iterator(); final float squaredViewDistance = radius * radius; int i = 0; while (iter.hasNext()) { int y = iter.nextY(); int x = iter.nextX(); this.x[i] = (short) x; this.y[i] = (short) y; double squaredDistance = MapCircle.getSquaredDistance(x, y); byte newSight; if (squaredDistance < squaredViewDistance) { newSight = CommonConstants.FOG_OF_WAR_VISIBLE; } else { newSight = (byte) (CommonConstants.FOG_OF_WAR_VISIBLE - (Math.sqrt(squaredDistance) - radius) / FogOfWar.PADDING * CommonConstants.FOG_OF_WAR_VISIBLE); } sight[i] = newSight; i++; } }