procedural generation

Building an island

Each playthrough is on a unique, procedurally-generated map. The three islands below all came out of the same generator using different seeds.

The whole generator is a single C# script called WorldGenerator. It takes a library of hand-made pieces (sand chunks, grass and dirt tiles, trees, rocks, caves) and arranges them using a handful of simple rules. Along the way it checks its own work by raycasting straight down onto what it has already built.

Gameplay WIP

General gameplay. The game is a work in progress.

The algorithm

The island is built from the bottom up. Each pass works on top of whatever the previous one left behind.

  1. 1 Ground
  2. 2 Water
  3. 3 Terrain
  4. 4 Props

01

Ground: growing the island outward

It starts with a single spawn chunk at the centre of the world. Each new sand chunk gets a random rotation, a random scale and a slight random height. The generator then picks a random chunk that's already been placed as an anchor and chooses a random direction. Then it slides the new chunk outward from the anchor until their edges barely touch. If it lands on top of another chunk, it tries again with a new anchor and direction.

A new chunk being pushed out from a randomly chosen anchor chunk until their edges touch. anchor new

Since every chunk is attached to one that already exists, the land always comes out as one connected piece. Picking a random anchor gives the island a blobby, branching outline instead of it looking like a long snake. Chunks are also allowed to overlap a little: a spot is only rejected when two centres are closer than 90% of the touching distance, which hides the seams without piling chunks on top of each other.

02

Water

Once the land is down, the generator measures its bounding box, centres a water plane underneath it, and stretches that plane to three times the island's width so the sea runs all the way to the horizon. Ground below the water line counts as water, so the low edges of chunks naturally turn into beaches and shallows.

03

Terrain: grass and dirt on sand

Grass and dirt tiles follow one hard rule: a tile's whole footprint has to stay on sand. For each tile, the generator tries up to 40 random spots. At each spot it checks rings of points moving outward, six rings of twelve points each. The first ring that touches water marks the limit, which tells it how big a tile can fit there.

Rings of sample points spreading out from a spot on the sand; the fourth ring reaches the water, so the tile fits inside ring three. ring 4 hits water, so fit = ring 3

The best spot wins. If even the best spot is smaller than the tile, the tile is shrunk to fit rather than skipped. There are also a couple of soft preferences: stay away from the spawn point, and don't crowd other tiles. Those apply for the first 30 tries and are dropped for the last 10, so a tile doesn't get lost entirely on a small island. Each tile is also lifted 0.01 units above the previous one so overlapping tiles don't flicker against each other (z-fighting).

04

Props

Props such as trees, rocks and other decoration are grouped into layers, and each layer has its own rules: where it can go, the steepest slope it can sit on, the minimum spacing from every other prop, and whether it tilts to match the ground.

To place a prop, the generator tries a random point and keeps the spot only if every rule passes. Layers allowed "anywhere" search an area 30% wider than the island, so rocks can poke out of the sea. Layers run in priority order: big trees claim their spots first, then smaller decoration fills in around them.

Seeds

Every random choice in the generator comes from one random number generator started from a seed. Using the same seed guarantees the same island. This allows for easy testing, or to find good islands to play.