🎮ArcadeLab

Neon Dodger

by PlasmaMeteor43
230 lines6.3 KB
▶ Play
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Neon Dodger</title>
  <style>
    * { box-sizing: border-box; margin: 0; padding: 0; }
    body {
      background-color: #0b0c10;
      color: #66fcf1;
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100vh;
      overflow: hidden;
    }
    #ui {
      display: flex;
      justify-content: space-between;
      width: 480px;
      margin-bottom: 10px;
      font-size: 20px;
      font-weight: bold;
      text-shadow: 0 0 8px #45a29e;
    }
    canvas {
      background: radial-gradient(circle at center, #1f2833 0%, #0b0c10 100%);
      border: 2px solid #45a29e;
      box-shadow: 0 0 20px rgba(102, 252, 241, 0.3);
      border-radius: 6px;
    }
    #instructions {
      margin-top: 12px;
      color: #c5c6c7;
      font-size: 14px;
    }
  </style>
</head>
<body>

  <div id="ui">
    <div>Score: <span id="score">0</span></div>
    <div>Best: <span id="best">0</span></div>
  </div>
  <canvas id="gameCanvas" width="480" height="600"></canvas>
  <div id="instructions">Use <b>Left / Right Arrows</b> or <b>A / D</b> to dodge • Press <b>Space</b> to restart</div>

  <script>
    const canvas = document.getElementById('gameCanvas');
    const ctx = canvas.getContext('2d');
    const scoreEl = document.getElementById('score');
    const bestEl = document.getElementById('best');

    let score = 0;
    let bestScore = localStorage.getItem('neonDodgerBest') || 0;
    bestEl.textContent = bestScore;

    let gameOver = false;
    let frameCount = 0;

    // Player object
    const player = {
      x: canvas.width / 2 - 20,
      y: canvas.height - 60,
      width: 40,
      height: 40,
      speed: 7,
      color: '#66fcf1'
    };

    let asteroids = [];
    let particles = [];
    const keys = {};

    window.addEventListener('keydown', e => {
      keys[e.code] = true;
      if (gameOver && e.code === 'Space') resetGame();
    });
    window.addEventListener('keyup', e => keys[e.code] = false);

    function spawnAsteroid() {
      const size = Math.random() * 35 + 20;
      const speed = Math.random() * 3 + 3 + (score * 0.05);
      asteroids.push({
        x: Math.random() * (canvas.width - size),
        y: -size,
        size: size,
        speed: speed,
        color: '#ff2e63'
      });
    }

    function createExplosion(x, y, color) {
      for (let i = 0; i < 25; i++) {
        particles.push({
          x: x,
          y: y,
          vx: (Math.random() - 0.5) * 8,
          vy: (Math.random() - 0.5) * 8,
          life: 1,
          color: color
        });
      }
    }

    function resetGame() {
      score = 0;
      scoreEl.textContent = score;
      asteroids = [];
      particles = [];
      player.x = canvas.width / 2 - 20;
      gameOver = false;
      loop();
    }

    function update() {
      if (gameOver) return;
      frameCount++;

      // Move player
      if ((keys['ArrowLeft'] || keys['KeyA']) && player.x > 0) {
        player.x -= player.speed;
      }
      if ((keys['ArrowRight'] || keys['KeyD']) && player.x < canvas.width - player.width) {
        player.x += player.speed;
      }

      // Spawn asteroids faster as score climbs
      const spawnRate = Math.max(15, 45 - Math.floor(score / 5));
      if (frameCount % spawnRate === 0) spawnAsteroid();

      // Update asteroids
      for (let i = asteroids.length - 1; i >= 0; i--) {
        let a = asteroids[i];
        a.y += a.speed;

        // Collision detection
        if (
          player.x < a.x + a.size &&
          player.x + player.width > a.x &&
          player.y < a.y + a.size &&
          player.y + player.height > a.y
        ) {
          gameOver = true;
          createExplosion(player.x + player.width / 2, player.y + player.height / 2, player.color);
          if (score > bestScore) {
            bestScore = score;
            localStorage.setItem('neonDodgerBest', bestScore);
            bestEl.textContent = bestScore;
          }
        }

        // Remove off-screen asteroids and add score
        if (a.y > canvas.height) {
          asteroids.splice(i, 1);
          score++;
          scoreEl.textContent = score;
        }
      }

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

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

      // Draw Player (Triangle Ship)
      if (!gameOver) {
        ctx.fillStyle = player.color;
        ctx.shadowBlur = 15;
        ctx.shadowColor = player.color;
        ctx.beginPath();
        ctx.moveTo(player.x + player.width / 2, player.y);
        ctx.lineTo(player.x + player.width, player.y + player.height);
        ctx.lineTo(player.x, player.y + player.height);
        ctx.closePath();
        ctx.fill();
      }

      // Draw Asteroids
      asteroids.forEach(a => {
        ctx.fillStyle = a.color;
        ctx.shadowBlur = 12;
        ctx.shadowColor = a.color;
        ctx.fillRect(a.x, a.y, a.size, a.size);
      });

      // Draw Particles
      particles.forEach(p => {
        ctx.globalAlpha = p.life;
        ctx.fillStyle = p.color;
        ctx.fillRect(p.x, p.y, 4, 4);
      });
      ctx.globalAlpha = 1;
      ctx.shadowBlur = 0;

      // Game Over Text
      if (gameOver) {
        ctx.fillStyle = '#ffffff';
        ctx.font = 'bold 40px Segoe UI';
        ctx.textAlign = 'center';
        ctx.fillText('GAME OVER', canvas.width / 2, canvas.height / 2 - 10);
        ctx.font = '18px Segoe UI';
        ctx.fillStyle = '#66fcf1';
        ctx.fillText('Press SPACE to play again', canvas.width / 2, canvas.height / 2 + 30);
      }
    }

    function loop() {
      update();
      draw();
      if (!gameOver || particles.length > 0) {
        requestAnimationFrame(loop);
      }
    }

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

Game Source: Neon Dodger

Creator: PlasmaMeteor43

Libraries: none

Complexity: complex (230 lines, 6.3 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: neon-dodger-plasmameteor43" to link back to the original. Then publish at arcadelab.ai/publish.