Glyph Arena

Small TypeScript building blocks for 2D browser games. New here? Build a game in 30 minutes goes from an empty folder to something you can play, with no assets. Each package is an independent workspace member with no runtime dependencies, so a game composes only the pieces it needs.

Each module below is a separate workspace member; @fogrexon/glyph-arena bundles all of them into a single ESM build. Inside this repository the modules are consumed through workspace:*.

Play it

Five samples and the API docs, published from this repository — open the links, nothing to install:

SampleWhat it isSource
PickupTop-down collection: 8 gems in 60 s, three livesexamples/pickup-demo
CampA side-on duel in two rooms: three verbs, and enemies that take turnsexamples/camp
MarchEleven guards on a 92-column road: fight each one, or roll through it — one minute, instant retryexamples/march
ParryDash into an enemy to parry it; 20 waves from a fixed scriptexamples/parry
RunnerSide-scrolling platformer: three levels, no randomnessexamples/runner
API DocsOne page per package, and the front page this README becomesdocs/

Every row is checked against the deployment: each example declares its own page in package.json (glyphArenaPage), assemble-site.mjs publishes exactly those, and scripts/demo-links.test.mjs fails when the table and the declarations disagree in either direction.

Which name to import

Only @fogrexon/glyph-arena is meant for consumers. It bundles every module and re-exports their value exports flat, so a game imports one name instead of one per module (API page).

The @fogrexon/glyph-arena-* names are workspace-internal: they are not published on their own, so importing them from outside this repository will not resolve.

Packages

Generated from packages/ when the docs are built — do not edit this table by hand.

ModuleWhat it doesAPI
glyph-arena-actionsKeyboard action bindings for Glyph Arena.api
glyph-arena-assetsFetch-based asset loading with in-flight deduplication and success caching.api
glyph-arena-audioWeb Audio playback for Glyph Arena.api
glyph-arena-bodyA platformer body for Glyph Arena: gravity, a run with acceleration, a jump with coyote time and an input buffer, and axis-separated collision against a solid test you supply.api
glyph-arena-camera2D camera state and world-to-screen view matrix for Glyph Arena.api
glyph-arena-chaseWhether a pursuer should be walking toward something, and which way. One pure call per frame: ``ts const chase = chaseTarget( { x: enemy.x, w: enemy.w, dir: enemy.dir }, { x: player.x, w: player.w }, { sightPx: 224, stepTolerancePx: 0 }, (dir) => stepAhead(enemy, dir), ); ` It returns { noticed, dir, distancePx, walkable } and does nothing else: no state, no speed, no dt`, no defaults. The ground is probed in the direction it is about to walk, so "the way it looks" and "the way it walks" cannot disagree.api
glyph-arena-collideAxis-aligned bounding box overlap for Glyph Arena.api
glyph-arena-drawMinimal 2D canvas drawing helpers for Glyph Arena.api
glyph-arena-ecsMinimal entity-component storage for Glyph Arena.api
glyph-arena-gamepadPolling gamepad snapshots for Glyph Arena.api
glyph-arena-inputKeyboard and pointer input snapshot for Glyph Arena.api
glyph-arena-loopInjectable frame loop for Glyph Arena.api
glyph-arena-resetOne list of "put this back", run in the order it was written: ``ts const reset = createReset(); reset.add("player", () => { player = createBody(spawn, PLAYER_CONFIG); }); reset.add("commitClock", () => { lastCommitMs = -Infinity; }); reset.run(); // boot // … reset.run(); // retry — the same list, not a second one ``api
glyph-arena-sceneHierarchical scene graph nodes for Glyph Arena.api
glyph-arena-screenScreen space: the CSS box a canvas is laid out in, the bitmap it actually is, and the ratio between them.api
glyph-arena-tilemapTile maps as text, and the two questions a platformer asks of them: *what is in this box*, and *what am I standing on*.api
glyph-arena-timerTick-driven timer scheduling for Glyph Arena.api
glyph-arena-touchOn-screen controls: which zone a finger is on, whether it still counts as down, and how far a stick is pushed.api
glyph-arena-transform2D local transform storage and world-matrix composition for Glyph Arena.api
glyph-arena-tweenTick-driven scalar tweening for Glyph Arena.api

Putting it together

import { createWorld, createLoop } from "@fogrexon/glyph-arena";

const world = createWorld();

const entity = world.spawn();
world.set(entity, "stats", { hp: 10 });

const loop = createLoop({
  onFrame(time) {
    // `time` is the tick time reported by the injected clock.
  },
});

loop.start();

Each package's API doc (docs/api-*.md) lists its exports, options and edge cases; each package also has a README.md under packages/. The same pages are rendered to HTML and published at fogrexon.github.io/glyph-arena/docs.

Running a sample locally

Each page in the table above is a Vite build of one directory under examples/. For the pickup sample:

pnpm install
pnpm build
pnpm --filter @fogrexon/glyph-arena-pickup-demo dev

pnpm build is not optional here: a sample resolves @fogrexon/glyph-arena-* through each package's dist, so starting the dev server before the packages are built fails to resolve them. The other samples use the same command with their own package name (@fogrexon/glyph-arena-camp-demo, -parry-demo, -runner-demo).

Development

pnpm install
pnpm typecheck                   # no build needed: tsconfig `paths` maps packages to their src
pnpm build                       # required: dist is what npm, Pages and the gates below read
pnpm check:package-entry-points  # package.json entry points must exist
pnpm typecheck:public-api        # emitted declarations must keep the public API
pnpm smoke:pack-install          # pack, install offline, import + strict tsc
pnpm test

CI (.github/workflows/ci.yml) runs the same gates in this order:

install → typecheck → build → check:package-entry-points → typecheck:public-api → smoke:pack-install → test

See CONTRIBUTING.md for the definition of done and the repository layout.

Repository layout

API pages

One page per package.