Feb 24, 2021 - BSP Lock and Key

Comments

I’ve been working on C-Dogs SDL lately, and one thing that often bothered me about that game is that its default random map generator provides an uneven experience. It’s exciting at the start when everything’s unexplored and there are many corridors and rooms to visit, but in the late stage when you are hunting for keys and objectives, backtracking all over the map, it can be quite tedious.

C-Dogs’s map generator is quite configurable and produces a wide variety of maps, but at its core it’s pretty simple:

  • Start with an open area
  • Randomly place rooms around the place
  • Randomly lock some rooms, and place keys in the rooms

C-Dogs map

The lock-and-key system is in series: the yellow key is in an unlocked room, the green key is in a room locked with the yellow key, the blue key is in a room locked with the green key and so on. Here’s a tree to illustrate this simple structure:

C-Dogs map graph

Because the keys (and objectives) could be in any one of several randomly placed rooms, you may need to criss-cross the map many times to collect them all. That’s a lot of backtracking! Another issue is the structure - rooms are isolated from each other, all leading outside. This gives all maps a similar feel. What if there were a map generator that could:

  • Provide a more interesting structure
  • Feel more like an indoors experience, like a building interior or dungeon?

I was first inspired by sauer2, maker of many C-Dogs SDL custom campaigns, which often take place indoors. These have cool features like:

  • Corridors linking many rooms
  • Rooms connected directly to each other
  • Locks separating entire sections of the map at a time
  • Branching pathways
  • Minimal required backtracking

Space Pirates map

Searching online, I came across a neat technique that uses binary space partitioning to generate a building interior. The algorithm recursively splits the area in half, placing a corridor at the split, and continues splitting (while alternating horizontal/vertical splits). Areas left unsplit are then filled with rooms. It’s a simple yet flexible technique.

BSP algo

As the structure of the map is a deeper tree, by finding a critical path that starts and ends at leaf nodes but passes through the root, we can get a fairly long main path, with shorter branches along the way. Here’s what that looks like, in my initial adaptation:

BSP interior demo

Read more

Jun 27, 2020 - Fantasy Consoles for Jams

Comments

I’ve done a lot of game jams and have used many engines and frameworks in these jams. They all have pros and cons, but lately, I’ve been using fantasy consoles as my platform of choice, and I think you should too - they are fantastic for game jams.

What are fantasy consoles? In short, they are virtual consoles that mimic retro computers and their limitations, but also provide a complete game development environment. Within the same application, you can draw simple sprites, compose chiptune music and sound effects, and write code using a limited API. Its severe limitations are also its appeal; it’s not only a piece of cake to pick up and learn, but the limitations encourage creativity. PICO-8 is the most popular, but there are many others to choose from.

PICO-8

One of the most important factors when choosing a platform for jams is development speed. You want to be able to put something playable together as quickly as possible, as time is the scarce resource. Here the popular engines do very well; Unity, for example, has a lot of functionality built-in, or easily accessed via its asset store, so you can quickly piece something rough together.

Fantasy consoles represent an alternate approach - with limitations and fewer tools at your disposal, there is less time wasted in choosing how to make your game and more time on focusing on gameplay and making something fun. It’s easy and quick to put together something playable, so you can start iterating and polishing on top of a solid base.

Read more

Apr 12, 2020 - The Language of Music

Comments

For a while there was this idea that music was the universal language. Our human languages may be mutually unintelligible but we could always enjoy each other’s music. Music is such an important part of our cultures that we even sent it out on the Voyager golden record.

But is it really as universal as we thought? Even hearing some of the songs in the golden record, they could sound beautiful yet alien to those of us accustomed to Western music, like this haunting Navajo chant:

And then consider how different everyone’s musical tastes can be, how they are shaped by teenage experience in particular. The kind of music we listen to as adolescents usually sticks with us for all time.

Read more

Mar 11, 2020 - Natural Path Generation

Comments

Random level generators are great fun to make; there’s nothing quite like coding an algorithm that creates endless variations of maps and dungeons.

A typical random map generator might place rooms randomly around the place and connect them with corridors. Then the map might be filled randomly with inhabitants - monsters, treasure, NPCs and so on. This is simple and effective, giving players unpredictable yet interesting encounters in games. It’s an evergreen approach starting from rogue (1980) all the way up to the latest indie dungeon crawlers.

Rooms and Mazes

This can seem backwards though. One problem is that the layout often seems artificial; there’s not much reason or purpose for the rooms and the connecting corridors. Real locales would be filled with inhabitants, with paths connecting important destinations together. The paths are like arteries; they are inextricably linked to the design of the whole place.

So I thought a fun experiment would be to make a random level generator that builds such a map via simulation: fill it with virtual inhabitants, who need to go from A to B, find out what paths they need via pathfinding, and create the paths based on travel patterns. Let’s see how this goes!

First, I start with a simple “village” generator - just a bunch of buildings scattered randomly around the place.

village

Read more

Oct 26, 2019 - Level Design Patterns in 2D Games

Comments

I’m a sucker for level design and design patterns, so when I came across this article (and paper) called “Level Design Patterns in 2D games”, I had to read it! Unfortunately it’s a bit wordy, so I thought I’d summarise it and throw in a bunch of pictures! Enjoy!

Hover over the images to read an explanation for each example!

Guidance

Guide the player through the path they need to take.

  1. Level shape

    | Super Mario Bros. | Super Meat Boy |
    | ------------- | ------------- |
    | ![Super Mario Bros. stairs to flagpole](https://raw.githubusercontent.com/cxong/cxong.github.io/master/_posts/smb.png "The upward shape of the staircase encourages players to hit the flagpole as high as possible, achieving a greater score") | ![Super Meat Boy hills](https://raw.githubusercontent.com/cxong/cxong.github.io/master/_posts/super_meat_boy.png "The goal is to reach the pink character on the middle platform, but it's impossible to jump here from the starting location directly. Instead the gentle staircase-like level layout hints at the solution - move to the right side of the level, then jump left onto the middle platform.") |
    {:.table-bordered}
    
Read more