Map generation

There are several map generator tools in rot.js; they all share the same usage pattern. You first need to instantialize the proper ROT.Map.* object and pass size (plus any additional relevant options) to its constructor; you can then call the main create method (repeatedly, if you want).

This toolkit does not force usage of any particular memory structure to store the map data. Instead, the map creation process is callback-based: you supply a callback function as an argument to the create method; the map creator will call your function repeatedly and pass it the generated map information. Your callback should accept these arguments:

These examples use the simplest map generator, Arena: a fully dug room.

var map = new ROT.Map.Arena(3, 3); var userCallback = function(x, y, value) { SHOW("Value %s generated at [%s,%s]".format(value, x, y)); } map.create(userCallback);

We can use ROT.Display to show the generated map (although it would make more sense to store the generated data as well). For debugging purposes, ROT.Display provides a built-in convenience method DEBUG, which works as a universal debugging callback.

var map = new ROT.Map.Arena(10, 5); var display1 = new ROT.Display({width:10, height:5, fontSize:18}); SHOW(display1.getContainer()); map.create(function(x, y, wall) { display1.draw(x, y, wall ? "#" : "."); }); /* debugging with small font */ var display2 = new ROT.Display({width:10, height:5, fontSize:8}); SHOW(display2.getContainer()); map.create(display2.DEBUG);

Read more about various types of generators: Maze, Cellular and Dungeon.