+1 vote

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?

asked May 29 in Engine by Allen Kennedy Jr. (70 points)

1 Answer

0 votes

There is an old tutorial in 2.1 called Fog of War:
https://github.com/godotengine/godot-demo-projects/tree/2.1/2d/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 fog.gd 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:
https://docs.godotengine.org/en/3.2/classes/class_rect2.html

answered May 29 by estebanmolca (1,201 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.