TINY GAMES · TINY CODE · REAL RIVALRIES
Paddle duel. First to 7 beats S0S0, and the ball is one of its eyes.
— LINES
That's all of Zero Rally: paddles, ball physics, scoring and the computer player, counted live from this page's own code. A shared —-line arcade shell handles controls, sound and best scores for every game.
The heart of it, lightly simplified:
// ball meets your paddle: send it back
if (b.vx < 0 && hit(this.you, 24)) bounce(this.you);
// 5% faster each hit, plus spin from where it landed
b.vx = -b.vx * 1.05;
b.vy += (b.y - (py + PH / 2)) * .12;
// first to 7 wins
if (this.s[0] < 7 && this.s[1] < 7) return this.serve();
// move the head one cell
const h = [head[0] + dir[0], head[1] + dir[1]];
if (crash) return api.end(...);
this.body.unshift(h);
// ate a leaf? keep the tail and grow
if (onLeaf) { this.score++; this.place(); }
else this.body.pop();
// the ship fires by itself every 11 ticks
if (--this.cool <= 0) {
this.shots.push({ x: this.ship, y: H - 46 });
this.cool = 11;
}
// a shot touching a drone destroys both
if (Math.abs(f.x - s.x) < 16 && Math.abs(f.y - s.y) < 14)
f.dead = s.dead = true;
// where the ball lands on the paddle sets the angle
b.vy = -Math.abs(b.vy);
b.vx = (b.x - (this.px + PW / 2)) / (PW / 2) * 5;
// the first brick it touches breaks
const k = this.bricks.find(k => touching(b, k));
if (k) { remove(k); b.vy = -b.vy; }
Every game in the library shows its code like this, so creators can see how few moving parts a fun, competitive game needs.