HuvaaKoodia • on 1st Kajam entry Infested Zone

I made a simple room based level generator for Infested Zone. It is heavily inspired by the generator in Spelunky.
Here's how it ticks.

The generator

1. Create a room database

In the handy dandy CSV format. The first line designates the type of the room, which sides it contain doors (openings) on and if it can be rotated or not.

Room Base 1 1 0 0 r
w,w,w,w,.,.,w,w,w,w
w,l,w,w,.,.,w,w,l,w
w,w,.,.,.,.,.,.,w,w
w,w,.,.,.,.,.,.,w,w
w,w,.,.,.,.,.,.,.,.
w,w,.,.,.,.,.,.,.,.
w,w,.,.,.,.,.,.,w,w
w,w,.,.,.,.,.,.,w,w
w,l,w,w,w,w,w,w,l,w
w,w,w,w,w,w,w,w,w,w

Extremely easy to setup in LibreOffice Calc with conditional formatting,

Likewise easy to implement in Unity. Just read the file and split lines with comma as the separator.

(I'm not going to bore you with code)

2. Create a 5x5 grid

A multidimentional int array, nothing else is needed.

3. Set one of the corners as the goal

Just pick a random corner. No safeguards here.

4. Find a valid path from the center to the goal using random walk

Random walk: pick a random direction, keep track of positions already visited, back up if surrounded by walls or visited positions, stop if goal reached otherwise repeat. A recursive function works well here.

This results in all sorts of paths. At worst the whole grid is filled, but usually gives a pretty straight forward path. The random walk can be skewed towards the goal position by weighting the direction choosing part (I'm not doing this as you can see in the gif below)

5. Add a valid sequence of rooms to the path

Making sure the doors match. Other than that the rooms are completely random. This is where earmarking each room with its doors comes to great use.

6. Add random rooms to other positions.

The randomization can be weighted or otherwise limited here if the results looks silly. Rooms with less doors seem to work pretty well as they don't mess too much with the path.

Done deal!

Conclusion

The room database is the saving grace here. No need to worry about invalid connections or silly shapes as the rooms are authored by a human designer. Rotating them adds a surprising about of variation too and the FOV system hides the grid like shape of the level pretty well.

Comments

Wan
18 days ago

Thanks for sharing room generation process, it was a nice read. I should probably make one about mine, which ended with some interesting tricks as well.

The conditional-formatting-on-spreadsheet thing is awesome, I never thought of it as I'm more used to JSON and/or TilEd. It's definitely a technique I'll add to my repertoire.

HuvaaKoodia
18 days ago

@Wan
If you have the time, please do. Sharing tech is very useful for everyone involved.

JSON is a great, fire and forget, solution for a whole lot of tasks (save state, for instance), but when it comes to tilemaps I go for extreme simplicity. Soothes my programmer sensibilities and it just works!

The conditional formatting trick is something I learned many, many years ago from a friend of mine who uses Excel for everything. Spreadsheets, regardless of the program, are surprisingly versatile.

Login to comment