A daily-challenge stacking game in 47 KB of vanilla JavaScript
We build and install real video walls for a living at CrownTV in New York, so for our first browser game we made one about stacking screens. It's called Screen Stack, it's free, and you can play it here: www.crowntv-us.c
We build and install real video walls for a living at CrownTV in New York, so for our first browser game we made one about stacking screens. It's called Screen Stack, it's free, and you can play it here: www.crowntv-us.com/game
The whole thing is four small files: one HTML page, one stylesheet, one script and a tiny audio file. That is about 34 KB of JavaScript and 47 KB in total (17 KB zipped). No engine and no libraries. Here are the four small tricks that made that possible.
1. The core mechanic is interval overlap
A screen slides back and forth. When you tap, the game compares it with the screen below as two 1D intervals:
const L = Math.max(cur.x, top.x);
const R = Math.min(cur.x + cur.w, top.x + top.w);
const ov = R - L; // overlap width
If ov <= 0 you missed and the run is over. Otherwise the new screen shrinks to the overlap, and whatever hangs past L or R goes into a list of falling pieces with a little spin so it tumbles away. That is the entire physics system.
2. A forgiving perfect window
Pixel-perfect drops are close to impossible on a phone, so a drop within a small tolerance of the screen below snaps into place and counts as perfect. Three perfects in a row make the wall slightly wider again, which gives players a way back after a bad start instead of a slow death spiral. A rare golden screen restores the full width if you land it perfectly.
3. A daily level with no server
Every player gets the same Daily Tower, and there is no backend involved. The game pulls its randomness from one function, and in daily mode that function is a tiny seeded PRNG (mulberry32) seeded with today's date:
rng = mode === 'daily' ? mulberry32(+today.replace(/-/g, '')) : Math.random;
Same date, same seed, same tower for everyone.
4. Sound without sound files
The sound effects are Web Audio oscillators: a short beep through a gain envelope. The pitch climbs with your combo (440 * 1.12 ** streak, capped), so a good run literally sounds like it is going up. Phones also get a short navigator.vibrate() buzz on a perfect drop and a longer one when you miss.
Small things that mattered
- The canvas is scaled by
devicePixelRatio, capped at 2, which keeps the pixel count sane on high-density phones. - High scores and settings live in
localStorage. The builds we upload to game portals make no network requests at all. - Results share as an emoji grid, Wordle-style, through
navigator.shareor the clipboard.
One thing the day job taught us
A fact from the hardware side that we like: in window displays, glass eats brightness. A rule of thumb from the nits guide on a related site of ours is to multiply the screen's nits by the visible light transmission of the glass, so 4,000 nits behind 70% glass reads closer to 2,800. None of that is simulated in the game, where every screen is equally bright.
If you try it, tell us your best tower and whether the difficulty curve feels fair. Play it here: Screen Stack
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.