0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Only 3KB! Introducing Playload, a Strange and Wonderful Game Engine

0
Posted at

This is the English version of my original Japanese article.

I'm the creator of Pyxel.

On a whim, I built a tiny game engine with a limit of just 3KB.

The Playload editor and the dungeon game Glyph Quest

It's called Playload.

It's available as open source on GitHub. If you like it, please give it a star!

Here are the basic specifications:

  • JavaScript, up to 3KB after compression (3,000 bytes)
  • 160×144 pixels, 8 colors, with a CRT display effect
  • 8×8 pixel characters, symbols, and Unicode emoji
  • Three-channel audio compatible with ZX Spectrum 128 PLAY
  • Four directions and two buttons
  • An API with six functions, two variables, and one callback
  • Edit, run, save, and share entirely in your browser

Why 3KB?

Hobby programming used to be a battle against tiny amounts of memory: 32KB, 64KB, and so on. There were even "one-screen programs," where the challenge was to squeeze as much as possible into a program whose listing fit on a single screen.

Are those battles over size a thing of the past? Not at all. The battlefield has simply moved to the length of a URL you can post on X!

X shortens URLs of up to 4,096 characters to 23 characters. Even after allowing for the app's base URL, that leaves roughly 4,000 characters for data. Working backward from the extra space required by Base64 encoding gives us about 3,000 bytes of compressed data. That's why I set the code limit at 3KB after compression.

Stay within that limit, and the entire game can fit in the URL's payload. The game is the payload—a payload you can play. Hence, Playload!

A Playload game URL looks like this:

https://kitao.dev/playload/app/#v1.compressed-game-code

The JavaScript code is compressed, encoded as Base64url, and appended to the URL.

How much can you make in 3KB?

Shooters, platformers, puzzles. Naturally, all the official sample games fit within 3KB too.

Shooter · 2.34KB Jump · 1.76KB Lights Out · 1.35KB
Play Shooter in a new tab Play Jump in a new tab Play Lights Out in a new tab
An Invaders-style shooter A jumping platformer The Lights Out puzzle

Click an image to launch the app. You can edit its code directly too.

Emoji: a modern take on ASCII games

To let you make games without preparing image files, Playload includes a large collection of built-in 8×8 pixel-art sprites mapped to Unicode emoji.

Unicode emoji and their corresponding built-in Playload sprites

Write one of these characters in your code, and Playload displays its pixel-art sprite.

For example, you can write a game level as a string, using emoji such as 👾 and 💎.

const stage = [
  '▓▓▓▓▓▓▓▓▓▓',
  '▓👾  💎    ▓',
  '▓  ▓▓    ▓',
  '▓     🏰  ▓',
  '▓▓▓▓▓▓▓▓▓▓',
];
put(1, 1, stage.join('\n'));
function tick() {}

Glyph Quest, the sample shown at the start of this article, works this way too. It has three stages and fits in about 2.05KB.

Sound from the ZX Spectrum 128

The Sinclair ZX Spectrum 128, with its heat sink on the right

For sound, I implemented compatibility with the PLAY command from the ZX Spectrum 128, a British home computer from the 1980s.

This model is nicknamed the "toastrack" because of the heat sink on its right-hand side. In BASIC, you could play three-channel music simply by passing it strings.

In Playload, you pass play() a string containing notes and tempo settings. Music is written as a string too.

You can hear it in action in these samples:

  • Chiptune sample: a complete tune with melody, bass, and noise drums. About 1.26KB.
  • Music Box sample: a small music tool where you compose by arranging notes and rests. About 0.90KB.

Save your code with a bookmark

Since the code is the URL, you can save it as a browser bookmark.

The URL updates as you edit. Bookmark milestones such as "before adding enemies" or "stage 2 complete," and you can return to those versions whenever you like.

Strange and wonderful games from the community

People have already started sharing interesting creations that somehow squeeze into 3KB.

Road Dodge

Road Dodge by sslab is a driving game where you dodge oncoming traffic. Pick up fuel cans to keep going, and earn bonuses for near misses.

Road Dodge gameplay

Play Road Dodge / The creator's post announcing the updated version

Endless Ghost Tower

Endless Ghost Tower by rococomico is a maze game where you avoid ghosts, collect items, and find the exit. It gets harder as you advance through the floors.

Endless Ghost Tower gameplay

Play Endless Ghost Tower / The creator's post announcing the updated version

Bit-Rate Rush 3KB

Bit-Rate Rush 3KB by ゲームで見るITの世界 (@0_game_it) is a survival game where you fight your way through waves of enemies while staying out of their reach.

Bit-Rate Rush 3KB gameplay

Play Bit-Rate Rush 3KB / The creator's post announcing the updated version

That game you keep seeing in ads

広告でよく見るゲーム ("That game you keep seeing in ads") by キクチユウ (@daifuku085) has you choose gates that increase or decrease your crowd, then face a group of enemies at the end. Yes, that game from the ads—within 3KB.

Gameplay from the revised version of That game you keep seeing in ads

Play the game / The creator's post announcing the revised version


Give Playload a try and take on the 3KB limit yourself.

I'd love to see what you make and share on X!

I also share Playload creations on my X account. Feel free to follow along.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?