Thursday, July 15, 2021

Metroidvania and Randomization: Forgetting the Moment

What comes to mind when you hear the term "Metroidvania"? Is it a connected world full of secrets and treasure? Is it a bounty hunter exploring a deep dungeon, jumping on platforms and shooting everything in the way? What about an rpg-esque level up system and a series of equipment that gets stronger as you progress? Deep lore that provides ultimate immersion?

What if I told you that the core of a metroidvania isn't any of that? It's actually just the map, with upgrades-as-keys needed to unlock areas. Take a look: https://www.kongregate.com/games/lozzajp/maptroid

Maptroid is a wonderful proof of concept. There are various lore bits scattered around the world to fill in the gaps, but the emphasis is on upgrades. You need a shovel to break through weak floors and a hammer to break weak walls. Cold areas need warm clothes. The map itself supports this; the first upgrade unlocks areas that you had seen before, but couldn't access due to the lack of a grappling hook.

Maptroid strips away all of the fancy graphics, world building, and platforming you would find in other, the game can be simplified to a basic story: Go left, find a key. Use it to move downward, find a second key. Repeat until you find all the keys and finish the game.

Creating a map in a more complex environment is a challenge. The world needs to have a cohesive idea. Traps, puzzles, roadblocks, and keys need to be scattered all over the places. Dead ends with precious loot entice the player into exploring every nook and cranny. Various parts of the map are intended to be replayed in the first run, let alone any replays that happen. All games need to start somewhere, so let's draw up a basic design for a procedural map that does one thing.

The Backtracking T




We start in the center. Basic controls are movement; we can go left and right. A door blocks our way to the right, and we can't jump, so we go to the left and grab a key. The key unlocks the door, so we go to the right and grab the next item. Now we can jump, so we go to the top of the map and touch the flag. You win!

This certainly works as a proof of concept. It has all of the core elements of a metroidvania: exploration, lock-and-key progression, and a connected world. The map was procedurally generated with an algorithm that can only follow one procedure with some slight variation, so you don't have to worry too much about testing branching paths, the map looping back in on itself, or odd ideas like the map changing as you progress through the run.

Let's assume that the basic mechanics are rock solid. At any given second the player has full control over the player. Platforming is fun, enemies are engaging, and everything on the screen does exactly what you want it to. At this very second, the game is great. A lot of games get built from the smallest details and expand over time.

Let's also assume that a game designer comes along and sees this well-working game and decides to layer on some of the more interesting things, like story and themeing. The generator gets split up into different zones. A Robot Named Fight separates its map out into a new city, a cave, a robot factory, an old city, and then expects you to travel these in reverse after you're done. This means we get to build from both ends of ground-up and top-down.

On the surface, there's nothing missing from this plan. The player's story should sound something like "The megabeast is closing in, you must defeat it! You start in a city, defeat a boss, grab a random upgrade, and progress into a cave where you do it all again. Find the cave's boss, grab the abandoned city's ultimate power, and return to the surface to defeat the megabeast."

Unfortunately, most procedurally generated games I've seen stick to this formula. The best ones focus on the "overall experience", while many of them focus on the interesting parts on the edge. They work on the smallest details like combat or upgrade variety or challenge. They might instead focus on the overall story, like a cult kidnapping villagers and the hero rescues the town, then takes on the elder god X'Tua Ulak. With all the effort and all the compromise to get both large and small working it should work out, right? Right?!

Desperation kicks in at some point when the developer realizes the entire process they thought would magically come together doesn't materialize. A lot of people will see the big and the small working just fine and assume they come together for a great experience. The novelty and the uniqueness of each experience will surely cover up any blemishes on the project. That is a trap that leads developers to layer on more and more ideas, or tweak and compromise on some of the core premises until the entire project is simultaneously hollow and bloated. 

Magic in the middle

 

What part is actually missing from the overall experience? In a phrase: moment-to-moment gameplay. It is the time period between twitchy active gameplay and a slow, methodical story. The moment-to-moment gameplay is where most games live and thrive, and is what many people mistakenly call 'Content'. This is the middle ground.

- Great mechanics. Platforming, upgrades, and combat. Timeframe: half a second
- MAGIC?!?! Timeframe: ???
- Great theme. Story and lore and bosses. Timeframe: 20 minutes to 300 hours

