Roguelike AoC – part 20
In the twentieth lesson of a roguelike game tutfifthorial the time has come to actually implement the pathfinding algorithm that was described in the previous one.
A couple things to start with
To be honest there was not much to do in this lesson. I mean – besides following the coding and just incorporating it into the current code base there was not much else to do. Of course, I had to add new pathfinding.c file to the code and let CMake know about it.
What is more – the constants (MAX_WIDTH and MAX_HEIGHT) had to be added, but I’ve used macros to do that and put them in rogue.h file among all others.
To make the added algorithm work with my Location struct I’ve changed the signature of a method not to get Position pointers but just the structures. We do not change the values in these parameters so there’s no point for them to be pointers.
I’ve substituted the code in roomsSetup function to be:
Then I’ve run the program. It worked! However, right now all the beautiful defensive programming I’ve done to not allow path go through walls and overriding doors is wasted. What is more – the connections are sometimes making the level look like after bomb went off. Wanted to actually do something about it but learning from my mistakes – I’ve checked what’s the topic of next lesson. Yes, You’re right – we will be fixing this problem. So I’ve let it be for one day 😉 For now I’ve settled for removal of connectLocations function.
Here is the direct link to the GitHub repo.
Leave a Reply