Select Page

Level Generation v1


It was finally time to look at the level generation. There were several things on my mind when thinking through the process of level generation and the requirements the end result would require (also I love lists):

  • No too heavy from a performance perspective.
  • Can handle levels of any size.
  • Could be adapted to make endless levels.
  • The raw data of each level needs to be easy to store/retrieve.
  • Can’t end up with massive level data file sizes.
  • Able to handle multiple threads of data at once (terrain, background, powerups, obstacles and enemies).
  • Easy to create new levels and test different scenarios.
  • Automatically handle object pooling for all of the different elements.
  • Bonus points for being able to start/stop/restart a level from any point or endlessly play through multiple levels.

The system I created, which I ended up calling The Sewing Machine, is far from elegant or complex but it works and covers (almost) all of the points. The system itself is based on 5 lists (threads) of comma separated values. These are loaded in to the level generator as arrays, each representing an area of the game (terrain, background, pickups, obstacles and enemies). Each value in the array data reflects what to spawn and its position in the array decides when. When a set position in the array is reached each thread’s value is taken and stitched together in to the game.

For example, loading an array of (01,03,02,04) in to the generator for terrain would create a level with a long section, a crater, a short section and finally a ramp. loading an array of (00,00,01,00) for obstacles would then spawn a boulder on the short section of terrain.

A number of colliders and detectors around the camera’s visible area help manage the current position in the arrays and move objects in and out of their respective object pools.

The great thing about this setup is that any level can be restarted from any position or an entirely new level loaded in without the need for reloading the scene. Something I’d like to implement for people who want to play multiple prebuilt levels in a row without needing to return to the menu.

The one downside is that hand crafting the levels in just a text editor would be a nightmare. But I believe making my own level editor shouldn’t be too hard thanks to the simplistic nature of the level data being in arrays. A level builder could also be a fun addition for players and sharing maps wouldn’t be hard since they’d basically be just a small txt file of data.

Recon Auth Signing Out