<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pong Game</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: black;
}
canvas {
border: 1px solid white;
}
</style>
</head>
<body>
<canvas id="pong" width="800" height="400"></canvas>
<script>
const canvas = document.getElementById("pong");
const context = canvas.getContext("2d");
// Game settings and variables
let paddleWidth = 10, paddleHeight = 100;
let playerPaddle = { x: 0, y: canvas.height / 2 - paddleHeight / 2, width: paddleWidth, height: paddleHeight };
let aiPaddle = { x: canvas.width - paddleWidth, y: canvas.height / 2 - paddleHeight / 2, width: paddleWidth, height: paddleHeight };
// Function to draw the paddles and ball
function draw() {
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = 'white';
context.fillRect(playerPaddle.x, playerPaddle.y, playerPaddle.width, playerPaddle.height);
context.fillRect(aiPaddle.x, aiPaddle.y, aiPaddle.width, aiPaddle.height);
}
setInterval(draw, 1000 / 60); // 60 FPS
</script>
</body>
</html>