This is a basic 2D world generator, implemented in TypeScript. I had the idea for this after playing MoonQuest.
A live demo is available here.
It features:
- Height map generation
- Cave generation
- Ores generation
- Trees generation
- Water particles simulation
git clone git@github.com:rgehan/2d-world-generator.git
cd 2d-world-generator/
yarn
yarn dev
It takes a few parameters, allowing to generate very different kind of maps:
size
, used to determine how wide the map is in term of blocks. The map is2^size
blocks wide.level
, the base ground level,0
is the lowest, while1
is the highestroughness
, how rough the map is.0
will produce a flat map, while1
would produce a very rocky mapmapHeight
, how high the map is in term of blocks. It's just used when sampling the heightmap function.
It takes an array of "steps". A step has a few parameters:
blockId
, which kind of block is generated by that stepsize
, the size of the ore veins (used to scale a Perlin noise function)amount
, the amount of ore in a given vein (used as a threshold for the Perlin noise function)
It takes a few parameters; they determine how many and how long the caves are:
count
, the initial number of cavesforkCapacity
, the number of times a given tunnel can split into two tunnels
Determine the quantity of liquids generated and how good it looks:
amount
, the quantity of water generatediterations
, how long the simulations run until we consider all liquid particles to have settled.
proba
, the probability a given grass tile will yield a tree.