This tiny demo shows simple 2D collision detection (circle vs circle). Use the arrow keys to move the green circle. When it touches the red circle, a collision event occurs.
// distance check
const dx = a.x - b.x;
const dy = a.y - b.y;
const dist2 = dx*dx + dy*dy;
if (dist2 <= (a.r + b.r)*(a.r + b.r)) {
// collision!
}
This demo is intentionally tiny so you can open it quickly in-browser. It demonstrates detection and a simple visual reaction.