dangrnoodl logo

1 October 2022 ~ 3 min read

Tunnel Walls


Tunnel Walls

In the last post I briefly mentioned how the current field of view implementation didn’t look great because we had no walls around our tunnels, and how the fix would not be entirely trivial. Well, that didn’t turn out to be correct, but I didn’t know it at the time. So, I started recording what I anticipated to be a long journey only to reach the goal much faster. The upside is, this will be a short post.

The visibility algorithm works well, but our problem started with the tunnel tiles being a single tile wide and a single tile high. The void around these tiles shows up as black, which is a bit jarring.

Our problem, tunnels in the void

The goal in this post is to place wall tiles around all tunnels. I suspect this will be harder than I think to do well and cover all edge cases, but let’s see how far we get by doing the naive thing first. For every tunnel, we go through each tile and place walls at each of the 8 adjacent tiles unless placing a tile means we overwrite an existing tunnel.

First attempt

That didn’t work well. For some reason we now have a bunch of wall tiles in the middle of the room.

You might remember from previous posts that our tunnels start and end at the center of the room. We’re now replacing room floor tiles with our new walls. Let’s fix this by skipping any floor tiles.

Skip any floor tiles

This is better, but our door and surrounding tiles have now been replaced with walls too. We need to skip any doors.

Skip doors too

Hmm, what’s happening here now? Our door is skipped correctly. We need to skip the room walls, which makes sense. But, why don’t we get walls around the tunnel tiles? Oh, it’s probably because the black tiles are actually no tiles at all. This would return null instead of a tile and is probably messing up our code.

Replace null tiles with a wall

There we go. Actually, it looks like this is it. I expected more edge cases but I haven’t found any yet. Once there’s more tiles involved it’s likely we’ll have to come up with a better system to tag what tiles should be replaced, but until then, this will do.