My algorithm is not very efficient but it works. (so many loops, but it still generates larger maps in some milliseconds)
- Fill a 2D array with zeros (type: integer, 0 means nothing to place there)
- Set the place of the starting room (for example at [5,5])
- Select a random array element in this 2 dimensional array.
- If the selected element has a room next to it, make a room there! (fill the array element with not zero, I think different rooms will have different numbers, 0 will be the starter room where the player will spawn, 1 will be one room type, 2 will be an other,...)
- If there is no room next to the selected element, do step 3 again. We shouldn't make room if the selected empty place has 2 or more neighbours! This will make the level a little bit different (figure 1, 2nd image)
- Do it until we want: if we want 15 room we need to do step 3 until we have 15 rooms (don't forget, we already have a starter room!)
Dungeon Generation algorithm - two different setups:
About the doorway generation, read this article: http://ap-p.blogspot.hu/2012/07/doorway-generator-is-almost-done.html
ReplyDeleteThank you so much :)
ReplyDelete