Games are really complex. They often have hundreds of moving parts that interact with each other in subtle and surprising ways.
“Subtractive Design” is one way of coping with this complexity. The idea is you first throw a bunch of different ideas into your game just to see what sticks. You then steadily subtract the ones that don’t fit very well until you’re left with a small, crystalised core where every element is important. The original Super Mario Bros is a good example of this. The game only has a dozen different enemies but they are all pretty unique and memorable.
You probably know how to handle every one of these critters.
Keeping the total number of elements low meant that each one could have its own artwork and code without making the game overly complex. This was especially important in the NES era because of the tiny amount of memory available to developers. Super Mario Bros checks in at just 31KB, far smaller than even an average text document today!
But what if you don’t want to make a small, streamlined game? What if you want your game to have a wide variety of content and encounters? As it turns out, Nintendo made another game on hardware even more limited than the NES which did exactly that.
Pokemon Have Layers
Despite clocking in at under 1MB in size, Pokemon Red & Blue contain a large game world and over 150 unique kinds of Pokemon. They were able to achieve this by splitting Pokemon into layers that can be varied independently.
The type system is the most obvious example of this. Every Pokemon has up to 2 types (fire, water, grass, electric and so on). Each move a Pokemon can learn also has a type. Instead of having a big list of how effective each move is against each Pokemon, they instead have a much smaller list of how effective each type is against each type.
So instead of listing all possible interactions like “Thunderbolt is super effective against Magikarp” and “Thunderbolt is super effective against Starmie”, they just have to say “Electric type is super effective against Water type” and they can work out the interactions from there. The interactions are defined on the Type layer rather than on each individual piece of content.
Pokemon have more layers than just their typing. They also have layers for their health, status ailment, base stats, level and moves. That’s at least 6 different layers that can each be modified independently to make hundreds of different Pokemon from a small set of base rules. Since every aspect that makes up a Pokemon exists on a content layer, you can actually describe the behaviour of every possible Pokemon with just a few pages of code.
This image contains (almost) all the information you need to know exactly how this Pokemon behaves.
Hardware has gotten much better in the last few decades and many new Pokemon games have been released. But modern Pokemon still use the same kind of layering their ancestors did. They now also have “Nature”, “Ability” and “Item” layers, but they are otherwise almost exactly the same as they always were.
This image still contains (almost) all the information you need to know exactly how this Pokemon behaves.
The series now has over 800 unique Pokemon, each of which can interact with all of the others in countless different ways. But since the interactions are defined on a smaller set of layers rather than the full set of Pokemon, the game is still simple enough for young children to play (and simple enough for the developers to actually build).
Cards Have Layers Too
RPG’s aren’t the only type of game to make use of layering. Card games like Hearthstone and Magic: The Gathering also aggressively layer their content.
A Hearthstone minion card has 5 layers. Let’s look at these two popular cards to get an idea of how this works:
- Name. This lets cards directly refer to certain other cards.
- Attack and Health stat. If the Azure Drake (4/4) fought with the Shieldmasta (3/5), they would both be left on 1 health.
- Mana Cost. The Shieldmasta costs one less than the Azure Drake, meaning you can play it a turn earlier.
- Tribe. The Azure Drake belongs to the “Dragon” tribe, meaning all cards affecting Dragons will also affect it.
- Ability Text. This is the big one. Each card can have some unique text that grants it extra abilities.
Since the ability text layer can contain a huge variety of different things, they also use keywords (shown in bold) to keep complexity at bay.
- Taunt means that this minion must be defeated before you can attack anything that doesn’t have Taunt.
- Spell Damage +1 means that any spells you have which deal damage will now deal one extra.
- Battlecry means that the following text will activate when you play the minion (here: Draw a card).
You may have noticed that these keywords are actually themselves a form of content layering. This means the ability text layer actually has two tiers: keywords and the full text. Putting layers inside layers is how Hearthstone can have over 1,000 unique cards without becoming incomprehensible.
In Patch Quest, my own game, the world itself has been separated into three tiers: The Habitat, Patch and Tile tiers.
Each tier operates on the same set of layers:
- Terrain Hazards. These are things like brambles and water which do stuff when you step on them.
- Creatures. This layer holds the various animals that attack, chase and generally make life difficult for the player.
- Scenery. This layer hold plants, rocks and other kinds of non-animal content.
- Special Content. This special layer lets me apply custom code that modifies the other layers.
The island you explore in Patch Quest regenerates every time you reach a checkpoint. To do this, the world is first split into habitat regions based on the distance to various landmarks. Each habitat is like a Hearthstone deck; they contain a set of terrain, creature, scenery and special “cards” that need to be evenly distributed across all the patches within that habitat.
At tier 2, the “Patch” tier, these cards are then distributed to the various tiles making up that patch. The special card is also resolved here, activating its custom code and modifying how things are laid across the tiles (here creating that pathway in the middle of the patch).
The final “Tile” tier is what the player actually interacts with. By having this 3 tier system, I can define a simple map at the highest tier and automatically generate a wide variety of maps that are very different at the lowest tier. By carefully choosing the generation rules between each tier I can also ensure that these maps have an even difficulty and a consistent theme.
We Need To Go Deeper
The layering in Patch Quest doesn’t end here. Creatures and scenery are also layered, much like Pokemon. Here’s two creatures from the game, the Spin Star and the Steagull:
The Steagull can walk and fly, whereas the Spin Star can’t move at all. The Spin Star can survive in the water though, whereas the Steagull is restricted to dry land. Docile creatures will happily sit around, whereas aggressive creatures will chase you down. They also each have a special move which triggers when you get too close (note that the player also counts as a “creature”, meaning these moves can target the player too).
Like with Pokemon, the creatures in Patch Quest share all their code. The differences between various creatures are defined not in their code but in their layer data. Below, you can see how simple the layer data is for the Spin Star and Steagull. It only takes a few short lines to make a unique creature.
In all honesty, the layering in Patch Quest doesn’t stop here either. Items and Quests are also layered and even a lot of the game’s graphics are layered! But these are all topics for another day.
In summary, content layers let you make a huge variety of unique game elements from a small set of base rules. They create variety for the player without also overloading them with massive complexity. Layered games are also resistant to software bugs, since each layer can have a small, well defined set of interactions. Games have been using content layering for decades now, but there are still plenty of new ways we could be applying this old idea.
Have a question? Want to comment? Head over to the forums. I’d love to hear from you.