4
\$\begingroup\$

I am developing a Roguelike in JavaScript using ROT.js. I'd like to keep with traditional gameplay (permadeath, randomly generated dungeons/mobs/items), but I want to have a statically defined overworld with randomly generated dungeons beneath.

Currently, I use the TILED map editor to create my overworld map and export it to JSON/JS format and import/parse the map into my game. For randomly generated dungeons, I use ROT.js's built in dungeon generator tool to create dungeons that are in the same JSON/JS format that the TILED maps are in.

The issue I am facing is finding an efficient way to store these maps and levels once they are generated, alongside the overworld. Right now, I just throw the generated maps into a JavaScript object indexed by the name of the map. Here's an example of how I do this currently:

levels = {};
// map class parses TILED map json and creates actors based on ascii
let map = new Map(TiledMaps["overworld"]);
levels["overworld"] = map;
let dungeon = new Map(randomMap(...)); // random map generates tiled map
levels["dungeon1"] = dungeon;
// to switch levels, just set the current game map
Game.map = levels["dungeon1"];

Is this a good approach? I would like to consider the possibility of having different types of dungeons. So, in the overworld, you might visit different sections of the world and those have different dungeons. Something like Link to the Past perhaps? Any advice?

\$\endgroup\$
  • \$\begingroup\$ Link to the pas had to maps, the overworld and everything else. \$\endgroup\$ – Bálint Jun 18 '17 at 19:01
2
\$\begingroup\$

I see nothing fundamentally wrong with your approach. Just a few thoughts:

Map is a pre-existing javascript data type. So unless the code in your answer actually uses this type of Map, you probably want to rename your custom data type to something unique, e.g. DungeonMap or similar.

JSON is a good format because it has little syntactic overhead and is also very well readable by humans. It should be totally sufficient for reasonably sized maps created by ROT. You could even store the maps in the browser of the user via localstorage so you don't have to reload it every time from the server, although it's probably a good idea to store it serverside as backup and create a hash so you can check if it has been manipulated.

Depending on the size of the dungeons, you might want to keep them in separate objects so you don't have to load the entire gameworld object, but rather load the data only when it is indeed needed.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.