public static void calculateFOV(Level level) { level.setLit(level.getHeroLocation(), 0); scanOctant1(level, level.getHeroLocation(), 1, 1, 0); scanOctant2(level, level.getHeroLocation(), 1, 1, 0); scanOctant3(level, level.getHeroLocation(), 1, 1, 0); scanOctant4(level, level.getHeroLocation(), 1, 1, 0); scanOctant5(level, level.getHeroLocation(), 1, 1, 0); scanOctant6(level, level.getHeroLocation(), 1, 1, 0); scanOctant7(level, level.getHeroLocation(), 1, 1, 0); scanOctant8(level, level.getHeroLocation(), 1, 1, 0); }
private static void scanOctant1(Level level, Location heroLocation, int depth, double startSlope, double endSlope) { if (depth >= Hero.MAX_SIGHT_DISTANCE) { return; } int y = heroLocation.y - depth; int x = heroLocation.x - (int)(startSlope * depth); while (getSlope(x, y, heroLocation.x, heroLocation.y, false) >= endSlope) { if (level.blocksSight(new Location(x, y))) { if (!level.blocksSight(new Location(x - 1, y))) { double newEndSlope = getSlope(x - 0.5, y + 0.5, heroLocation.x, heroLocation.y, false); scanOctant1(level, heroLocation, depth + 1, startSlope, newEndSlope); } } else { if (level.blocksSight(new Location(x - 1, y))) { startSlope = getSlope(x - 0.5, y - 0.5, heroLocation.x, heroLocation.y, false); } } level.setLit(new Location(x, y), 0); x++; } x--; if (depth < Hero.MAX_SIGHT_DISTANCE && !level.blocksSight(new Location(x, y))) { scanOctant1(level, heroLocation, depth + 1, startSlope, endSlope); } }
private static void initLighting(Level level, Rect bounds) { for (int x = bounds.x1; x <= bounds.x2; x++) { for (int y = bounds.y1; y <= bounds.y2; y++) { if (isDark(level, new Location(x, y))) { level.setLit(new Location(x, y), Entity.LIT_FULL_DARK); } } } }