Let's focus on that middle part for now. Minecraft embodies moment-to-moment perfectly, to the exclusion of everything else. Combat is lame and movement is basic. It takes forever and a day to do anything. I would wager that you could tell me everything that went on the first day you played the game. Here's how mine went
1. The title screen started up, version 1.2 beta. I created a world called "New World". The game loaded up and I was off
2. Everything is made of blocks? This is cool, let me look around and get used to the controls
3. Sheep! Punch the sheep! I have wool? Place the wool? OOH THIS IS HOW THE GAME WORKS
4. Punch the nearest tree. Logs are nice, leaves don't do anything. Punch more trees.
5. Punch the sand. Water pushes me around, so I want more sand. Sand is life.
6. The sun is getting lower in the sky. I should find somewhere to shelter for the night. Dirt on the side of a cave is the way forward.
7. The sun is setting. I built a nice hovel with a doorway. The game is lagging now... let's go inside.
8. Nothing to do inside. Stare at the sand... I guess I can get the sand
9. WHAT THE HECK IS THAT AND WHY IS EVERYTHING EXPLODED?!?!
10. Delete world, throw computer in trash

That is the story of the first 15 minutes of gameplay. The minute, miniature story beats that define quite a lot of games. For some games this time scale runs on a bit too long and for others it gets compressed and chaotic, but the underlying structure is the same. This is also why older games tend to be more interesting than newer games. Filling 200 hours of content 90 seconds at a time is a nigh impossible challenge.

It also seems really weird that Minecraft would focus exclusively on the middle ground. There are a lot of ideas floating around about how game mechanics work and how overall game story progresses, but very little that focuses on the middle. When games were shorter, they had to fill in the middle as much as possible. Complicated mechanics are very hard to program in assembly, and memory limitations prevented anything but the most basic of games from having long-lived experiences. These games needed to focus on the most important aspect to deliver maximum potential. 

Building up Features

 

How do we deliver on the middle ground? We have obviously good mechanics and obviously good themeing. Generating a dungeon randomly is still missing something... let's add in some structure and see where that leads. The Backtracking T map needs a few more rules to it. Our initial rules:
1. The map is divided up into separate areas called zones. Each zone has a key area that unlocks the next zone. Zones are desert, cave, and mountain.
2. Zones have their own set of rooms, picked randomly from a list of choices.

We have the high end of design - zones - and the low end of mechanics - rooms. The design is flexible; it can be any size that we want. The design is also sparse enough that anything at all can be inserted. We can use this as a base to build off of and add in story, enemies, crafting, jukeboxes, liquid particle simulation, jaywalking, and stealing candy from the dirt.
 
Thinking that this is a complete design is a trap. If the design is so flexible that you can put anything in it, then it has to accept everything. The design doesn't add enough restrictions so anything that goes in needs to fit with everything else. The stories that the design will tell do not depend at all on the design, but from the content. If the intention is chaotic random happenstance, then it's a fine idea. If the intention is poor, you will end up with generic cookie-cutter pieces that make a complete puzzle of a square built out of squares.

We need more rules than that. Let's go deeper.
1. The map is divided up into separate areas called zones. Each zone has a key area that unlocks the next zone. Zones are desert, cave, and mountain. The starting area is a forest.
2. Each zone should be around 3 moments long, or about five minutes.
3. Zones have their own set of rooms. Rooms are grouped up into features, and each feature has its own story to tell.
4. Features can overlap and blend together.

Rooms in many metroidvania games try to capture a single moment in time. This is why Super Metroid's rooms tend to be so large. You will spend as much time as you need to in them, they are distinct and the expected time in any single room varies somewhere between 30 seconds and 4 minutes.

Features are a way of trying to string these individual moments along. They can form a miniature cohesive story on their own. If two features overlap, then they can blend together in a way that leads the player down a path from one miniature story to the next. You might end up walking down a path, stop to smell the flowers, get off on a side trail, find a squirrel, climb its tree, and then return to the trail. This was expected, and the experience still feels like a natural exploration of the world.

Features can also control the flow of difficulty and pacing in a game. A particularly difficult obstacle will be notable if the surrounding area is easier, and will seem out of place if it's put in at random. In fact, extra difficult obstacles are usually left out of randomized games because they break the flow too much. If you can guarantee that an infinite pit comes after a series of smaller pits though... you can work in the idea of a death trap at the end of a series of constantly increasing difficulty features.

The design structure for blending features looks like this:
<[ 1 ]=[ 1 ]=[ 12 ]=[ 12 ]=[ 12 ]=[ 2 ]=[ 2 ]>

Features 1 and 2 are both five rooms long. They have a significant amount of overlap in the middle. The overlap will take more effort to generate than simply randomizing everything around it, but will allow for much smoother transitions than "this magic portal leads to space". You might need to run some special code to generate two rooms on top of each other or have a kind of middle ground between the two.

