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.

Here I’ll show you my weapon-of-choice: TIC-80. It’s very similar to other popular fantasy consoles, so the experience is transferrable. Within the same tool, you can:

  • Code in Lua*, against a simple sprite-and-tile based 2D API
  • Draw sprites and tiles using a 16-colour palette
  • Create chiptune sound effects and music with up to 4 channels in a simple tracker
  • Edit tilemaps
  • Export to HTML

TIC-80

Coding

TIC-80 code editor

TIC-80 primarily uses Lua for coding, but you get other language choices - Moonscript, JavaScript, Wren and Fennel. I like Moonscript the best because it’s like Lua without the bad parts. Its class syntax is excellent, something that sucks in Lua.

As a fantasy console, the editor window is tiny. While charming, I highly recommend getting the pro version for $5, which lets you code using any text editor.

This way, the entire game fits in a single text file, even graphics and sound, which is great for version control and collaboration between your artists and musicians. No more headaches from merging everyone’s work - it’s just lines of code in a file!

TIC-80 pro code

Graphics

TIC-80 has a mainly sprite-based 2D API, with built-in sprite editor and tilemap editor. They’re nothing to write home about, and get the job done.

TIC-80 sprite editor

Worth mentioning are the shape drawing functions available. In addition to the expected lines, rectangles and circles, you can also draw textured triangles, and which some enterprising folks have made 3D engines out of this. Not that you should do this for your jams, but they’re nifty tools to have. Check out the API for more details.

TIC-80 sprite rotation

Sound & Music

Sound and music work differently in TIC-80 than you might be used to, but in a way that makes it quite fun to use. In essence, you build these up in layers:

  • Create waveforms - you get 16 of these. You get the standard square, triangle, sawtooth and noise waves, but you can also draw your own, something which few other tools let you do.

    TIC-80 waveform editor

  • Edit envelopes - these are the sound effects, defined as four parameters: waveform, volume, arpeggio, and pitch. It’s a bit hard to explain, but here are some examples of things you can do:
    • Create a plucked-instrument with a sharp attack, by starting with a noise wave
    • Fade in or out using the volume envelope
    • Create a melodic chime with the arpeggio envelope
    • Create a vibrato effect with the pitch envelope

    TIC-80 envelope editor

  • Edit music. Here the editor is a more conventional tracker - you use instruments (which are the sound effects created earlier) and lay notes on patterns. Patterns are per-channel and can be reused, which is handy because you only get 60 of them.

    TIC-80 music editor

I’ve found it handy to keep a notebook of all the sound effects and pattern numbers used, as this is perhaps the clunkiest part of TIC-80.

Exporting

Exporting is probably the best part of TIC-80 for jams - how easy it is to export games from it. You can:

  • Save the game as a .tic cartridge, loadable by anyone running TIC-80
  • Export to a single .html file using export html
  • Export to an executable using export native
  • Take a screenshot using F8
  • Record a gif using F9

So preparing a jam submission is a cinch. What might take an hour messing around with screen recorders, exporters and so on, take only minutes with TIC-80. Take screenshots and gifs early and often and tweet/blog your progress!

Try it out!

That’s it! Fantasy consoles are so simple to learn, use, and are perfect for jams. Here are some games I’ve made with TIC-80:

And you can even take a look at the source code and how the game was put together - these fantasy consoles are editor-and-player all-in-one.

Try it out and happy jamming!

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.

So how universal is music really? To get to the bottom of this we need to go to the fundamentals of music: melody, harmony and rhythm.

Music is made up of sound; consider a single note, which is a vibration at a constant frequency, or pitch. A melody is a sequence of such notes. But what pitches should these notes be? Why do we have things such as scales?

Well if you look at a string instrument, the vibrating string creates the sound. Halve the length of the string, and it creates a pitch that is exactly one octave up - it sounds very similar, but is a higher pitch. Play the string at 1/3 (or 2/3) the length, and we get a pitch corresponding to a perfect fifth.

overtones

If we keep going, we’ll get the major third as well. These three notes comprise the major chord, a very harmonic and uplifting chord very commonly found in many styles of music, especially Western music. Ode to Joy in particular uses predominantly major chords in its main theme, and it’s a very powerful piece.

