Difference between revisions of "Quick and dirty FOV/LOS"

From RogueBasin
Jump to navigation Jump to search
m
Line 5: Line 5:
== Pseudo-code ==
== Pseudo-code ==


<syntaxhighlight lang="basic">
 
For each block (assuming your roguelike map works in blocks, 99.9% of RL's do)
void DoSomeFov()
{
{
   if the block is within the players view radius
   For each block (assuming your roguelike map works in blocks, 99.9% of RL's do)
   {
   {
       draw a virtual line from the player to the block
       if the block is within the players view radius
      for each block on the line
       {
       {
         set it as visible initially
         draw a virtual line from the player to the block
         if it is a wall/door/object that blocks vision
         for each block on the line
         {
         {
             the block = non-visible
             set it as visible initially
            if it is a wall/door/object that blocks vision
            {
              the block = non-visible
            }
         }
         }
       }
       }
   }
   }
}
}
</syntaxhighlight>


== Other methods ==
== Other methods ==


This method worked fine in my RL, however, it may be more efficient (read: probably) to draw a line to each block that lays on the line of circumference around the player (the radius being view distance), and going through each block on the line and checking for blocking objects.
This method worked fine in my RL, however, it may be more efficient (read: probably) to draw a line to each block that lays on the line of circumference around the player (the radius being view distance), and going through each block on the line and checking for blocking objects.

Revision as of 17:42, 29 February 2012

Quick and dirty field of view/line of sight algorithm

This is a FOV algorithm i used in a C# roguelike i made for the learning experience, it is probably not as efficient as it could be.

Pseudo-code

void DoSomeFov() {

  For each block (assuming your roguelike map works in blocks, 99.9% of RL's do)
  {
     if the block is within the players view radius
     {
        draw a virtual line from the player to the block
        for each block on the line
        {
           set it as visible initially
           if it is a wall/door/object that blocks vision
           {
              the block = non-visible
           }
        }
     }
  }

}

Other methods

This method worked fine in my RL, however, it may be more efficient (read: probably) to draw a line to each block that lays on the line of circumference around the player (the radius being view distance), and going through each block on the line and checking for blocking objects.