AI Game Dev Search

Music that follows the player: seven tracks, one theme, written in code

One prompt wrote seven looping tracks as notes in code, all on one seven-note theme, that change with the room and sit under the sound effects. Press play on each, then play the finished game.

Tested with Phaser 3.80.1 · Claude Code · Opus 5.5

This is the real result. Click it and play. Open full screen

What we asked“The game has sound effects but no music. Write an original soundtrack for it in code: calm music for the camps, music for exploring each section, rising tension for the storm chase and a release at dawn, all sharing one theme. It should follow what the player is doing, sit under the sound effects, and have its own mute. Don't change how anything plays.”

What happened

You
The game has sound effects but no music. Write an original soundtrack for it in code: calm music for the camps, music for exploring each section, rising tension for the storm chase and a release at dawn, all sharing one theme. It should follow what the player is doing, sit under the sound effects, and have its own mute. Don't change how anything plays.
  • Used the game-music skill
  • Wrote one seven-note theme and seven eight-bar tracks as notes in a text file
  • Wrote a small sequencer that switches tracks on the next bar or beat
  • Rendered every track offline and measured its loudness
  • Ran a 96-second scripted tour through 14 game states
  • Wrote tests/music.mjs: 13 checks
Claude
I've written seven music tracks for the game, all built on one short theme. The music changes with the room you're in, sits under the sound effects, and has its own mute (B key or the music on/off button above the sound button). Nothing about how the game plays changed. I couldn't listen to it, so I measured it: no loop has an audible seam, the tracks are within 2 LU of each other, and in the game the music sits 6 to 8 dB under a jump and 17 dB under the death sound.

The game has effects, sound, art and a shape. The last layer is music, and it comes last because it needs to know everything else: where the player is, what is happening, and what the sound effects are doing.

Step 10: a soundtrack in code

The game has sound effects but no music. Write an original soundtrack for it in code: calm music for the camps, music for exploring each section, rising tension for the storm chase and a release at dawn, all sharing one theme. It should follow what the player is doing, sit under the sound effects, and have its own mute. Don't change how anything plays.

It took 15 minutes and $2.24. Claude loaded the game-music skill and wrote seven tracks as notes in a text file, played by a small sequencer in the browser. There is nothing to download or license, and you can edit the music as text.

All seven open with the same theme, seven notes: G D C B, then A B G. Each track changes it to suit the place.

TrackKeyTempoCharacter
CampG major72Slow and round, no drums
MeadowG major100Light, with a pushed rhythm
Spring HillsG with an F natural (Mixolydian)108Bouncy, off-beat chords
QuarryE minor96Low melody and toms
Lantern RidgeG with a C sharp (Lydian)88Floating, with a high “firefly” arpeggio
StormE harmonic minor152, then 167The theme twice as fast, plus a fast high alarm part
DawnG Lydian into major76The theme stretched out, with a bell answering it

Every loop is eight bars long, and every track is in G major or E minor, so a switch from one to the next never changes key.

How it follows you. Camps play calm music, and the last camp before the storm adds a slow distant thump. Each section has its own track, and drums fade in for the section’s final test room. The storm chase starts on the next beat, adds weight in each of its three segments, and the last mile plays 10% faster. At dawn the storm fades out over three seconds into the release track. Dying keeps the same loop playing and only dips it for a moment, and nothing starts until your first key press or click.

Hear them

Press a track. Each is one 8-bar loop, rendered offline from the same notes the game plays.

A player we built for this page. Listen to Camp, then Storm: it is the same seven notes, played twice as fast with an alarm over them.

What it measured

  • Loudness. The tracks’ peaks are between -7.6 and -3.0 dBFS with nothing clipped, and the tracks are within 2.0 LU of each other, so switching doesn’t jump in volume. No loop has an audible seam.
  • Under the effects. In the game the music averages -38 to -40 dBFS: 6 to 8 dB under a jump and 17 dB under the death sound.
  • Following the player. A 96-second scripted run through 14 states and events changed the music every time, and none changed early: tracks switched on the next bar, and the storm on the next beat.
  • Mutes. B mutes the music only and stays off after a reload. M silences music and effects together.
  • Nothing plays differently. The mechanics (48 checks), journey, sound (43) and difficulty numbers are the same before and after. One older test showed a small difference in jump peak (99.3 against 104.3 px), but it shows the same two values on back-to-back runs of the untouched game, so the music doesn’t cause it.
  • A new test covers the music: 13 of 13 pass, including no music before the first input and the right track in every room.

Play the finished game

This is the whole thing: 37 rooms in five sections, with everything from the previous six parts. Click it first, because browsers don’t play sound before a key press. Music is B, sound M.

Before: the journey from part 6, with effects and sound and no music. Starts at Lantern camp; the rest of the game is ahead of you if you want it.

After: the finished game. Walk into the Quarry, then reach the storm, and listen for the track to change on the beat. Starts at Lantern camp; the rest of the game is ahead of you if you want it.

What to take from this

  • One theme is the whole trick. Seven tracks with different moods sound like one soundtrack because they share seven notes and two keys.
  • Tell Claude what you hear. It can’t listen, but it can change the notes the moment you say “the storm is too busy”.
  • The whole series, in numbers: 13 Claude Code sessions, about $40 and about five hours in total, from an empty folder to a 37-room game.

Get the skill. Back to the overview.

The skill that made it work

It makes Claude write the music as notes in a text file, with one theme in every track, so the game can tell it what to do bar by bar.

game-music
  1. Write one short theme and build every track from it, so crossfades never change key.
  2. Switch tracks on the next bar (or beat), never mid-note, and never restart a loop when the player dies.
  3. Keep the music under the sound effects, with its own mute, and check the levels by measuring.

Save it as .claude/skills/game-music/SKILL.md in your project.

Was this useful?

Part 7 ofMake a complete platformer with AI
All parts →