So that’s pretty cool - the major chord in fact has a mathematical basis, and since math is universal, the major chord is too. If we go further, we find that the pentatonic scale can also be constructed using just intonation, and this is a scale that’s very widely used, like in Eastern music, blues, and many of their descendants.

Mathmagic land

However if we keep going and look at further harmonics, we notice something odd. In Western music we use an equal temperament scale - that is, every tone is separated by the next by an equal ratio. This doesn’t happen with harmonics, where if you tried to construct a scale out of natural harmonics, some notes will sound slightly out of tune:

This was especially frustrating to the ancient Greeks, who were obsessed with perfect mathematical representations of reality. The Pythagorean scale, which is constructed completely out of the 3:2 ratio, is ever so slightly off compared to the equal temperament scale.

Although we’d like to think there’s something universal about the Western scales, in reality it does contain arbitrary elements. The Western scale is based on 12 equal interval semitones; look outside that system and we find ones like those used in gamelan music, made up of equal 5ths or 7ths:

Or various Middle Eastern scales, which use quarter tones:

Many listeners accustomed to Western music will find these dissonant, but there is nothing inherently dissonant about these, any more than Western music is inherently harmonious. The only thing notable about the Western scale is that it both incorporates equal temperament (12 semitones) and many of the pure intonations. 12 can be evenly divided by 2, 3, 4 and 6, which is quite a lot. But varying that, we could construct many alternate scales. There is no one perfect scale.

Let’s look at rhythm, since it seems there might be more universality there. The most basic rhythm is a steady beat, but at what frequency? Research shows the most popular kinds of music fall within the 120-130 beats per minute range, and this may have to do with the heart rate of a brisk walk. The most popular time signature - that is, how many beats per measure, or “bar” - is 2 or 4 beats. It seems no coincidence that this even number corresponds to the physical act of walking - tick, tock, tick tock; or left, right, left, right… the rhythm we prefer is tightly coupled to our physiology. So much so that our bodies actually want to sync up with the rhythm. Slow music soothes and relaxes us, whereas fast music gets us excited. A lot of other activities syncs up to this tempo, whether that’s walking pace, or even the speed of clapping. Our bodies have a natural rhythm, and that translates to our music.

We see more of this correspondence between our bodies and rhythm in music. Add elements like shuffling, swings, or syncopation, and a dancer is compelled to follow using more complex movements. Music played slightly ahead of the beat sounds eager; played slightly behind the beat and it sounds laid back.

This might be the case for humans, but it might apply for animals too. By varying the tones, pitch and rhythm to suit their physiology, we’ve seen that animals can respond to music too, but this music would sound incomprehensible to us, just as sounds that are too high or low pitched, too slow or too fast, would sound uninteresting. It seems there’s much truth to the slow-talking of the Ents.

So what the heck is music? It’s perhaps a bit of everything: something based on universal mathematical properties, but also with cultural variations analogous to our languages or even accents, and rooted in our unique physiology. It is a language but much more; universal, expressive, and fundamentally human.

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

Before we place paths to connect these buildings, we need to think about how these buildings will be used. Some - shops, inns - will be more important than others - private residences. Let’s express that by making some buildings important, giving them a different appearance, and populating them with more NPCs.

village with NPCs

Now to connect the buildings, by taking random pairs of them, then using pathfinding to draw a path between each pair, with two conditions:

  • the more important the building, the more we use it as a path destination;
  • make sure all buildings have at least one path

village with paths

This seems ok but now the village is overrun with paths. Some are obviously more well travelled than others. What if we showed that by using different tile types? From tree (no wear), grass (light wear), dirt road (moderate wear), stone road (heavy wear):

village with varied paths

Now it’s starting to look nice! But there are still a few problems: there’s a lot of grass, representing lightly travelled paths, and odd patches of stone/dirt roads, right next to each other.

It turns out we could make one more improvement: when there’s an existing path, it would make more sense to reuse it, even if it’s slightly out of the way, rather than cutting through untravelled roads. This makes sense and it’s what real travellers do. So let’s modify our pathfinder, so that it favours well-travelled tiles, and see what we get:

village with shared paths

Nice! Now we see some clear heavily-travelled avenues. By observing the paths, we can also make sense of where the important locations are. Cool huh?

You can find this map generator here: https://github.com/cxong/gomapgen under the village option. It’s also where I make lots of different map generators for fun.

Hope you enjoy!

village animation