Stoikoon Game Development Stack Exchange • Recommends
On “More efficient way to implement Line of sight on a 2d grid with ray casting?”
I have implemented the algorithm suggested by Jimmy.
Video of the code in action here: link to this video
/*
What this code does:
Rasterizes a single Field Of View octant on a grid, similar to the way
FOV / shadowcasting is implemented in some roguelikes.
Clips to bitmap
Steps on pixel centers
Optional attenuation
Optional circle clip
Optional lit blocking tiles
To rasterize the entire FOV, call this in a loop with octant in range 0-7
Inspired by http://blogs.msdn.com/b/ericlippert/archive/2011/12/12/shadowcasting-in-c-part-one.aspx
*/
static inline int Mini( int a, int b ) {
return a < b ? a : b;
}
static inline int Maxi( int a, int b ) {
return a > b ? a : b;
}
static inline int…