A New Adventure - Random Room Generation.


Hello!,

This project was produced as an interest to participate for the 32Bit JAM (We were the 11th place). Initially I joined with Zee and Marrow, however, it was just Marrow and I at the end since Zee couldn't continue. At the beggining I offered the idea to the team, and they both seemed interested in it. so I produced a Game Design Document (Here) so that we could be synched.

The idea was sparkled by the memories of those times I played Dungeons and Dragons, where you'd roll a dice to decide what would be the outcome of any type of action, from looting a corpse to battling a goblin. So, I just named it "Dungeon Dice" at the beggining since I didn't  want to spend much time deciding the name, I would later change it to "Dice Dungeoneer".

I have previously made a game where the rooms would be randomly generated creating a sense of never playing in the same dungeon. I though it would be easy to replicate this mechanic in a new game, but I came to realize I hadn't solved an issue and it was the issue of the room not generating again if you enter an area that already had a room in it.

It took me longer than I anticipated and I think this made it harder for me to finish the game on time. But I finally solved it and here's how.


First, let me explain the problem, and then, I'll tell you what was the solution. 

The idea was for each room to have four different "doors" or entryways: North, East, South and West. Whenever the player steps into one of them, the next room would be created. All that was good, but the issue comes when the new room also has its own "sensors" for each cardinal point. So, if the player initiates in a room and goes north, the next room will load, but the south detector of the new room would be touched and that would load a new room just on top of the room that the player would be coming from.

To avoid this from happening, my solution at the time, was just to make a code that would get the player's position and then remove any collider or sensor that was within the area, so, if the player goes north, we run that code and the south sensor from the new room would be removed... however... a second problem came into light.


So, this other problem... comes when you go back into a previous room, but not from the door or entry you have already used but a different one. In the picture above, the player initiates in the room with the orange square, when going north, both the north sensor of the current room and the south sensor of the next room are removed and the player can move into the next room, same thing happens when going west and then going south.

But now, since the east sensor of the final room and the west sensor of the initial room was never removed, if the player decides to go east on the last room, the next problem will show when a new room is loaded on top of the initial room. I can't remove the east and west sensors since I didn't enter through that entry, so what would then be the solution? Dictionaries.

The closes thing I know to a Dictionary is an array. But let me explain it in easy terms, as I understand it. A dictionary is like a safe box. Imagine you have a key for this safebox, and inside the safebox, you have whatever you want to keep, in my case, it could be coordinates, the name of an asset within the engine, it could be the position of the player, it can be many things. So, now imagine the safe box, is inside a bigger box, and it can be organized by the keys of each safe box.

In GDscript (yes, I used Godot), your keys for each safe can be integers, vectors, floats, strings, node names, etc. So what I did, was storing the position of each room. as the keys for my dictionary. So to give you a much more clear idea, it would look somewhat like this:

var Rooms : Dictionary = {}

where:

"var" is the way for me to initialize the variable.

"Rooms" is the name of my Dictionary.

": Dictionary" is the way for me to tel GDScript that this type of variable is a Dictionary.

"= {}" this is to say that my dictionary will initiate empty.

So, when the game initiates, and the first room is loaded, the empty Dictionary would change to something like this:

 Rooms = {
    (0,0,0) : 0
}

Meaning that the key is (0,0,0) which is the position of my first room, and the "contents" of the safe box, in this case, is just the integer 0. So, following the path that the player is taking the second picture, the Dictionary would look like this:

Rooms = {
    (0,0,0) : 0,
    (0,0,-1) : 1,
    (1,0,-1) : 2,
    (1,0,0) : 3,
}

Once the player reaches the green sensor (East one from the last room), the code checks the position that the new room will have, and if this is already existing as a key in my Dictionary, then it will not create the room and just erase the sensor. The same thing would happen if the yellow, or the one in the west from the first room is touched.

Ok, so in a very (VERY) sumarized way, this is how I solved the problem of having multiple rooms getting loaded on top of other rooms. I hope this has been somewhat entertaining to you. I will continue to work on this game, since it wasn't finished. However, I'll move the project to Godot 4.2 (it was made with Godot 4.0). I will also try to upload the project to github, please, look forward for more updates since, as you may see in the GDD, there was much more to this game, and I plan on at least completing everything that was written there. 

Thank you and good bye.

Files

Dice Dungeoneer.exe 101 MB
Dec 24, 2023
Dice Dungeoneer.dmg 83 MB
Dec 24, 2023
Dice Dungeoneer.zip Play in browser
Dec 24, 2023

Get Dice Dungeoneer

Leave a comment

Log in with itch.io to leave a comment.