Hi!
I’m implementing fog of war into my tile based game. It’s chunky, meaning that a tile either has the fog, or does not have the fog.
Every frame I set all tiles to “not visible”. Then, I loop through all the entities, lighting up circles of tiles around them. For the circle, I use this algorithm:
public class CircleAlgorithm {
private ArrayList<GridPoint2> pointList = new ArrayList<GridPoint2>();
public List<GridPoint2> getCirclePoints(int x, int y, int radius) {
pointList.clear();
for(int j = -radius; j <= radius; j++) {
for(int i = -radius; i <= radius; i++) {
if(i*i+j*j <= radius*radius + radius* 0.8f) {
pointList.add(new GridPoint2(x+i, y+j));
}
}
}
return pointList;
}
}
I know it look shady, but it produces really good looking circles for its low complexity. I fear this method of having, and maintaining fog of war is not the best. Here’s an overview of the task, each frame:
- Loop through entire map, setting “not visible” on each tile.
- Loop through all Actors, light up circle (r=3) around the Actor
- The “lighting up” procedure loops through 6*6 tiles, for a radius 3 circle.
I would very much like some input as to how this can be improved! I ruled out only updating the changing parts (as opposed to recalculating every point every frame), because a lot of the vision from actors close to eachother overlap. Because of this, I can not simply “turn off” the circle of vision around an actor.
Maybe I am missing something.