Gate Demo in WebAssembly

Rust added a new compiler target a couple of months ago: wasm32-unknown-unknown. This allows Rust code to be compiled to WebAssembly and run in a web browser. Since I had recently completed my Gate Demo game, I thought it would be neat if I could use this target to play the game in a browser. It took some refactoring of Gate, but I got it working, and you can play it here. Despite needing to update the Gate library, I didn't need to update the core game logic at all.

As an aside, I tweeted this yesterday, and currently have 152 likes and 49 retweets! This breaks my previous tweet record of 2 likes and 6 retweets.

Tags: coding, gamedev

Writing a Short Chiptune Song

When I made the demo game for Gate, I wanted to have a simple song that went along with it. However, since I was putting the game, and thus the song, in source control on github, the song would need to take as little memory as possible. I took this as a challenge: write a short, looping song for a video game that doesn't become annoying. Here's what I came up with:

(This is an OGG file and should be playable from Firefox and Chrome.) The song is a grand total of 11 seconds long and 64.2 kilobytes, a quite managable size.

While I was coming up with this song, I tried to think of other songs that might not be annoying if played in a short loop. I thought of the games worked on by my favorite video game composer, David Wise. That led me to consider the beginning of the bonus theme from Donkey Kong Country (though there were multiple composers on this game and I'm not sure which wrote this particular song). It has a simple chord progression: I, V, vi, IV, I, V, IV to V, I. I decided to use the same chord progression, though the notes are different and my song actually sounds quite different than what it was inspired from. I used two chiptune instruments, which went with the game's retro feel (also because I was having trouble finding a marimba in FL Studio, but maybe that's for the best). There is some percussion, but it's very soft and you may only notice it subconciously. Overall, it was a quick song to write and I'm very pleased with the results. I may try to hone my skills at writing chiptune music in the future.

Tags: music, gamedev

Introducing Gate

As I mentioned previously, I've been trying my hand at game development in Rust recently using SDL2. Even though SDL2 is a general purpose cross-platform game library, I still think it is good practice for a game developer to create a layer of code specific to their own needs that acts as a gateway between the game logic and everything else (rendering, audio, user input, loading and saving data, etc.). This keeps the game logic clean and helps with possible migrations later. So, I did write that layer of code. And after I wrote it, I thought others might benefit from seeing this code, so I decided to make it open source.

This is how Gate was created. Gate is tailored to my own use cases, so it might not line up exactly with what other game developers want, but it may be a good starting point regardless. Things like the user input and audio just ended up being a thin wrapper over SDL2, so there's not much exciting happening there. But the rendering uses an interesting shader that I wrote for displaying pixel art properly at any scaling or rotation. Also, the texture packing takes place as part of the build process, and I generate enums to easily reference assets from the source code. Pretty cool!

To go along with Gate, I made a demo game that demonstrates its capabilities. This is a simple 2D platformer, and it is also open source. It's actually pretty fun, despite being short. Currently, you need to build from source in order to actually play the game, which is a bit of a problem for non-coders. I'm hoping to make a WebAssembly/WebGL backend for Gate so that anyone can just play it on a webpage. If you just want to see some footage, you can watch this video.

Tags: coding, gamedev