Home | Rules and Guide | Sign In/Create Account | Write a Post | Reddit | #ludumdare on irc.afternet.org (Info)

Thanks for making Ludum Dare 26 AWESOME! See you in August!

Ludum Dare 26 — April 26-29th, 2013
[ Results: Top 100 Compo, Jam | Top 25 Categories | View My Entry ]
[ View All 2346 Games (Compo Only, Jam Only) | Warmup ]

[ 10 Sec Video Compilation (x3) | 260 Game Video Compilation | IndieCade Deal | Ludum Deals (Unity Deal Ends Soon!) ]


Generating a random map for my game

Posted by
August 21st, 2011 5:54 pm

I’ve dabbled with this a bit in the past, using a grid to randomly generated rooms in a 2d game.

I used a very overly complicated process before, I started with a two dimensional grid and I converted each room into a symbol that stood for a different type of room, then when I tunnel through that room, converted it into another variable ie “T” = a room with only a top wall, and X would be a room with no walls etc…

I completely scrapped that idea this time around! And I couldn’t be happier about it.  Instead I made a 3 dimensional array of bools.  two dimensions for X / Y (or x / z as it is in unity) of the map, and then the 3rd held 5 bools, one for floor, and then one for each wall.  North / East / South / West etc.  I then start up with a new array that is all false, start off somewhere, and start tunneling my way one section at a time. I made a function that will go from one tile to a next, if there is no floor, it generates all the walls + floor, and then it breaks down walls connecting the two rooms.   I found this so much easier than my old method, as I didn’t have to make a ton of cases to handle changing different rooms.

Also this time, I made a system that adds on some branches after the first tunneling function runs . I look for a random tile that has a floor, then I check for any tiles next to it that have no floors, put each result with no floor into a hastable, and then randomly choose one of those to move to- and continue doing that to make some winding tunnels that go until they get stuck, which added some very nice variation to the maze.  The best part about this system, is I’m pretty sure I could easily make  a 3 dimensional maze by just adding one more bool and dimension to the array and changing the randomization around a bit, which I will most likely try out sometime in the future.

Leave a Reply

You must be logged in to post a comment.


All posts, images, and comments are owned by their creators.

[cache: storing page]