# How to do FoV similiar to Nethack? [duplicate]

This question already has an answer here:

I am currently writing a little roguelike and wondered how Nethack/other games do the FoV of the player. I had a look at Nethacks source code, but since it's C it's pretty hard to read.

For people who don't know how it looks in nethack:

I couldn't find good resources on how to achieve this result.
Of note is that my maps are a little more complex with regards to shape and objects that block sight.

So how would I actually implement that? Map is just an array of ints.

I figure I should have flags on each cell saying if it's been discovered or not, but how to I simulate the FoV?

-

## marked as duplicate by Josh Petrie♦, Byte56♦, Trevor Powell, bummzack, Sean MiddleditchFeb 17 '13 at 20:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

## 2 Answers

This is a very similar question to one posted just today: Cast ray to select block in voxel game

Basically, you could implement the Bressenham's Line Algorithm and cast rays from the player's location to all the possible tiles. If the ray intersects a wall, then given tile is not visible.

-
If the outer wall is closed, you can also cast rays to each point on the wall. Depending on layout, this may be more efficient. – MSalters Feb 15 '13 at 13:10

I wrote an article recently on how to do field-of-view calculations. That article shows an implementation for a slightly different type of map then the one you would have in a Nethack map but the basic math should still apply.

Basically I ray-cast from the observer to via the edges of obstacles to the extents of the visible area and then calculate and area that would be obscured from the observer.

The article can be found here; http://www.codeproject.com/Articles/545808/Visual-concealment-for-games-using-Javascript

And there's an JsFiddle over here if you want to play around with it.

-