{"assets":[{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample1-300x243.png","local":"\/data\/posts\/2013\/10\/5bacfa3c7e92abe8cc427977de853c44.png"}],"author_link":"author\/local-minimum\/","author_name":"local minimum","cat":"Uncategorized","categories":["Uncategorized"],"comments":[],"epoch":1383146160,"event":"","likes":7,"metadata":{"p_key":"80329","p_author":"local minimum","p_authorkey":"0","p_urlkey":"289339","p_title":"Procedural Maps","p_cat":"Uncategorized","p_event":"LD27","p_time":"1383146160","p_likes":"7","p_comments":"0","p_status":"WAYBACK","us_key":null,"us_name":null,"us_username":null,"event_start":"1377216000","event_key":"18","event_name":"LD27"},"source_url":"2013\/10\/30\/procedural-maps\/","text":"<p>In my personal slow-Jam I\u2019m working on I decided to leave everything to Random and a few parameters.<\/p>\n<p>Still there\u2019s 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.<\/p>\n<p>There\u2019s 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\u2019m gonna outline how I did.<\/p>\n<ol>\n<li>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<\/li>\n<li>Randomly seed some few (&lt;1%, but more than ~7) positions so that each has a safety margin to the border of the array<\/li>\n<li>Iteratively connect dots by randomly selecting one not connected to the others and walk towards the closest other true position following <a href=\"http:\/\/en.wikipedia.org\/wiki\/Manhattan_distance\" title=\"Manhattan Distance\">Manhattan distance = 1<\/a> setting all passed positions to true.<\/li>\n<li>Repeatedly randomly select any edge pixel and randomly select one of its 4-neighbours that are unused and expand there.<\/li>\n<li>When sufficient number of tiles have been placed. For all edge tiles, place a wall in all unused positions with a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Chessboard_distance\" title=\"Chessboard Distance\">chessboard distance<\/a> of one<\/li>\n<\/ol>\n<p>This is the result of three maps generated after one and other:<br\/>\n<a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample1.png\"><img alt=\"Cube Sphere Pyramid Lvl example 1\" class=\"alignnone size-medium wp-image-299260\" height=\"243\" sizes=\"(max-width: 300px) 100vw, 300px\" src=\"\/data\/posts\/2013\/10\/5bacfa3c7e92abe8cc427977de853c44.png\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample1-300x243.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample1-550x445.png 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample1.png 835w\" width=\"300\"\/><\/a><\/p>\n<p><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample2.png\"><img alt=\"Cube Sphere Pyramid example lvl 2\" class=\"alignnone size-medium wp-image-299261\" height=\"286\" sizes=\"(max-width: 300px) 100vw, 300px\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample2-300x286.png\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample2-300x286.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample2-550x525.png 550w\" width=\"300\"\/><\/a><\/p>\n<p><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample3.png\"><img alt=\"Cube Sphere Pyramid example lvl 2\" class=\"alignnone size-medium wp-image-299262\" height=\"300\" sizes=\"(max-width: 265px) 100vw, 265px\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample3-265x300.png\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample3-265x300.png 265w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2013\/10\/lvlExample3.png 584w\" width=\"265\"\/><\/a><\/p>\n<p>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.<\/p>\n<p>I also like how one sort of can see where the seeds must have been placed.<\/p>\n<p>Of course if anyone is interested in the code just let me know (it\u2019s C# for Unity, and it\u2019s not super-efficient by any means but since it\u2019s only run at level start I figured it doesn\u2019t matter too much).<\/p>\n<p>Tags: <a href=\"http:\/\/ludumdare.com\/compo\/tag\/c\/\" rel=\"tag\">C++<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/level-design\/\" rel=\"tag\">level design<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/procedural\/\" rel=\"tag\">procedural<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/procedural-maps\/\" rel=\"tag\">procedural maps<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/unity\/\" rel=\"tag\">unity<\/a><\/p>","time":"October 30th, 2013 3:16 pm","title":"Procedural Maps","title_was_empty":false}