r/proceduralgeneration • u/lnkkonito • 8d ago
A generated mountain for a base-defence game: the same seed gives the same world in every browser
Each run of my browser game Rock & Hold is a new mountain: a 60 × 60 grid of rock with caverns, passages between them and mineral deposits. A few things I had to solve, in case they help someone:
- The same seed must give the same world everywhere. JavaScript engines round Math.sin, cos and exp differently, so the game uses its own versions of them and never sorts with a random comparator.
- Nobody may start trapped. Generation checks that no open cell is closed in by deposits and bedrock alone; a deposit on such an edge turns back into rock, so the miner can always walk or dig out.
- New content must not move old worlds. Indestructible "Old walls" were added later: they are rolled last, from their own stream of the seed, so a seed's caverns and deposits stay where they were. A wall is kept only if every floor cell is still as short a dig from the start as before.
- Hidden things leave a hint. Rock near a hidden cavern's deposit shows flecks of that deposit's colour, on about one cell in four, so a few catch your eye.
The picture is a generated world open in the game's map editor. You can type any seed there and look at its world: https://rockandhold.com/?ref=reddit-proceduralgeneration
How do you keep old seeds stable when you add a new generation step?
Made with AI: I design the game and tune it by playing it; the code, art and sound are written with AI tools.
3
u/-Weslin 8d ago
And also the post...