Roguelike Aoc – part 22

In the twenty-second lesson of a roguelike game tutorial we still remain in the area of connecting doors. I’ve skipped a large part of the lesson as I’ve already implemented part of it. The details are below.

Move everything down

That is actually the thing that happened not in the beginning of the lesson but later. However, I think it’s important to do first as sometimes my current connecting/drawing solution just quits unexpectedly while rendering the level. It does not happen that often but still – it’s annoying. So in the createRoom function I’ve done changes the author did, but actually added 2 instead of 1 to the Y dimension (left 1 for X) and what is more – I’ve added them to the operation result.

   
/* offset */
newRoom->position.x += rand() % (29 - newRoom->width + 1) + 1;
newRoom->position.y += rand() % (9 - newRoom->height + 1) + 2;

With this change my code always runs and generates beautiful level.

Random door locations

Yup, that was already covered a long time ago. My code randomly generates doors in the rooms and then also randomly connects them with each other. The author also decided that all the doors must be connected (or at least tries to do this). IMHO this is not a good approach – no such thing exists in Roguelikes I’ve played like Angband or ADOM. I think that my solution that there are 4 connections is sufficient for the time being. It can be easily increased. What is more – I have no problems with actually getting to monsters and slaying them. So I did not introduce the changes that author suggested (with separate Door struct).

Code

Here is the direct link to the GitHub repo.

You Might Also Like

Leave a Reply

Back to top