Racing game 1.1

<html>
  <head>
    <style>
      canvas {
        border: 1px solid black;
      }
    </style>
  </head>
  <body onload="startGame()">
    <canvas id="gameCanvas" width="600" height="400"></canvas>
  </body>
</html>
#gameCanvas {
  background-color: lightblue;
}
function startGame() {
  const canvas = document.getElementById("gameCanvas");
  const ctx = canvas.getContext("2d");

  let x = canvas.width / 2;
  let y = canvas.height - 30;
  let dx = 2;
  let dy = -2;

  function drawBall() {
    ctx.beginPath();
    ctx.arc(x, y, 10, 0, Math.PI * 2);
    ctx.fillStyle = "#0095DD";
    ctx.fill();
    ctx.closePath();
  }

  function draw() {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    drawBall();
    x += dx;
    y += dy;
  }

  setInterval(draw, 10);
}

you have posted some code. What did you intend to post?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.