Saturday 2 June 2012

Ground Rules

It looks like it's time for my first tech post. Today, I'll be talking about how I like to set up random/procedural worlds for endless-world games, such as We Want YOU and its upcoming sequel, They Want ME.

The goal of map generation in WWY was to make every area look unique and random, while still always having an available path. We don't want people getting stuck in pits and having to restart the level.

In WWY, the system wasn't perfect. People could, in fact, get stuck in pits once in a while. We ended up adding the C4 item for this reason. It wasn't a weapon and it took too long to explode for it to be "fun" to use often. Its purpose was to get players out of otherwise inescapable situations.

TWM uses an altered version of the same system, which removes those inescapable situations from the game and allows the player to move upward, whereas WWY always had the player move downward.




Above is a shot from my current, work-in-progress, procedural game (the potential remake of WWY that I mentioned in the last post). The map is a grid of cells, in this case 8 blocks wide and 8 blocks tall. I find that using fixed grid cells works well when spawning new areas, because I know that there won't be any unintentional overlap.

Anyway, each cell has its own "chunk type". These aren't Minecraft "chunks" or Spelunky-style ground configuration. These are essentially rulesets for how to fill a cell with ground. Spacing and sizes aren't fixed values, but are instead set up as ranges of allowed values. This is how I ensure that no pit is inescapable, and make it more likely that a path upward will occur somewhere.

There are currently three types of chunk:
  • Parallel Floors
  • Parallel Walls
  • Trough
  • Tree

Parallel floors are what they sound like, and spacing is set up so that you will often be able to jump up to the floor above. Note how a path upward is formed, despite not "forcing" the code to generate such a path.


Parallel walls are vertical strips of ground with spaces between. I like the look of those, and they allow you the choice of either jumping from top to top or falling between.


Troughs are made in a "U" shape, with variable width and the sides being 1 to 3 blocks high. I've set it up so that if one side is 3 blocks high (ie. impossible to jump up), then the other side has to be lower. You can't get stuck that way. I may add water to the troughs at some point. We'll see.


Tree structures are made up of a vertical "trunk" with horizontal "branches". The upper branches are usually, but not always, shorter than the lower ones so that you can use them as stairs. I also allow branches to be disconnected from the trunk. I felt like forcing them to be attached would make every tree structure look essentially the same, and that didn't mesh with my goals.


There's still some work to do, but the terrain so far is quite varied. I think I'm going to add some "noise" (ie. random blocks and holes) to improve the chances of upward paths being generated.

WWY was very random, but this version of my terrain-generation code has more rules and more thought put into it. Decor- and enemy-placement will be similarly rule-based, with trees where they make sense and snipers placed on ledges with no chance of hiding in holes.

I think that's it for my first tech post. Feel free to comment, ask questions or give suggestions.

No comments:

Post a Comment