Created
June 21, 2013 21:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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