Back to the blog
Creative Coding

I Built a Game Where Everything Is Generated by Code

July 2, 2026 6 min read

It started as a dumb question

One evening I asked: "can you make music with code?" A few hours later it had snowballed into a complete, playable game. No downloaded assets. No game engine. No dependencies. Everything you see and hear is computed from a short recipe.

This is the story of that snowball — and the one idea that made it all click.

1. Music from a formula

The first experiment was a synthesizer written by hand: fill an array with samples, sample by sample. A sine wave here, a square wave there, an envelope to shape each note. Within an hour it had grown into:

  • a chill lo-fi loop,
  • an 8-bit chiptune with proper NES-style channels (two pulse waves, a triangle bass, a noise channel for drums) — including the signature trick where chords are arpeggiated at ~50 Hz because each channel is monophonic,
  • a boss-fight theme in A harmonic minor.

None of it is a recording. It's the notes, the waveforms, the math.

2. Sprites from a grid

If music is "notes, not a recording," what's the equivalent for a sprite? The grid, not the image. A character drawn as rows of text:

"....KhhhhhhK...."
"...KhhsssshhK..."
"...Khsessesh K.."   // eyes

Plus a dictionary mapping each character to a color. A 16×16 sprite is ~256 characters of text. To prove it was self-contained, I even wrote the PNG encoder by hand (zlib + a few chunks). Animating it? Swap four lines of text between two poses.

3. The detour that taught the real lesson

Someone asked: "so why not generate a 1080p image in code?" Great question. I rendered a 1920×1080 Mandelbrot set in ~50 lines, in 9 seconds.

That's when the principle crystallized:

A file is either computed detail or stored detail. Code gives you the first for free. Not the second.

A fractal has infinite detail from a 2-line formula. A 16×16 sprite has 256 hand-placed pixels. A photograph has ~2 million pixels that no short formula can regenerate — which is exactly why you can't "code" it, and why that's the job of an AI image model or an artist. The dividing line isn't resolution. It's compressibility: is the content describable by rules?

4. The game

With music and sprites sorted, the rest was assembly. CodeQuest is a Vampire-Survivors-style survival game: hordes of enemies that home in on you, an auto-firing weapon, XP gems, level-ups, and a skull boss with its own soundtrack that kicks in when it appears.

The whole thing — rendering, physics, enemy AI, two procedural soundtracks, particle effects, a scrolling camera — is one index.html, ~28 KB, zero dependencies, no build step. It's the entire game, in a text file you can version-control.

5. This is literally how the classics were made

Here's the part that turns a weekend hack into a history lesson: this is how the games you grew up with were built.

The NES couldn't store recorded audio. Its sound chip — the Ricoh 2A03 — gave composers five channels: two square waves, a triangle, a noise channel, and one costly sample channel most games barely touched. A cartridge held kilobytes; there was no room for an MP3. So music wasn't recorded, it was described — pitches, waveforms, durations. The recipe, not the result. Exactly what CodeQuest does. (Zelda is a neat tell: its Japanese Famicom Disk System version had extra audio hardware, and Nintendo scaled the music down for the cartridge release.)

And the constraints bred genius, not compromise. Koji Kondo wrote the entire Super Mario Bros. soundtrack into roughly 40 KB across those five lo-fi channels — and made melodies the whole planet still hums. He reused material the way I reuse a function:

  • The power-up jingle you hear when Mario grabs a mushroom is the "Course Clear" level-complete fanfare, played at a wildly faster tempo — one composed cue, two uses.
  • Themes were deliberately short and loopable, built to repeat for minutes without grating. The constraint became the style.

We didn't love that music despite the limits. The limits are why we loved it — scarcity forces melody. CodeQuest is just a tiny modern echo of the same trick: when you can't store everything, you describe it — and it turns out "describable" and "beautiful" overlap far more than you'd guess.

6. Why this matters (beyond the fun)

For a minimalist game, procedural generation is a superpower:

  • Tiny. Kilobytes, not megabytes. No asset pipeline.
  • Version-controllable. Every sprite and song is a diff in a text file.
  • Infinitely tweakable. Change two numbers, get a new level or a new tune.

And the hybrid future is obvious: use an AI image model (Nano Banana, GPT-image) for the look of a complex sprite, then bring it back into code — downscale, quantize to a small palette, and you have an editable, tiny, animatable asset again. AI for the shape, code for the detail you want to keep light.

Try it

It started as a dumb question. It ended as a method. Next stop: iOS.


Also on Medium. I build all this solo, in public — andygarcia.pro.

A project like this one?

I design and deploy products like this. Let's talk.

Let's talk