Dev Diary - Barnstorming Remake: Level Generator

All 3 levels of my Barnstorming remake are made by generating the level in real time.


From seeing the gif above, it shows that as the camera moves (following the player), new tiles are added and old ones are removed. Across the 3 levels, the way the levels generate are not that different, except for very small changes.

When the game starts, it generates the first 6 tiles. These tiles are all city tiles, which don't have any game elements on them and are just there to give context to the game. From then on, the game will spawn in forest tiles, which have a whole set of rules to determine what is placed where and how often.

Let's start by spawning in a tile...

Its position is determined by the last placed tile. We get the position of that and set our new tile's position to plus 10 on the x axis. This places it right next to the previous tile.

Then we check if a gas station should spawn on the tile.

  1. By default, the chance is 20%.
  2. If there was a gas station on the previous tile, then the chance is 5%.
  3. If there was a gas station on the previous 2 tiles, then the chance is 0%.
  4. We roll a random number and if it is less than our chance, the gas station gets placed.
  5. It's a 50/50 chance whether or not it will be placed on the top or bottom of the road, with a 30% weighting to the side that was not of the last gas station.
    1. So the last gas station was on the top of road, the next one will have an 80% chance to be on the bottom and vice versa.

If a gas station wasn't placed, then we check to see if we should place a fallen tree.

  1. Fallen trees have a 50% chance of being placed.
  2. If we can place one then we need to choose if it will be coming in from the bottom or top of the road.
    1. If the last fallen tree came from the bottom, then this one will come from the top and vice versa.
    2. It's an alternating pattern, so the placement is predictable.

No matter if there's a gas station or not, we check to see if we can place potholes.

  1. 50% chance to place one, 25% chance to place 2 on the same tile.
  2. If the level is Dusk, then there is a 10% more chance of placing them.
  3. If we do place them, their positions are determined by choosing a random X and Z position.
    1. This is done so that the final position is inside the dimensions of the road.

If this is the last tile of the game and all gas stations have been gone through, then we need to place the farmhouse.

  1. Pretty simple, this tile only has the farmhouse on it.