Procedurally Generating Worlds
Welcome to our dev blog! We’re going to try to update this at least a couple of times a week depending on what we’re working on. As CodeSpells revolves around the idea of teaching, we feel that we should be open about the development process and describe what we’re achieving, and more specifically how we’re doing it.
Over the last two weeks, I’ve started working on the procedurally generated worlds for CodeSpells. These are currently relatively small fixed size maps 512m x 512m, with some simple layered aspects of procedural generation. We hope to grow the size substantially but for now, we want to build the general framework for the engine we’ll be using. In most games, the procedural generation would come much later in the development process, but we feel that creating a functioning world with working systems is integral to how we structure the magic you’ll be able to use in the world of CodeSpells.
First off, I am not an expert on procedural generation, and this will not be a super technical write-up, but I want to give a general overview of the topic and what I’ve learned these past weeks.
One of the most important rules of making games is to cheat wherever possible. Games are intended to create a world that is convincing to the player, but that clearly defines a set of rules and doesn’t break them. Computers have limited power and can’t simulate everything all at once, so you have to focus on what is important to the game. At the same time, you want the player to have freedom, but you can’t simulate everything in the world and make it feel right. Imagine a game where you could control the legs of your character with incredible detail. This could be incredibly fun (see QWOP), but it doesn’t make sense in any game that isn’t specifically about controlling each leg. If your game is about being a fighter pilot, it wouldn’t make any sense to have the legs of the player be simulated in such detail. Moreover, if you never see the pilot, you wouldn’t want to simulate anything relating to the player’s body at all!
For that reason, most video games have static worlds. The mountains, rivers, trees, houses, etc. don’t change, but what you do in it and what happens does. A game like Skyrim basically gives you a world to play in. It’s an incredible world with immense detail, but you don’t have any control over affecting the systems of the natural world. The game reacts to your interactions with other characters in the game and the monsters you battle, because that is what the makers of the game wanted the actual gameplay to revolve around. You don’t worry about burning down trees or digging holes through mountains, and even if the technology of the game supported it, it would take an incredible amount of design work and balance to make it actually be fun.
Something like Minecraft, on the other hand, has a completely dynamic world. The game is about exploring and interacting with the world. Still though, what is simulated is fully designed around what the player will do, and though it does add components of fighting monsters, those mechanics are fairly rudimentary.
What we aim to do with CodeSpells is achieve as much of a dynamic world as possible, so that you can feel the world changing around you. One of our major inspirations is the game From Dust where the entire game is about deforming the terrain to achieve different puzzle-style objectives. The problem with something like From Dust, is that it is hard to scale to larger systems. Something like Minecraft intelligently uses localized changes to update areas that you explore without having to simulate an incredibly large world all at once. When you have a constantly flowing fluid simulation, things get substantially more complicated.
There’s plenty of excellent resources for generating terrain using randomized techniques (see libnoise). We actually use this type of generation, but the only problem with these terrains is that, as much as they can create interesting mountains or hills, they lack the sense of meaning that can be achieved in a natural or handcrafted environment. They don’t achieve the same level of cohesion that you get in real life. In most games, this is resolved with rules for generating the world, or by purely hand crafting the environment. Our current approach is to layer these types of systems together.
Then we layer sand on top of the terrain to cover it completely and we simulate it settling using Cellular Automata type rules. Note: we still want the sand to settle more than this to fill gaps better and create less clumps.
And then we can add water at a certain “sea” level:
And we can continue to add water after that will flow and fill any regions properly.
There’s still plenty of work to do! I have to optimize these systems, and Jason and I are going to make sure to fancy up the look to feel as polished as the rest of the game so far. By next week, we want to clean up issues with the sand not settling properly, cleaning up areas where it looks chunky, etc. But, we feel like we’re on track to creating a pretty convincing world.
With the ability to deform terrain, redirect rivers, and really interact and alter the environment, we want to focus the attention of players on using their magic to interact with a living world so that you feel that your magic isn’t contained to just throwing stuff at other players!