User Showcase: Procedurally Generating a “Zombie City!”


03, 2012

by Andrew Haak


Zombie City SkylineProcedural generation refers to content that is created algorithmically, as opposed to manually. It was originally implemented in video games as a workaround to the memory limitations of early hardware; for example, the 1984 computer game Elite used procedural generation to create a universe with eight galaxies, each containing 256 planets, that wouldn’t soak up valuable memory. Today, procedural generation persists, but instead serves as a method for developers to make each play session of their game dynamic. ROBLOX’s Build and Battle, for instance, uses it to create a random swath of jagged terrain for each match.

Cunning ROBLOX users have found ways to implement procedurally generated content in their games. Zombie City!, an abstract – at least, for now – game by user um3k, known outside ROBLOX as Justin Phillips, is one such case. Each time a player starts an instance of the game, it procedurally generates an expanse of terrain and a complete city — littered with zombies.

The game itself is simple. You spawn at the top of a building, descend the many staircases and take to the land with nothing but a sword. In its current state, it’s all about the procedural generation.

“I enjoy exploration, and few things satisfy it more than a well-generated procedural terrain,” Justin said. “I also liked the idea of having a large city without having to build the whole thing.”

Generating terrain, the city grid and buildings

Zombie City! is generated using a two-pass process. The first pass generates the terrain, including roads and the wall surrounding the city. The second pass creates the buildings. Both passes use randomized parameters and Boolean conditions to determine the correct material for a given block, and make judicious use of the modulo operation for roads and windows.

The presence and type of building at a given location is determined probabilistically. According to the Lua script that generates the city, there is a roughly 75% chance of a regular office building spawning, and a 5% chance for both clock towers and churches to spawn at each grid location on the terrain.

Want to take advantage of Justin’s work?
You can download a ROBLOX Studio plugin that lets you quickly and easily place a randomly generated building, as seen in Zombie City!. Download the plugin here, and see it in action:

Generating the city quickly

The original version of Zombie City! used what Justin called an “overly complex” terrain-generation algorithm, which delivered pretty results, but was excruciatingly slow, freezing the server for 45 seconds or more. Justin experimented with adding a wait() function every few cycles, which, in theory, would let the players watch the terrain generate. But the terrain replication could not keep up with the terrain generation, causing the first player in the server to see half-loaded buildings and holes in the terrain.

Terrain Generation Code

The terrain-generation system. Click to enlarge.

“If something processor-intensive (e.g. terrain generation) absolutely must be ready when the game starts, it should be done with no waits, as long as the execution time can be kept below 15-20 seconds. If it takes much longer than that, most people will feel like the loading has failed and give up on the game.”

Justin later realized that a simpler terrain algorithm could produce visually acceptable results. It cut the terrain generation time to below 20 seconds, which is quick enough that players don’t ever feel like the game has timed out.

Zombie City Scroll

What’s next for Zombie City?

Zombie City! has always been something of a testing ground for procedural generation and, not as obviously, pre-recorded ragdoll effects. Future updates could bring a deeper story that includes solving the mystery of the zombie apocalypse (while thwacking zombies with a sword) and experiencing emergent gameplay (while thwacking zombies with a sword).

“Anything I do will likely continue the theme of procedural generation, and I’ve toyed with the idea of procedural plotlines that may work like mad-libs,” according to Justin.

Keep an eye on Zombie City! here.