← all demos · chapter 06

The cube codex — one protagonist, 104 effects

Meet the cube. It paces its little stage the way a fighting-game character idles on theirs — and every card gives it a different power: a fireburst, a waterhose, a bolt from the sky, a halo that follows it around. Each effect is a static loop (alive while the cube goes about its day) plus a press reaction (the cast, the strike, the pose — click a running card to trigger it; some effects aim at where you click). If the bestiary was buttons possessed by elements, this codex is what those elements look like attached to a character: decorations, neutral energy, and fighting moves. Press ▶ Run all, or click any single card to wake just that one. Under each card, open code loads its full source into the editor at the bottom — every effect is ~25–40 lines, self-contained, and editable.

Every move also hides a rhyme. A rhyme is the same effect with two or three dials turned — a palette, a speed, a direction, a count — and nothing else. Click ⇄ its rhyme on any card to swap them in place (104 more demos, folded into the same cards), then open code to read the pair side by side: the rhyme's opening comment names exactly which dials moved. Fireburst becomes Frostburst by swapping a palette and letting the shards hang; the knockback becomes a launcher by aiming the same helplessness upward; the tempest becomes the doldrums by swapping which half is the idle and which is the press. Once a recipe is understood, its neighbours are nearly free. The rhymes travel with the Godot port too: in the downloadable project, right-click any card to swap original ⇄ rhyme — each family file scenes/cubefx/<family>.gd has a sibling <family>_r.gd that overrides only the branches whose dials moved, so diffing the pair is the same lesson in GDScript.

↓ jump to the code editor

The editor — pick an effect above

Every effect is one function, make(u), returning { frame(dt, t), press(x, y) }. The kit u: ctx, W, H (canvas), G (the ground's y), C (the cube: x, y, s, face, vx, pace…), stage() (backdrop + floor), tickCube(dt) (the patrol — set C.pace = false to take control), drawCube(), glow(x, y, r, colour), rand(a, b), TAU. Draw behind the cube, call drawCube(), draw in front — the sandwich is the whole layering system.

The preview is bigger than the cards, and every effect is written relative to W, H, G, and the cube's size — the same code scales up without edits. Click the preview to trigger the press reaction.

Try tweaking: every effect keeps its magic numbers near the top. The cube's stroll lives in the kit — find tickCube in the editor's loaded code and slow the stroll, or set C.pace = false and drive C.x yourself. Swap an attack's palette (an ice fireburst, a golden shadow clone) and you've invented effect #105.

In Godot: all 104 are ported — fourteen family files in scenes/cubefx/, paged by family in cube_vfx.gd (grab the Godot project and press its menu's S). The kit's cube patrol, stage, and glow helpers live in scenes/cubefx/kit.gd; on a real character you'd hang the same logic on a CharacterBody2D with GPUParticles2D children and a Tween per move. In Unity: CubeVfx2D.cs (sprite cube + the effect-slot anatomy) and CubeVfx3D.cs (a real 3D cube: particle bursts, a following halo light, an aura) — attach one script, press Play. In Unreal: SSCubeVfx is the 3D patrol-cube actor with named effect slots (Niagara + a following point light), and recipes/cube-vfx.md maps each family onto Niagara, materials, and UMG. Chapter 06 teaches the ingredients; chapter 05 explains why the cube's stroll makes everything feel inhabited.