How to do map discovery on with a tilemap (Shadow Casting?)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Allen Kennedy Jr.

Here’s the scenario. I want to have a grid based game, like a roguelike where you don’t see anything to start. When the player is placed, he can see the room he is in and the walls of it, As the player moves through doors and hallways, they each uncover themselves on the map.

This is a very common feature of roguelikes and dungeon crawlers. where you can only see what the player character has been able to see.

I’m trying to do with with 2 tilemaps. The first map has the floors and walls. The second map has only black tile covering everything.

I was thinking shadow casting was probably the solution, where every time the player moves, you clear the black tilemap grid cell based on what is hit from the shadow cast. Implimentation of this is non-trivial to say the least. Requiring manual line algorithms, and complex vector math.

So, I fooled with that for a while and gave up because all the resources on the web gloss over the real details, “Just use the front facing edges” or “figure out which vertex is closest” with no explanation how to do those things.

Currently I’m trying to cast a ray to each of the 4 corners of every tile in the map, and where it hits, I uncover. This is good for the walls, but I haven’t yet figured out how to uncover the floor. That is, how to find all the cells from the player character to the ray collision point. I thought about creating a polygon, and checking if each cell is in the polygon, but Polygon2d doesn’t have a “has_point” function… so I’m stuck.

Am I going down the wrong path all together? Am I making this harder than it needs to be? Or Do all Roguelike devs deal with this crap?

:bust_in_silhouette: Reply From: estebanmolca

There is an old tutorial in 2.1 called Fog of War:

From what I see it is something similar and maybe you can adapt it to your game.
You can look at the script or download godot 2.1 and test the scene, because I don’t think it will work in the latest versions.

Regarding the has_point function, it is included in Rect2: