Shall We Play a Game?
A 404 page easter egg from 2016, rebuilt from scratch as react-pong.
Nobody lands on a 404 page on purpose. You followed a link, it went nowhere, and now you are a little annoyed. In 2016 I hid a game of Pong on Moved’s: “Lost? The page you are looking for does not exist. Feel free to pong for a while.” It was an easter egg, and an attempt to turn one of the web’s small frustrations into something surprisingly delightful.
It was also an early experiment in taking someone else’s library and making it my own. The game started as strawbserve’s angular-pong, which I forked and rewrote over a weekend for that one page: a single player against the computer, a new look, a few fixes, and a computer opponent with a habit of talking smack.
That page is long gone, and the game isn’t live anywhere anymore. This month I brought it back as react-pong, rebuilt from the ground up for a modern page. It isn’t a screenshot of Pong; it’s right here:
normal
press ? for help
Why start over
The 2016 version was built to own a whole page, and it shows. It listened for the arrow keys on the entire document, so anywhere else it would steal them from the page around it. It moved everything on timers that fired every hundredth of a second, so the speed of the game depended on how punctual the browser felt. Its sounds were three audio files loaded from a folder it assumed was there, and it needed AngularJS and a handful of other libraries on the page before it could do anything at all.
None of that survives on a modern site. So react-pong keeps the look, the rules, and the attitude of the original, and none of its code.
A good guest
The goal was a game you can drop into somebody else’s page without it taking over. The keys reach the game only while the court has focus, and the keys it doesn’t use pass through to the page. A rally pauses by itself when you click away, switch tabs, or scroll the court out of view. Nothing is global, so several games can share a page, and removing one cleans up everything it started.
Everything on the court is plain HTML and CSS: the ball and paddles are elements, and the score and messages are real text a screen reader can read. The blips are synthesized on the spot rather than loaded from files. There are light and dark palettes, and every color and size is a CSS custom property. The game on this page is following this site’s theme switch.
Releases install straight from GitHub, and using it in React is a few lines:
// pnpm add github:jasondecamp/react-pong#semver:^0.2.0
import { Pong } from 'react-pong';
import 'react-pong/styles.css';
<div className='arcade'>
<Pong difficulty='hard' />
</div>
Underneath is an engine with no framework at all, for pages that don’t use React. Every option has a control in the playground, which writes out the matching code as you go.
Getting the feel right
Pong has almost no rules, so everything rides on how it feels. Most of the work went there.
The ball. It moves by how much time has passed rather than by the frame, so the game plays at the same speed on any screen. Every paddle hit makes it 5% faster. The flat of a paddle straightens its path a little, so rallies don’t get steeper and steeper; a moving paddle drags the ball along with it; and the corners send it off at a sharp angle. That gives you three ways to place a shot with nothing but up and down.
The opponent. At easy, normal, and hard, the computer reacts ten times a second, moves under the same speed limits as you, and aims a little imperfectly. It also plays shots: it swings through the ball to bend its path, and now and then it goes for a corner. The fourth difficulty, impossible, drops every handicap. It works out where the ball will arrive the moment it is hit and goes straight there, and its paddle glows like a watching eye the whole time. The only thing that can beat it is the speed limit on its paddle, which is the same as yours.
The arcade. Until you serve, the computer plays both paddles, like a cabinet waiting for a coin. The first serve is tossed for. The ball takes its color from where it is on the court, so a ball coming at you wears your opponent’s color, and it leaves a fading trail. A paddle one point from winning starts to glow. And the computer still talks: it gloats when it scores, and it makes excuses when you do.
Built with Claude Code
Like Ethereal and react-snow, react-pong was written by Claude Code, and I never edited the code by hand. It began the same way too, with Claude interviewing me about every decision until the answers added up to a plan.
I expected the rest to be mostly hands off. It wasn’t, because the plan could say what the game does but not how it should feel, and only playing it could settle that. So it turned into far more testing and refining than I had planned: play a few games, say what felt wrong, play the next version. I was not going to complain about a job that was mostly playing Pong.
The ball’s trail is a good example. It was first built as a row of ghosts that followed the ball, and that looked wrong the moment I saw it. I asked for ghosts that stay where the ball left them and fade one by one, then tried the spacing until it stopped looking crowded. The glow on the impossible paddle took three tries: a pulse toward a paler color read as fading out, and a two-beat heartbeat was too lively for something meant to be menacing, before it became the slow, steady swell it has now. And watching the computer play itself in attract mode showed me something I had never noticed while playing against it: sometimes it seemed to step out of the ball’s way. Now when it misses, it looks like a miss.
What it accomplished
The easter egg is back, and it is a far better guest than the one it replaces. It fits in a box on someone else’s page, keeps its hands off that page’s keyboard, and plays the same on any screen.
It is also plainly unfinished. It is version 0.2, and the physics and the opponent are still being tuned by playing. It is keyboard only, so on a phone you can watch the computer play itself but you can’t take over. And it is one player against the computer, with no way yet to play another person.
That is fine, because this is meant to be a starting point. I have ideas for turning Pong into something more complex and more strategic, and this is the foundation for them. A rapid fire mode with several balls in play at once is next, and power-ups that turn your next hit into a trick shot come after that. Someday, I hope, you will be able to play a friend over the internet. For now, the computer is waiting, and it has a few things to say about your backhand.