Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+2)

Super fun! A lot of the castles feel new and interesting, and if you don't mind me asking I'm curious as to how the levels are created?

(+2)

The levels are created from a mishmash of stuff; a lot of graph-algorithm things. I think this is code I started working on in 2009 or so; here’s a blog post: http://playtechs.blogspot.com/2008/09/villa-creation-first-steps.html. It’s been used to generate starship levels as well (with a more free-form set of rooms but keeping a symmetry axis).

The core of it is a grid of rooms. The number of rooms in each dimension is chosen by adding up coin flips (with the number of coins increasing with later levels), so there’s a fair amount of variation. In this version of the game there are ten mansions. It generates the number of rooms for all the mansions up front and then distributes 100 loot across the ten mansions in proportion to the number of rooms they have.

For a given mansion, I then offset all the walls randomly a bit, then go through every corner between four rooms and force either the horizontal or the vertical walls to line up. The inspiration for these are siheyuan, the Chinese courtyard houses, although the overall structure doesn’t end up very close to them. Still, it has the symmetry axis, the southeast entrance, and the private rooms at the back of the house. Courtyard rooms are randomly chosen; the private rooms are just the back half of the house or so, as measured by distance from room to room starting at the southernmost rooms. Room decoration is designed to get a bit less friendly for cover as you go toward the back of the house. Windows are just part of the room-decoration system, which has some templates for different sizes of rooms. Loot placement first distributes loot to dead-end rooms (it’s a law of games), then to private rooms (farther from the entrance), then wherever.

Guard patrol routes are built so every room gets visited by one guard. It shuffles all the room adjacencies, then assembles them into chains (which can become loops). Then it clips long chains into shorter pieces if necessary to try to hit the target guard density for the level, and finally inserts side-trips into any rooms that didn’t make it onto the chains. For any end room in a route it tries to pick an interesting place for the guard to go: a window to look out of, if there is one; a chair to sit on; or some loot to stand next to. If none of those are available it tries to walk a couple steps into the room. On later levels a couple of extra guards are added to patrol around the outside of the house.

The code’s on GitHub if you want to look at it: https://github.com/mcneja/7drl-2023/blob/main/src/create-map.ts It’s not the most elegant code, and has been hastily ported from Rust (which in turn was ported from C++). The guard patrol routes were the major new bit this time around.

Love it, thanks!