Skip to content

Instantly share code, notes, and snippets.

@fidel-karsto
Created June 21, 2013 21:27
Show Gist options
  • Save fidel-karsto/5834468 to your computer and use it in GitHub Desktop.
Save fidel-karsto/5834468 to your computer and use it in GitHub Desktop.
Pseudocode for field of view determination. Quite slick - real life example: http://noelfb.tumblr.com/post/53528361309
// from http://roguebasin.roguelikedevelopment.org/index.php?title=Eligloscode
void FOV()
{
float x,y;
int i;
CLEAR_MAP_TO_NOT_VISIBLE();//Initially set all tiles to not visible.
for(i=0;i<360;i++)
{
x=cos((float)i*0.01745f);
y=sin((float)i*0.01745f);
DoFov(x,y);
};
};
void DoFov(float x,float y)
{
int i;
float ox,oy;
ox = (float)PLAYERX+0.5f;
oy = (float)PLAYERY+0.5f;
for(i=0;i<VIEW_RADIUS;i++)
{
MAP[(int)ox][(int)oy]=VISIBLE;//Set the tile to visible.
if(MAP[(int)ox][(int)oy]==BLOCK)
return;
ox+=x;
oy+=y;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment