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.**

- By default, the chance is 20%.
- If there was a gas station on the previous tile, then the chance is 5%.
- If there was a gas station on the previous 2 tiles, then the chance is 0%.
- We roll a random number and if it is less than our chance, the gas station gets placed.
- 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.
- 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.**

- Fallen trees have a 50% chance of being placed.
- If we can place one then we need to choose if it will be coming in from the bottom or top of the road.
- If the last fallen tree came from the bottom, then this one will come from the top and vice versa.
- 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.**

- 50% chance to place one, 25% chance to place 2 on the same tile.
- If the level is Dusk, then there is a 10% more chance of placing them.
- If we do place them, their positions are determined by choosing a random X and Z position.
- 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.**

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