Before I move to the next step, let’s do some theory about the next topic. A field of view (or vision) is actually what the player (current unit) sees on the map from his current position. I will implement the whole FOV calculation in three steps, because every step method can be used also later on to add more interesting mechanics. The steps are:
- Show only tiles which are around the unit’s current position for a given viewing distance (radius). Practically we must construct a circle around the player and show only tiles that are inside the circle. Interesting features can be added here; for example, unit’s viewing distance is longer when the unit has a equipped flashlight. The same method will be used later to calculate the radius of a explosion.
- Do not draw tiles which are behind unpassable tiles (walls, closed doors… etc). To do this we construct a line from the unit’s current position to the tile’s position that we are testing using the Bresenham’s line algorithm. If we find a unpassable tile on our way, the destination tile can’t be seen from unit’s position. The same method will be used later to detect if a enemy unit is in our line of sight.
- Do not draw tiles which are behind the unit by taking into account unit’s current heading. Well, this is self explanatory.
Today I managed to implement the first method and I tested it by blowing a part of the map (finally some action). The line algorithm for the second step is also finished and successfully tested.