An expanded blended map looks like this:
     [!1]=[12]=[2 ]>
      ||
{ !]-[!@]-[@#]-[#$]-[$%]-[% ]>
      ||
[AB]=[!A]
 ||
[B ]>


Every room blends into every other room here. The main intersection has a primary type [!] and a blending type [@].

Moment to Moment Story

 

Now that we have everything defined we should be able to define everything between mechanics and theme.

- Mechanics. Platforming, upgrades, and combat. Timeframe: half a second
- Rooms: Self-contained area for a story beat. Timeframe: one moment, 90 seconds
- Features: A small series of events with a cohesive experience. Timeframe: 3-7 moments
- Levels or Zones: A general area with a common set of features, difficulty progression, and significance in the overall story. Timeframe: 5 minutes to 2 hours.
- Theme. Story and lore, overall playthrough. Timeframe: 20 minutes to 300 hours

With these extra structures in place, what the story of The Backtracking T look like with a real set of assets?


- Test player controls. Examine your surroundings. Find a door that needs a round object of some kind and some kind of unscaleable mountain.
- Leave the forest and traverse the desert. It's treacherous, so keep track of the sandpits.
- Find the mystic gem. Quickly backtrack and dodge the sandpits, then put the orb in the door.

- Find your way through the cave, dodging bats and slick floors. Grab the climbing claws.
- Dodge and smash all the bats on the way out. The place is still quite treacherous, so it takes time, but less so because you can scale walls.

- The climbing claws let you climb the mountain! There are harpies, so you get knocked off multiple times and have to start over
- The top of the mountain has a harpy queen. She agrees to give you medicine for a mystic orb. Down you go and up you go, but quicker this time.
- Gain the medicine, the game ends.

This story takes 8 moments to complete. Each moment is a miniature arc in the story. The player can relate to each part, find a particular memory to differentiate it, and then describe in their own words what happened. The middle arc is the least defined of the group, but the middle of a video game can vary in length quite a bit based on the differences in player skill, experience, and knowledge of your game.

This is a far cry from the previous story of "go left, find the key, go right, find the key, go up, beat the game". Even better, the game can have bad mechanics, no story, look terrible, and have no sound. The chance you would remember this game as being a bad game would be high, but it would still hold your interest long enough to finish it. THAT is the important part.

By restricting the rules into a set of features, the designer is forced to think about each one of those features. Each one needs an emphasis and a connection to the rest of the world. By combining theme and mechanics, we have what lies in the middle.

Conclusion

Make sure you include the middle when procedures are written. Players do not live in the minute or on the theme. Grand overarching epics of greatness and wonder still need time to pass. Minute mechanics can be wonderful in an instant, but out of place with other things. Most importantly, stories are not constructed out of the largest or the smallest pieces. They lie somewhere in the middle.

We live in the moment. Make sure your game knows what a moment is.

Wednesday, July 14, 2021

Metroidvania and Randomization: Breakdown

Objective: A full-scale random map generator that is indistinguishable from a hand-crafted experience. Will we get there? Who knows!

Analysis:
Metroidvania games are based around tight hand-crafted experience. Levels are built in a way that encourage backtracking, to show improvement in the player's avatar and skill over time, a lock-and-key system to gate progression, and repeat playthroughs tend to change the way the game is experienced though advanced tricks or sequence breaking.

Procedural generation has the opposite promise. Every playthrough and experience has been shuffled, randomized, or otherwise changed. Each run is novel and unique. The world itself is unknown until explored and discarded at the end.

These two experiences are fundamentally incompatible. Combining the two will end up compromising on the promise of one or both experiences. This may be a small way, but

I believe the incompatibility exists on an experiential level. Super Metroid is a masterpiece of gaming; a randomly generated Super Metroid game is the holy grail of game design. Attempting to make a randometroidvania game requires a high level of design skill. The idea has been attempted, but it's hard. Let's take a look at why.

Problem 1: Randomized games are a lot less memorable

The core promise behind randomizing a game is that it is novel and unique. Seeing something for the first time is exciting; imagine seeing everything for the first time every time you started up a game. It would truly be a unique experience that can be shared and related to other people. There might be some common thread running through the gameplay, such as building a dirt house in Minecraft, but that common thread could happen on top of a mountain or next to a river or even inside a cave.

Experiences have narratives. Anyone who plays a game becomes the main character in their story. If the story is about making a tree, then it might involve research, a sketchbook to draw out a rough design, scanning, painting, and eventually taking the finished piece and putting it in a game. It might be about pulling up the dictionary in Scribblenauts and dropping a tree on a vampire. It might just involve bone meal to magically sprout a full size tree out of a sapling. The story itself is how we share games, and "random" games tend to be bad at this.

Trying to build something "random" makes building up the story of the world difficult. It's a lot easier to describe a single tree in a field than a single tree in a forest. It's also a lot easier to describe a forest in space than a forest next to a plain next to another forest next to a lake next to another forest. Differentiating the first forest from the last is difficult enough when the game is static; when the game constantly shifts around under its own weight, you miss the forest for the stars.

Procedural games tend to make everything into the forest: level elements are cookie cutter, bland, and can be shuffled around or inserted at any given point. Every piece in the story needs to be self contained and inserted into an experience at any given point. Relative difficulty over a scale becomes impossible to pin down, and the closest thing you'll see is that an area is more difficult because the monsters in it have more health and damage.

Cookie-cutter rooms are a design trap. If every piece needs to fit everywhere, then every piece needs to be more-or-less the same. Sure, the level might have some difference in the way it looks, and later parts of the game may have more traps or features to traverse, but they still can't have much variation.

If every piece is generic, then every piece is the same. If you're doing the same thing again and again for a few minutes, it's going to get boring. Why would you do a repetitive task that merely has slight variations? It's almost like the designer lost part of the design in the process or didn't know how to handle this to begin with.

Many games treat procedural generation as a blank check to replace what would be interesting and engaging content with novelty. The systems can be the best technical gameplay ever made and they will still be disappointing if there is no challenge or variation to use it on.

This problem rears its face again and again across any game with a randomized system. The problem can be solved; the best randomly generated games have a particular idea or experience they're going for. The randomness may blend into the background, or it may become the centerpiece of what the game is trying to express.

Random generation done right can can be better than hand-crafting everything. When it's done poorly... well. Let's just say that the results don't speak for themselves.

Problem 2: Procedural levels do not tell a cohesive story.


If we define a dungeon as a series of traps and pathways full of loot and danger, then Super Metroid becomes one of the greatest dungeon crawlers of all time. Its platforming system is quirky and floaty. The game is easy enough that a random person could pick it up and have a fun time over a 10-20 hour experience, but the skill ceiling is high enough that the human limit may not be reached. The game even has the same constraints as a lot of modern procedural counterparts: the entire game is a series of rooms and tubes connected up at doorways.

Super Metroid's greatest strength is in the way player skill is handled. A new player will find themselves fumbling through the entire world looking for the next upgrade. They will stumble into areas that show that Samus has skills that the player doesn't know about: running, wall jumping, and the shinespark. Once the player has mastered each of these skills, a new game opens up. Suddenly you can go where you hadn't before, beating the game "out of sequence", and with enough practice the common experience that everyone had when they started gets shattered into a wide variety of routes and choices.


(Above this plant is an item that needs a shinespark to access)

The unchanging map also lends itself towards mastery over the game itself. There are tiles placed strategically around the level to show where certain tricks or borders are. The level may seem a bit dull at first, but every tile, enemy, and doorway is placed in a way that notes "I am here". Even the smallest detail can be used as a visual cue. Combine that with completing the game out of order - sequence breaking - and eventually you can go anywhere in the game at any time provided you have the personal skill to do so. 

Super Metroid's story is something that can be explained as "I accidentally found a new area, got an upgrade, and then went back and did it again. The varia suit lets you run in super hot rooms to find a speed booster that turns you into the flash, and there was a boss the size of the entire screen, pools of acid to burn your face off, and the planet exploded!"

You'd be forgiven for missing out on the details of your journey. I'm sure each area was memorable, and subsequent trips will make all the little things shine.


Contrast this with Dead Cells, the roguelite metroidvania fusion. Every time you play the game a new world is generated. Characters do not start off fresh; instead they start with all of the skills and unlocks that have been gained over previous runs. A player who has been playing for an hour has likely died five times, unlocked two levels of potions, gotten used to how the basic sword and bow operate, and found themselves at the mercy of the prison.

Because each run is unique, the player needs to rely on their general gaming skill to get by. There aren't any specific training areas. The levels are mostly comprised of a linear path with some branches, and each section has a teleporter to make backtracking faster. Most areas are flat. Traps tend to be blocky, made of spikes, and infested with enemies.

Dead Cells sacrifices its individual upgrade aspects and some fine tuned gameplay to offer up a huge variety in weapons, good variety in enemies, a branching progression path that resembles its level layout, a level-up system based on loot, and a permadeath system that brings some upgrades forward each time cells are spent. It's a good tradeoff that leans heavier on its roguelite aspect than its countepart.

Dead Cell's story can be summarized as "I found a sword, killed some things, ran around AS a chicken with its head cut off, got my head cut off, and did it again. Each time I got a little further and the game got harder, but I finally triumphed after countless deaths."

This game gets around the problem of moment-to-moment player story by absolutely littering every level with enemies. There are occasional areas tacked on to the level called "lore rooms" that expand on the actual story, and each new level has a theme and a different type of layout behind it. The Docks always comes after a boss fight, has a lot of vertical buildings thatyou can go inside, and there are a good number of secret rolling areas to visit.


(the most interesting part of the game is the very beginning)

Let's look at another game with the same intention. A Robot Named Fight has the same roguelite metroidvania fusion as Dead Cells, but leans much heavier on its metroid roots. In fact, the robot controls so similar to Samus that you could play Super Metroid as a training area. That fact alone wouldn't be a problem if the difficulty of the terrain wasn't exactly uniform across the entirety of the game. There's no challenge in movement; you either jump high enough or you don't. You either jumped or you didn't.

Upgrades are randomized without any progression. The start may have a double jump, an explosive shot, or a movement shell. The last boss may have the same items. Every one of the items is about the same power level, give or take, and the only real thing that matters is damage or bolt changes.

Unfortunately, Fight comes out as the worst of the bunch. The entire world is shaped like an upside down e. It's broken up into four distinct zones, and the deeper you go into the map the harder the enemies are. However... every room feels like every other room across the entire game. The lock-and-key system is preserved, but it feels arbitrary to block off doorways with explosives or lightning because there's no real way of identifying where these doors are outside of looking at the map.

How much meaning can you find in the placement of an empty room? Nothing. How much meaning can you find in the placement of a completely randomized upgrade? Also nothing. How about single templates level layouts? Maybe something, but not much. At least not without making it painfully obvious.

A Robot Named Fight's story can be summed up as "Robot fights meat and gets random things to open random areas". It's not compelling. My own story hardly worth a mention. Each run is 'unique', but when you've played one run you've played them all.

Fight's problems go deeper than the fact it is a mediocre game. Narrative and story is not something that can simply be put on after the fact. Each area should be something the player interacts with and can get behind. Instead we get generic, bland, recycled single templates that get stitched together in a broken line. I couldn't even tell you what planet you're on.



Maybe the problem is the roguelite aspect? Let's try a pure version instead: Chasm

The entire game is generated at the start of a run. You can explore, collect resources, gather upgrades, die, respawn, and do it all again. This one leans more on Castlevania than it does on Metroid, and the weapons certainly match that. Daggers are quick with impossibly low range, greatswords are slow but highly damaging, and skills take mana that can be found inside random objects.

It seems like a great setup. The idea is sound and it wants to scratch the itch of a wonderful platforming upgrade niche. Bait, meet switch.

The game quickly turns into a drag. The character's movement speed is as slow as any Belmont's movement, but without the precision in level design, devilishly placed enemies, or intricate maps. Most of the terrain is flat platforms in wide open rooms.

The map is a sprawling list of tunnels that connect to other tunnels in long hallways of tunnels. Very occasionally the path branches off, but they don't connect. You would be forgiven if you would get lost in the bland nature of the open level design if it were not for the strictly linear nature of the paths. On the off chance you do have to go off the beaten path for an upgrade, you probably won't remember where the upgrade actually is.

This project commits the cardinal sin of gaming: boredom. The entire thing is boring from start to finish. The idea of a procedurally generated game is enough to suck you in, but the sheer amount of compromise in this product turns the entire thing on its head. The best thing I can say about Chasm is that it serves as an example of what not to do.

Chasm's story goes like this: "I started in a castle, got a message to travel to a place, took a look around, and jumped right in. After that I got lost multiple times and died a lot and then stopped playing because the last upgrade was a double jump."

Conclusion

We have two main problems to deal with that have the same root problem. Trying to marry a game type that tells its story through hand-crafted environments and repetition with a design pattern that rewards novelty and uniqueness leaves the two at odds. The ideas don't seem incompatible; hand-crafted and unique areas are similar, and repetition can be married with novelty in a variety of interesting ways.

 The real problem comes down to the restriction of completely replaceable templates all over the map. If these two ideas are going to get along they will need more structure, not less.

Self Reflection, Avatar Reflection

It started as a joke. One day I decided that my game development was going poorly because I was too attached to my characters. If I messed a...