In tile based games you might need to workout if an enemy can see you, if your player can see past an object etc…
Ive based the demo on this http://roguebasin.roguelikedevelopment.org/index.php?title=FOV_using_recursive_shadowcasting_-_improved which is itself based on an article by Björn Bergström on the subject.
Here is the demo http://www.alienhorde.com/files/field_of_view.zip It requires Lime so you need to add all the files for Lime yourself.
It should also be said this cannot run in realtime, the code is just too much for LUA but it is useful in turn based games. My implementation is also running slower as im rendering a separate shadow mask to make a torch light effect.
In fov.lua change “local maskTileSize = 16” to either 8 or 4 to up the resolution of the shadow mask.
Hi Res Very Slow Calculation
Low Res Fast Calculation
This is an early demo of the code, any ideas how to speed it up would be great, otherwise help yourself and alter as needed.
A better implementation would be to alter the map directly rather than building the separate shadowmask as that is only the size of the screen and if there were not walls at the edges it would try to access values in the array which didnt exist and cause a crash. By scanning the full Lime map that would probably be avoided.
The images are for the demo only as I found most of them online and are not mine. [import]uid: 5354 topic_id: 8193 reply_id: 308193[/import]