Procedurally Generating a Animal Crossing World - Part 1
Procedurally generating an environment is a very interesting problem and the process very much depends on what kind of result you want.
In this case I’d like to replicate the generation process for the Gamecube version of Animal Crossing, which means:
High ground / low ground seperation
Fully connected plots of lands
Constraints on placement of Points of Interest
In this article I’ll be looking at generating a mask for high ground / low ground for a grid, since it is the most important and the most defining feature for these maps.
In AC on Gamecube, the player arrives at the train station which is located at A3. All maps show high grounds on the first 2 rows of the map (A and B), while subsequent rows are either low ground or high ground. It is important to note that a cell can only be high ground IF the cell above it is also high ground.
It seems then that we should start with setting the top most row or two as high ground, and then employ an iterative process that draws at random whether the cell is high ground or not.
The setup is pretty simple: we create an array of int (or bool), fill up the first row, then we go row by row, column by column to draw the type of ground. We’ll add a little bonus: we don’t only check the cell directly above the current cell, but also the one on top-right and top left. This allows us to get a smoother look, with less chances of having a single column being all high ground and seperating the map in two.
How we do this is simple: we track whether the tiles above the current one are high ground or not and increment a score (for example if we’re going to draw for B2 and A1 is high ground, then score += 1, else score stays the same).
This score is an integer that then serves as an index to an array of probability thresholds: if the current cell has a score of 3, then we draw a random number and compare it to the defined threshold for a value of 3 high ground neighbours. If the number is below the threshold, then it is considered to be high ground.
Here’s the result, visualized by instantiating cubes:
Playing with the draw thresholds can vary the map shape. The code below enforces 1-padding for out of bounds cells and spawns cubes when calling Run. Editor code is below as well.