Write me javascript code that does simple bricks game using the mouse as controller.
- User
Write me javascript code that does simple bricks game using the mouse as controller.
Assistant
Here's a simple implementation of a brick game using the mouse as the controller:
<!DOCTYPE html> <html> <head> <title>Brick Game</title> <style> canvas { width: 500px; height: 400px; border: 1px solid black; } </style> </head> <body> <canvas id="gameCanvas"></canvas> <script> // Initialize the canvas const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); canvas.width = 500; canvas.height = 400; // Initialize the ball let ball = { x: canvas.width / 2, y: canvas.height - 10, radius: 5, vx: 0, vy: -10 }; // Initialize the bricks let bricks = []; for (let i = 0; i < 5; i++) { bricks.push({ x: Math.random() * (canvas.width - 20), y: Math.random() * (canvas.height - 20), width: 20, height: 10 }); } // Initialize the score let score = 0; // Update the ball's position function updateBall() { ball.x += ball.vx; ball.y -= ball.vy; // Check for collision with bricks for (let i = 0; i < bricks.length; i++) { if (ball.x > bricks[i].x && ball.x < bricks[i].x + bricks[i].width && ball.y > bricks[i].y && ball.y < bricks[i].y + bricks[i].height) { ball.vx = -ball.vx; } } // Check for collision with the top wall if (ball.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.