ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.33k stars 254 forks source link

Generating map on the fly? #114

Open adiron opened 7 years ago

adiron commented 7 years ago

Hi there

So I'm experimenting with a certain idea for a roguelike with an "overworld" map type thing. I could in theory just generate a very very big map in advance and just use that, but I don't think that's necessarily the best idea, as the map could get very, very big. Unfortunately the map generators included require a width and height and will not generator for specific squares alone.

Any ideas on this?

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/43317585-generating-map-on-the-fly?utm_campaign=plugin&utm_content=tracker%2F297828&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F297828&utm_medium=issues&utm_source=github).
ondras commented 7 years ago

This is an interesting concept. And a pretty hard one, in my opinions.

Built-in generators in rot.js are certainly not well suited for this. You might be able to create one itself, but you will have to solve certain constraints -- in particular, the fact that generating a new part of a map shall not modify/influence existing parts.

Alternatively, you can use existing generators to create rectangular areas of your mega-map on the fly, connecting these tiled segments manually.

adiron commented 7 years ago

I think that the trick would be to use some kind of pure function that, given X, Y coords and a seed (which is the same for all iterations) will spit out a tile that when put together would make a nice map.

I haven't tried this, but for example Perlin Noise could maybe accomplish this?

I came across this page but it is far too mathematical for a designer like me.

ondras commented 7 years ago

rot.js has a noise implementation (ROT.Noise.Simplex()) that fits your requirements. The question is, how to convert this deterministic noise generator into a suitable map.

Several years ago, I made a proof-of-concept for this, using the noise function to create an infinitely large outdoor map. Check it out: https://github.com/ondras/railrl (playable version: http://ondras.github.io/railrl/)

This map is not stored in memory. Instead, every cell is evaluated "on the fly" by consulting the (deterministic) noise generator. If this works for you...

I am not sure how to correctly apply this approach to a traditional dungeon map with rooms, walls and corridors, though.

adiron commented 7 years ago

Thanks for your proof of concept. I managed to do something similar. Works great so far.

As for dungeon generation, I think that sticking to the good old generation style for that is fine. ;) It's mostly the outdoor map that's an issue.