๐ŸŽฎArcadeLab

Orbit Catch

by PlasmaMeteor43
336 lines8.8 KB
โ–ถ Play
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <title>Orbit Catch</title>
  <style>
    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      user-select: none;
      -webkit-user-select: none;
      touch-action: manipulation;
    }
    body {
      background: #0b1020;
      color: #f8fafc;
      font-family: system-ui, -apple-system, sans-serif;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100dvh;
      overflow: hidden;
    }
    #game-wrap {
      position: relative;
      width: 100vw;
      max-width: 420px;
      height: 100dvh;
      max-height: 760px;
      background: radial-gradient(circle at top, #172554, #090d16 70%);
      overflow: hidden;
    }
    canvas {
      display: block;
      width: 100%;
      height: 100%;
    }
    .hud {
      position: absolute;
      top: 18px;
      left: 0;
      right: 0;
      display: flex;
      justify-content: space-between;
      padding: 0 22px;
      font-weight: 700;
      font-size: 18px;
      pointer-events: none;
      text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
    }
    #overlay {
      position: absolute;
      inset: 0;
      background: rgba(9, 13, 22, 0.78);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 14px;
      text-align: center;
      padding: 24px;
    }
    #overlay.hidden {
      display: none;
    }
    h1 {
      font-size: 32px;
      letter-spacing: 0.5px;
    }
    p {
      color: #cbd5e1;
      max-width: 280px;
      line-height: 1.4;
      font-size: 15px;
    }
    button {
      margin-top: 6px;
      background: #38bdf8;
      color: #082f49;
      border: none;
      border-radius: 999px;
      padding: 13px 28px;
      font-size: 16px;
      font-weight: 800;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <div id="game-wrap">
    <div class="hud">
      <div>Score: <span id="score">0</span></div>
      <div>Best: <span id="best">0</span></div>
    </div>
    <canvas id="game"></canvas>
    <div id="overlay">
      <h1 id="title">Orbit Catch</h1>
      <p id="desc">Tap anywhere to launch your orb into the target ring before it drifts away. Chain hits for streak points!</p>
      <button id="play-btn">Tap to Play</button>
    </div>
  </div>

  <script>
    const canvas = document.getElementById("game");
    const ctx = canvas.getContext("2d");
    const scoreEl = document.getElementById("score");
    const bestEl = document.getElementById("best");
    const overlay = document.getElementById("overlay");
    const titleEl = document.getElementById("title");
    const descEl = document.getElementById("desc");
    const playBtn = document.getElementById("play-btn");

    let width = 0;
    let height = 0;
    let dpr = 1;

    function resize() {
      const rect = canvas.parentElement.getBoundingClientRect();
      dpr = Math.min(window.devicePixelRatio || 1, 2);
      width = rect.width;
      height = rect.height;
      canvas.width = width * dpr;
      canvas.height = height * dpr;
      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
    }
    window.addEventListener("resize", resize);
    resize();

    const BEST_KEY = "orbit_catch_best_v1";
    let bestScore = Number(localStorage.getItem(BEST_KEY) || 0);
    bestEl.textContent = bestScore;

    let running = false;
    let score = 0;
    let streak = 0;
    let orb = null;
    let target = null;
    let particles = [];
    let shake = 0;

    function makeTarget(yPos, speedScale = 1) {
      const radius = Math.max(24, 38 - Math.min(score * 0.35, 13));
      const dir = Math.random() < 0.5 ? -1 : 1;
      const baseSpeed = (75 + Math.min(score * 4, 150)) * speedScale;
      return {
        x: width * (0.25 + Math.random() * 0.5),
        y: yPos,
        r: radius,
        vx: dir * baseSpeed,
        pulse: 0
      };
    }

    function resetGame() {
      score = 0;
      streak = 0;
      particles = [];
      shake = 0;
      scoreEl.textContent = 0;

      orb = {
        x: width / 2,
        y: height * 0.82,
        r: 11,
        vx: 0,
        vy: 0,
        flying: false
      };
      target = makeTarget(height * 0.34, 1);
    }

    function spawnBurst(x, y, color, count = 14) {
      for (let i = 0; i < count; i++) {
        const angle = (Math.PI * 2 * i) / count + Math.random() * 0.3;
        const speed = 60 + Math.random() * 140;
        particles.push({
          x,
          y,
          vx: Math.cos(angle) * speed,
          vy: Math.sin(angle) * speed,
          life: 1,
          color
        });
      }
    }

    function launchOrb() {
      if (!running || orb.flying) return;
      const dx = target.x - orb.x;
      const dy = target.y - orb.y;
      const dist = Math.hypot(dx, dy) || 1;
      const speed = 640;
      orb.vx = (dx / dist) * speed;
      orb.vy = (dy / dist) * speed;
      orb.flying = true;
    }

    function endGame() {
      running = false;
      shake = 10;
      spawnBurst(orb.x, orb.y, "#fb7185", 20);
      if (score > bestScore) {
        bestScore = score;
        localStorage.setItem(BEST_KEY, bestScore);
        bestEl.textContent = bestScore;
      }
      titleEl.textContent = "Missed!";
      descEl.textContent = `Final score: ${score} ยท Best: ${bestScore}`;
      playBtn.textContent = "Play Again";
      overlay.classList.remove("hidden");
    }

    playBtn.addEventListener("click", (e) => {
      e.stopPropagation();
      overlay.classList.add("hidden");
      resetGame();
      running = true;
    });

    canvas.addEventListener("pointerdown", (e) => {
      e.preventDefault();
      if (running) launchOrb();
    });

    let lastTime = performance.now();
    function loop(now) {
      const dt = Math.min((now - lastTime) / 1000, 0.05);
      lastTime = now;

      update(dt);
      draw();
      requestAnimationFrame(loop);
    }

    function update(dt) {
      if (shake > 0) shake = Math.max(0, shake - dt * 35);

      for (let i = particles.length - 1; i >= 0; i--) {
        const p = particles[i];
        p.x += p.vx * dt;
        p.y += p.vy * dt;
        p.life -= dt * 2.4;
        if (p.life <= 0) particles.splice(i, 1);
      }

      if (!running) return;

      target.x += target.vx * dt;
      target.pulse += dt * 5;
      if (target.x - target.r < 16) {
        target.x = 16 + target.r;
        target.vx = Math.abs(target.vx);
      } else if (target.x + target.r > width - 16) {
        target.x = width - 16 - target.r;
        target.vx = -Math.abs(target.vx);
      }

      if (orb.flying) {
        orb.x += orb.vx * dt;
        orb.y += orb.vy * dt;

        const dist = Math.hypot(orb.x - target.x, orb.y - target.y);
        if (dist <= target.r + orb.r * 0.4) {
          streak += 1;
          const gained = 1 + Math.floor((streak - 1) / 3);
          score += gained;
          scoreEl.textContent = score;
          spawnBurst(target.x, target.y, "#38bdf8", 14);

          orb.x = target.x;
          orb.y = target.y;
          orb.vx = 0;
          orb.vy = 0;
          orb.flying = false;

          const nextY = score % 2 === 1 ? height * 0.28 : height * 0.42;
          target = makeTarget(nextY, 1 + Math.min(score * 0.015, 0.6));
        } else if (
          orb.y < -30 ||
          orb.y > height + 30 ||
          orb.x < -30 ||
          orb.x > width + 30
        ) {
          endGame();
        }
      }
    }

    function draw() {
      ctx.save();
      ctx.clearRect(0, 0, width, height);

      if (shake > 0) {
        ctx.translate((Math.random() - 0.5) * shake, (Math.random() - 0.5) * shake);
      }

      if (target) {
        const ringPulse = Math.sin(target.pulse) * 3;
        ctx.beginPath();
        ctx.arc(target.x, target.y, target.r + ringPulse, 0, Math.PI * 2);
        ctx.strokeStyle = "#38bdf8";
        ctx.lineWidth = 4;
        ctx.stroke();

        ctx.beginPath();
        ctx.arc(target.x, target.y, 6, 0, Math.PI * 2);
        ctx.fillStyle = "#bae6fd";
        ctx.fill();
      }

      if (orb) {
        ctx.beginPath();
        ctx.arc(orb.x, orb.y, orb.r, 0, Math.PI * 2);
        ctx.fillStyle = "#fbbf24";
        ctx.fill();
      }

      for (const p of particles) {
        ctx.globalAlpha = Math.max(0, p.life);
        ctx.beginPath();
        ctx.arc(p.x, p.y, 4, 0, Math.PI * 2);
        ctx.fillStyle = p.color;
        ctx.fill();
      }
      ctx.globalAlpha = 1;

      ctx.restore();
    }

    resetGame();
    requestAnimationFrame(loop);
  </script>
</body>
</html>

Game Source: Orbit Catch

Creator: PlasmaMeteor43

Libraries: none

Complexity: complex (336 lines, 8.8 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: orbit-catch-plasmameteor43" to link back to the original. Then publish at arcadelab.ai/publish.