Chapter 10: "Locked In A Dungeon"
Some details, ideas, and
musings I've had experiencing effective RPGs and RPG Makers
© April 2019 Written by David Wicker
Please do
not reprint without permission
Today's we're going to focus on Dungeons. Yep, those creepy, deep, dark pits which house all manner of monsters and treasure.
How to go about making one ?
Well, you can certainly build it yourself manually from a series of graphic tiles ... or, you might be more interested in writing code to randomly generate them.
This entry will not cover how to make your own where you determine where the walls and items are by yourself, no, it will cover two very important ways in which you can write code to randomly generate them.
This has several advantages. The primary being that if the player starts a new game, they are guaranteed a unique and random dungeon each time they play.
So what are the types of dungeons that can be randomly generated ?
The simplest being a maze.
Close off the top and bottom entrance and exits and you are all set. If the player is a sprite that is 32x32 pixels (single tile size) then make the walls and floors at least 96x96 pixels, or 3-tiles across and down.
To generate a maze like this, fill the entire map with walls and ensure the SIZE of the map is an odd number of tiles. Let's say, for instance, you wanted to build a maze in a 21x21 set of tiles.
Clear the whole map to the WALL tile, that is 0-20 and 0-20.
[1]
Check, are there any free spaces left to cut anywhere on the map ? NO ? GOTO [4]
[2]
Randomly pick a marker horizontally: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, always an odd number
Randomly pick a marker vertically: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, always an odd number
Is this marker on top of a WALL ?
NO ?
GOTO 1
[3]
Randomly pick a direction of Up, Down, Left, or Right
Check 2-spaces in that direction. Are both tiles in this direction WALL ?
YES ?
cut them out to FLOOR, put the marker on the last cut FLOOR tile, then GOTO 2
NO ?
GOTO 2 but pick a direction you have not tried yet
if ALL 4 directions have been tried with no success, instead GOTO [1]
[4] DUNGEON COMPLETE !
Now that you know how to make a maze, it's time to fill it up with good things.
Randomly place the following on a FLOOR tile:
[1] Stairs leading UP
[2] Stairs leading DOWN
[3] A collection of MONSTERS
[4] A smaller collection of TREASURES
[5] Some doors that require keys to open
[5] A small collection of TRAPS
[6] Maybe 1-2 very important ITEMS, but maybe not
[1] The stairs leading up will work the player towards the exit if it is a dungeon, and deeper into the dungeon if it is a tower. Place this tile on FLOOR. Also player can touch and cross it if they decide not to take these stairs.
[2] The stairs leading down will work the player deeper into the game if it is a dungeon, and towards the exit if it is a tower. Place this tile on FLOOR. Also player can touch and cross if they decide not to take these stairs.
[3] The collection of monsters can and should be invisible and match the level of difficulty this dungeon is. Only activate and enter combat if [1] player steps on top of, or if you want more aggressive action if the player enters within one square of. Then you can have multiple monsters attack at once. Place this tile on FLOOR.
Once this monster is defeated, they do not return. Player can cross this FLOOR tile normally.
[4] Treasures can be treasure chests and they might very well be locked, requiring a key to open. If they are trapped, a THIEF in the party may be able to disarm the trap first before the contents are removed. Place this tile on FLOOR.
Once this treasure is taken, the chest loses 50% alpha (image solidity, ghost-like, you can see the floor through it) and the player can touch and cross. They can also touch and cross if they decide not to open this chest. In no way should a chest EVER block a player from crossing over it.
[5] Doors are randomly placed ON TOP of the WALLS in such a way that they do not appear on corners. That is, they must have a normal wall tile either to the left and right or up and down. Doors are mere convenience helping the player travel through more of the dungeon and at a faster pace instead of taking the long way around as the maze might require.
[6] Special items could be a special item someone wanted you to retrieve, like a crown or palantir.
THOUGHTS:
You could set it so the stairs to the next level of the dungeon is guarded by a BOSS monster and perhaps this BOSS also carries an important item with it, that you gain - if you defeat it.
And there you have it ! A very basic dungeon indeed.
If you want rooms, you can follow this method:
This can be constructed by converting the map to solid wall, then build a room provided there is space, maybe anywhere from 3-tiles across to 7-tiles across and 3-tiles down to 7-tiles down. In that room, randomly pick a side of the wall, move out one step, cut that as a door, then create an adjoining room, also 3-7 x 3-7. Repeat the method of making a door. And do so until the map is filled.
Let's see this in pseudocode, like the maze making above.
For this example, let's make the dungeon sized 35x35, or 0 by 0 to 34 by 34.
[1]
Is there any more space to cut a room ? NO ? GOTO [3]
Randomly pick a point inside from 1-34 by 1-34.
[2]
Choose a room size from HERE - from 2x2 up to 5x5.
Is there enough space here to cut it with the first point being the top-left tile AND in it being drawn it does not touch any existing previous rooms (must have at least 1-space free all directions) ?
YES ?
Is this the 2nd or after room ? draw the DOOR tile now connecting from previous room.
cut out the entire room to FLOOR. Now pick an edge to this newly created room.
But it cannot be a corner of the room.
Move out one more space out. Remember this space to draw a DOOR but not yet.
Move out one more space (same direction)
GOTO 2
NO ?
GOTO 1
[3] DUNGEON COMPLETE !
Using this method of building rooms, you can add decorations to the inner walls like lit torches, debris you must circumnavigate, and possibly other graphical elements that make the player feel more at "home" and that this is an effective dungeon.
Here is a screenshot of a dungeon-maker I wrote years ago to show you how all the rooms connect to each other.
. . .
Next
we'll cover the topic of WARPING. Many RPGs have this, but how can it be done effectively ? What gets left behind when you do warp from one city to another ? How can the computer keep track of every place you've been and of your transportation ?
The answer to this and many other pertinent questions will be solved the following week !
Until then, bye for now ...