pong_game = {
({
prompt: "Create an automated retro looking game of pong",
time: 1699389743848,
comment: "Creating an automated retro-looking game of Pong"
});
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = 200;
const context = canvas.getContext("2d");
const ball = { x: width / 2, y: 20, dx: 3, dy: 2, radius: 15 };
const paddle = { x: 5, y: canvas.height / 2, width: 20, height: 60 };
const drawBall = () => {
context.beginPath();
context.rect(
ball.x,
ball.y - ball.radius,
ball.radius * 2,
ball.radius * 2
);
context.fillStyle = "#FFFFFF";
context.fill();
context.closePath();
};
const drawPaddle = () => {
context.beginPath();
context.rect(paddle.x, paddle.y, paddle.width, paddle.height);
context.fillStyle = "#FFFFFF";
context.fill();
context.closePath();
};
const update = () => {
context.fillStyle = "#000000";
context.fillRect(0, 0, canvas.width, canvas.height);
drawBall();
drawPaddle();
if (
ball.x + ball.dx > canvas.width - ball.radius ||
ball.x + ball.dx < ball.radius + 10
) {
ball.dx = -ball.dx;
}
if (ball.y + ball.dy < ball.radius) {
ball.dy = -ball.dy;
} else if (ball.y + ball.dy > canvas.height - ball.radius) {
if (ball.x > paddle.x && ball.x < paddle.x + paddle.width) {
ball.dy = -ball.dy;
} else {
ball.dy = -ball.dy;
}
}
ball.x += ball.dx;
ball.y += ball.dy;
paddle.y = ball.y - 30;
};
const interval = setInterval(update, 10);
return canvas;
}