Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

How a One-Tap Game Like Coreball Works: Rotation, Collision and Timing

One-tap browser games look trivial, but they are a nice exercise in game loops, angles and collision checks. I spent some time playing Coreball and sketched how its core mechanic could be built in plain JavaScript.

One-tap browser games look trivial, but they are a nice exercise in game loops, angles and collision checks. I spent some time playing Coreball and sketched how its core mechanic could be built in plain JavaScript.

The mechanic

A circle (the core) rotates at a constant speed. Each tap fires a pin from the bottom of the screen. When the pin reaches the core it sticks at whatever angle the core is currently facing. If the new pin lands too close to an existing pin, the round ends. Clear all pins and you move to the next level.

Representing stuck pins

You do not need to track pin positions in screen space. Store each pin as an angle relative to the core:

const pins = [];        // angles in radians, relative to the core
let rotation = 0;       // current rotation of the core
const SPEED = 0.03;     // radians per frame
const MIN_GAP = 0.18;   // smallest allowed angle between two pins

function update() {
  rotation = (rotation + SPEED) % (Math.PI * 2);
}

The collision check

When a pin arrives, its angle on the core is the firing angle minus the current rotation. Then you compare it with every stuck pin:

function angleDiff(a, b) {
  const d = Math.abs(a - b) % (Math.PI * 2);
  return d > Math.PI ? Math.PI * 2 - d : d;
}

function shoot() {
  const hitAngle = (Math.PI / 2 - rotation + Math.PI * 2) % (Math.PI * 2);
  const crash = pins.some(p => angleDiff(p, hitAngle) < MIN_GAP);
  if (crash) return gameOver();
  pins.push(hitAngle);
}

Drawing is just a loop over pins, rotating each by rotation before rendering a line and a small circle.

Making levels harder

  • Increase SPEED gradually.
  • Start the level with a few pins already stuck.
  • Reverse direction every few seconds (SPEED *= -1).
  • Add a small random speed wobble so the rhythm is harder to learn.

That last one is what makes the real game tricky: you cannot rely on a fixed rhythm, you have to watch the gaps.

If you want to feel how the timing works before building your own version, you can play Coreball in the browser. It is a good reference for how little you need to make a game that is hard to put down.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.