BenMakesGames.FoV 2.0.0

Prefix Reserved
dotnet add package BenMakesGames.FoV --version 2.0.0
                    
NuGet\Install-Package BenMakesGames.FoV -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BenMakesGames.FoV" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BenMakesGames.FoV" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BenMakesGames.FoV" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BenMakesGames.FoV --version 2.0.0
                    
#r "nuget: BenMakesGames.FoV, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BenMakesGames.FoV@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BenMakesGames.FoV&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BenMakesGames.FoV&version=2.0.0
                    
Install as a Cake Tool

What Is It?

BenMakesGames.FoV is a collection of field-of-view algorithms designed for square tile grids. It features the following algorithms:

  • Diamond-wall
  • Milazzo's Beveled-wall
  • Raycasting
  • Shadowcasting

Field-of-view/line-of-sight is useful for roguelikes, and other tactical, tile-based games where vision plays an important role.

🧚 Hey, listen! You can support my development of open-source software on Patreon

How to Use

Install

dotnet add package BenMakesGames.FoV 

Create a Map

Your map must implement IFoVMap, which requires a single method: BlocksLight(int x, int y). This method should return true if the tile at the given coordinates blocks light (is opaque), and false otherwise.

For example:

public sealed class MyMap: IFoVMap
{
    public int Width { get; }
    public int Height { get; }

    // store your tiles however you want; here's one possibility:
    public MyTile[] Tiles { get; }

    // BlocksLight is the only method required by IFoVMap
    public bool BlocksLight(int x, int y)
    {
        // treat out-of-bounds tiles as opaque
        if(x < 0 || x >= Width || y < 0 || y >= Height)
            return true;

        return Tiles[x + y * Width].IsOpaque;
    }

    ...
}

Another common implementation is to use a Dictionary<(int X, int Y), MyTile> collection to store the map. In that case, your BlocksLight method might treat missing keys as opaque (walls) or transparent (open space), depending on your game's needs.

Call One of the FoV Algorithms

All of the algorithms have the same signature:

HashSet<(int X, int Y)> Compute(IFoVMap map, (int X, int Y) origin, int radius)

They take a map, origin point, and sight radius, and returns a set of points that are visible from the origin.

Basic usage:

var visibleTiles = DiamondWallsFoV.Compute(Map, (Player.X, Player.Y), Player.SightRadius);

for(int y = 0; y < Map.Height; y++)
{
    for(int x = 0; x < Map.Width; x++)
    {
        if(visibleTiles.Contains((x, y)))
        {
            // tile is visible; draw it!
        }
        else
        {
            // don't draw the tile, or draw it as a fog of war tile
        }
    }
}

When implementing field-of-view in your game, you should only compute a new field of view when the player moves, or the map changes (such as a door opening or closing).

Available Algorithms, and Their Features

  • DiamondWallsFoV
    • Relatively fast algorithm. Compared to other algorithms, reveals more tiles in a given sight radius.
  • MilazzoFoV
    • Medium speed; designed to have intuitive lines of sight, especially for maps which contain many single-tile walls/pillars.
  • RayCastFoV
    • Slowest algorithm, with occasionally unintuitive lines of sight. Not generally recommended; included for historical reasons.
  • ShadowCastFoV
    • The fastest algorithm of the bunch, especially when used in large, open spaces with large sight radii.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 105 2/2/2026
1.1.2 310 2/3/2024
1.1.1 330 4/16/2023
1.1.0 312 4/16/2023
1.0.0 321 4/14/2023