rajbanshisubho685-dotcom commented on issue #5245:
URL: https://github.com/apache/hop/issues/5245#issuecomment-3370955678

   
   
   <!DOCTYPE html>
   <html lang="en">
   <head>
     <meta charset="UTF-8">
     <title>Brick Breaker Game</title>
     <style>
       * { padding: 0; margin: 0; box-sizing: border-box; }
       canvas {
         background: #111;
         display: block;
         margin: 50px auto;
         border: 3px solid #00ffcc;
         border-radius: 10px;
       }
     </style>
   </head>
   <body>
     <canvas id="myCanvas" width="480" height="320"></canvas>
   
     <script>
       const canvas = document.getElementById("myCanvas");
       const ctx = canvas.getContext("2d");
   
       // Ball properties
       let x = canvas.width / 2;
       let y = canvas.height - 30;
       let dx = 2;
       let dy = -2;
       const ballRadius = 10;
   
       // Paddle properties
       const paddleHeight = 10;
       const paddleWidth = 75;
       let paddleX = (canvas.width - paddleWidth) / 2;
       let rightPressed = false;
       let leftPressed = false;
   
       // Brick properties
       const brickRowCount = 4;
       const brickColumnCount = 6;
       const brickWidth = 60;
       const brickHeight = 20;
       const brickPadding = 10;
       const brickOffsetTop = 30;
       const brickOffsetLeft = 30;
   
       let score = 0;
   
       const bricks = [];
       for (let c = 0; c < brickColumnCount; c++) {
         bricks[c] = [];
         for (let r = 0; r < brickRowCount; r++) {
           bricks[c][r] = { x: 0, y: 0, status: 1 };
         }
       }
   
       document.addEventListener("keydown", keyDownHandler);
       document.addEventListener("keyup", keyUpHandler);
   
       function keyDownHandler(e) {
         if (e.key === "Right" || e.key === "ArrowRight") rightPressed = true;
         else if (e.key === "Left" || e.key === "ArrowLeft") leftPressed = true;
       }
   
       function keyUpHandler(e) {
         if (e.key === "Right" || e.key === "ArrowRight") rightPressed = false;
         else if (e.key === "Left" || e.key === "ArrowLeft") leftPressed = 
false;
       }
   
       function collisionDetection() {
         for (let c = 0; c < brickColumnCount; c++) {
           for (let r = 0; r < brickRowCount; r++) {
             const b = bricks[c][r];
             if (b.status === 1) {
               if (
                 x > b.x &&
                 x < b.x + brickWidth &&
                 y > b.y &&
                 y < b.y + brickHeight
               ) {
                 dy = -dy;
                 b.status = 0;
                 score++;
                 if (score === brickRowCount * brickColumnCount) {
                   alert("🎉 YOU WIN! Congratulations!");
                   document.location.reload();
                 }
               }
             }
           }
         }
       }
   
       function drawBall() {
         ctx.beginPath();
         ctx.arc(x, y, ballRadius, 0, Math.PI * 2);
         ctx.fillStyle = "#00ffcc";
         ctx.fill();
         ctx.closePath();
       }
   
       function drawPaddle() {
         ctx.beginPath();
         ctx.rect(paddleX, canvas.height - paddleHeight - 10, paddleWidth, 
paddleHeight);
         ctx.fillStyle = "#00ffcc";
         ctx.fill();
         ctx.closePath();
       }
   
       function drawBricks() {
         for (let c = 0; c < brickColumnCount; c++) {
           for (let r = 0; r < brickRowCount; r++) {
             if (bricks[c][r].status === 1) {
               const brickX = c * (brickWidth + brickPadding) + brickOffsetLeft;
               const brickY = r * (brickHeight + brickPadding) + brickOffsetTop;
               bricks[c][r].x = brickX;
               bricks[c][r].y = brickY;
               ctx.beginPath();
               ctx.rect(brickX, brickY, brickWidth, brickHeight);
               ctx.fillStyle = "#ff3366";
               ctx.fill();
               ctx.closePath();
             }
           }
         }
       }
   
       function drawScore() {
         ctx.font = "16px Arial";
         ctx.fillStyle = "#00ffcc";
         ctx.fillText("Score: " + score, 8, 20);
       }
   
       function draw() {
         ctx.clearRect(0, 0, canvas.width, canvas.height);
         drawBricks();
         drawBall();
         drawPaddle();
         drawScore();
         collisionDetection();
   
         if (x + dx > canvas.width - ballRadius || x + dx < ballRadius) dx = 
-dx;
         if (y + dy < ballRadius) dy = -dy;
         else if (y + dy > canvas.height - ballRadius - 10) {
           if (x > paddleX && x < paddleX + paddleWidth) dy = -dy;
           else {
             alert("💀 GAME OVER!");
             document.location.reload();
           }
         }
   
         if (rightPressed && paddleX < canvas.width - paddleWidth) paddleX += 5;
         else if (leftPressed && paddleX > 0) paddleX -= 5;
   
         x += dx;
         y += dy;
         requestAnimationFrame(draw);
   
     </script>
   </body>
   </html>
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to