Sunday, August 5, 2012

Procedurally Generated Dungeons (Includes GM implementation)

[This article will be appearing in indie(Magazine); which comes out of hiatus this weekend.]

In this article, I will explain how to procedurally generate a dungeon. Most of the work is in the implementation, not the concept. First, let's think about how a dungeon (The crawl type, not the prison type) would work in the real world. There would be various rooms of different sizes to hold monsters and treasure, and hallways to connect them. With that in mind, let's begin coding. The first part to creating our dungeon is to set up an array. It should be a variable width and height and filled with 1s, which represent walls. Then, create a function to add "rooms", which will clear out a random rectangle and record the center of that rectangle in an array. Next, write some code to connect all of these center points with two-tile wide "hallways". For displaying your new dungeon, simply create a function that loops through the array and draws each tile if it's a wall. You could also create more numbers, such as a "2", for storing other tiles. You might also want to create a player and give it x and y variables, then place it in the center of one of your rooms.

Let's look at how you can do this in different languages.

GameMaker:
-Read this in Indie Magazine out this weekend-

No comments:

Post a Comment