Roguelike AoC – part 21

In the twenty-first lesson of a roguelike game tutorial we fix the ‘going through walls’ problem.

Piece of cake

The main thing to start with actually here, was to fix usage of Y variable in the while loop at the end of pathFind function.

Second thing to do was to add checks for addNeighbours function. I was thinking about using canGoToPosition function that we already have for monster/player movement. However, the problem is that this function check specifically for the ability to go to some position. Empty spaces in which we create room connections does not qualify. I’ve decided then to create new function that will be used to check if a floor can be put in the specific location. For doors, I allow it, the only no-go location are walls.

bool canDrawFloorOn(int y, int x) {
   return mvinch(y, x) != *WALL_SIGN;
}

Usages of this function where added to every IF statement in the pathFind function. Run, and it works! The beauty of this success is unfortunately a little shadowed by the fact, that our door signs are being overridden by floor printing. To avoid such problems I’ve modified the drawing loop to look like this:

// This check is not that great (there could be more locations that should not be overridden by this algorithm but for the time being it will suffice
if(mvinch(y, x) != *DOOR_SIGN) {
     mvprintw(y, x, FLOOR_SIGN);
}

I’ve also removed getch function call there and increased the amount of connections we want in the dungeon in the roomsSetup function (to four connections in total). That will actually be resolved in the next lesson (I’ve checked what’s there already).

Code

Here is the direct link to the GitHub repo.

You Might Also Like

Leave a Reply

Back to top