Procedural Maps

Posted by (twitter: @Local_Minimum)
October 30th, 2013 3:16 pm

In my personal slow-Jam I’m working on I decided to leave everything to Random and a few parameters.

Still there’s the need for levels, and the very basic requirements that everything should be connected, walled in and have a nice balance between narrow passages and open spaces.

There’s probably well known and better ways to do this, but any case, since I think the end result was more or less exactly what I wanted, I’m gonna outline how I did.

  1. Define an allowed geometry by normal sampling a width and height of the map (in tiles). I used a 2D boolean array as representation when doing the calculations
  2. Randomly seed some few (<1%, but more than ~7) positions so that each has a safety margin to the border of the array
  3. Iteratively connect dots by randomly selecting one not connected to the others and walk towards the closest other true position following Manhattan distance = 1 setting all passed positions to true.
  4. Repeatedly randomly select any edge pixel and randomly select one of its 4-neighbours that are unused and expand there.
  5. When sufficient number of tiles have been placed. For all edge tiles, place a wall in all unused positions with a chessboard distance of one

This is the result of three maps generated after one and other:
Cube Sphere Pyramid Lvl example 1

Cube Sphere Pyramid example lvl 2

Cube Sphere Pyramid example lvl 2

I only need quite small levels as each is only meant to last for maximum of 60s and the game is absolutely way too confusing to allow for larger levels, but in principle it would only require some parameter tweaking to get them too look quite differently.

I also like how one sort of can see where the seeds must have been placed.

Of course if anyone is interested in the code just let me know (it’s C# for Unity, and it’s not super-efficient by any means but since it’s only run at level start I figured it doesn’t matter too much).

Tags: , , , ,


2 Responses to “Procedural Maps”

  1. Qrchack says:

    Seems legit!

  2. lazyeels says:

    Nice work, definitely better than my procedural map algorithm. Would love a peek at your code.

Leave a Reply

You must be logged in to post a comment.

[cache: storing page]