Нужно исправить код так, чтобы одновременно появлялось не больше 1 зеленой платформы. скорость платформ должно постепенно увеличиваться.
код:
const canvas = document.createElement('canvas');
    const context = canvas.getContext('2d');
    
    canvas.width = 640;
    canvas.height = 480;
    document.body.appendChild(canvas);

    const player = {
      x: 100,
      y: 420,
      width: 50,
      height: 50
    };

    const platforms = [];

    let gameOver = false;
    let mouseX = 0;
    let mouseY = 0;

    function random(min, max) {
      return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function addPlatform() {
      const platform = {
        x: canvas.width,
        y: random(50, canvas.height - 30),
        width: random(player.width, 150),
        height: 20,
        velocityX: -3,
      };
      platforms.push(platform);
    }

    function resetGame() {
      gameOver = false;
      platforms.length = 0;
      player.x = canvas.width / 2;
      player.y = canvas.height / 2;

      setTimeout(function addAndSchedule() {
        if (gameOver) return;
        addPlatform();
        setTimeout(addAndSchedule, 2000);
      }, 2000);
    }

    function update() {
      if(gameOver) return;

      player.x = mouseX - player.width / 2;
      player.y = mouseY - player.height / 2;

      platforms.forEach((platform, index) => {
        platform.x += platform.velocityX;

        if (platform.x + platform.width < 0) {
          platforms.splice(index, 1);
          return;
        }

        if (checkCollision(player, platform)) {
          gameOver = true;
          return;
        }
      });
    }

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

      context.fillStyle = 'blue';
      context.fillRect(player.x, player.y, player.width, player.height);

      context.fillStyle = 'green';
      platforms.forEach((platform) => {
        context.fillRect(platform.x, platform.y, platform.width, platform.height);
      });

      if (gameOver) {
        drawOverlay();
      }
    }

    function checkCollision(rect1, rect2) {
      return rect1.x < rect2.x + rect2.width &&
        rect1.x + rect1.width > rect2.x &&
        rect1.y < rect2.y + rect2.height &&
        rect1.y + rect1.height > rect2.y;
    }

    function gameLoop() {
      update();
      draw();
      requestAnimationFrame(gameLoop);
    }

    function drawOverlay() {
      context.fillStyle = 'rgba(0, 0, 0, 0.8)';
      context.fillRect(0, 0, canvas.width, canvas.height);
      
      const boxWidth = 100;
      const boxHeight = 70;
      
      context.fillStyle = 'white';
      context.fillRect(canvas.width / 2 - boxWidth / 2, canvas.height / 2 - boxHeight / 2, boxWidth, boxHeight);
    }

    function onMouseMove(event) {
      const rect = canvas.getBoundingClientRect();
      
      mouseX = event.clientX - rect.left;
      mouseY = event.clientY - rect.top;
    }

    function onClick(event) {
      if (!gameOver) {
        return;
      }

      const boxWidth = 100;
      const boxHeight = 70;
      
      const boxLeft = canvas.width / 2 - boxWidth / 2;
      const boxRight = canvas.width / 2 + boxWidth / 2;
      const boxTop = canvas.height / 2 - boxHeight / 2;
      const boxBottom = canvas.height / 2 + boxHeight / 2;

      if (
        mouseX >= boxLeft &&
        mouseX <= boxRight &&
        mouseY >= boxTop &&
        mouseY <= boxBottom
      ) {
        resetGame();
      }
    }

    canvas.addEventListener('mousemove', onMouseMove);
    canvas.addEventListener('click', onClick);

    resetGame();
    gameLoop();