From e1c310fe18cef53fc617d0d845d9dc4def8798e7 Mon Sep 17 00:00:00 2001
From: Leonardo Bishop <me@leonardobishop.com>
Date: Sun, 27 Oct 2024 11:25:20 +0000
Subject: more shit2

---
 src/App.vue | 66 ++++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 39 insertions(+), 27 deletions(-)

(limited to 'src/App.vue')

diff --git a/src/App.vue b/src/App.vue
index 1e30df3..239f5c2 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -79,6 +79,7 @@ let mousePos: { x: number; y: number } = { x: 0, y: 0 };
 
 let isFire = false;
 let isFiringMode = true;
+let isGameOver = false;
 
 const brickHeight = 45;
 
@@ -321,50 +322,61 @@ function processWallIntersection() {
     ballVelocityX = -ballVelocityX;
   }
 
-  if (nextStepY > canvasHeight || nextStepY < 0) {
+  if (nextStepY < 0) {
     ballVelocityY = -ballVelocityY;
   }
+
+  if (nextStepY > canvasHeight) {
+    message = "Game over!";
+    isGameOver = true;
+  }
 }
 
 function tick() {
   const ctx = canvas.value!.getContext("2d")!;
   ctx.clearRect(0, 0, canvasWidth, canvasHeight);
 
-  processMovement();
+  if (!isGameOver) {
+    processMovement();
+    if (!isFiringMode) {
+      message = null;
 
-  if (!isFiringMode) {
-    message = null;
+      processPaddleIntersection();
+      processBrickIntersection();
+      processWallIntersection();
+      processBallMovement();
 
-    processPaddleIntersection();
-    processBrickIntersection();
-    processWallIntersection();
-    processBallMovement();
-  } else {
-    message = "Use left-click to fire";
+      if (bricks.every((r) => r.every((brick) => brick.hit))) {
+        isGameOver = true;
+        message = "Level complete";
+      }
+    } else {
+      message = "Use left-click to fire";
 
-    ballPosX = paddlePosX;
-    ballPosY = paddlePosY - 10;
+      ballPosX = paddlePosX;
+      ballPosY = paddlePosY - 10;
 
-    drawRay();
+      drawRay();
 
-    if (isFire) {
-      isFire = false;
-      isFiringMode = false;
+      if (isFire) {
+        isFire = false;
+        isFiringMode = false;
 
-      const x = mousePos.x - ballPosX;
-      const y = mousePos.y - ballPosY;
+        const x = mousePos.x - ballPosX;
+        const y = mousePos.y - ballPosY;
 
-      const xSquared = x * x;
-      const ySquared = y * y;
-      const hSquared = xSquared + ySquared;
+        const xSquared = x * x;
+        const ySquared = y * y;
+        const hSquared = xSquared + ySquared;
 
-      const h = Math.sqrt(hSquared);
+        const h = Math.sqrt(hSquared);
 
-      const velocityX = x / h;
-      const velocityY = y / h;
+        const velocityX = x / h;
+        const velocityY = y / h;
 
-      ballVelocityX = velocityX * 2.5;
-      ballVelocityY = velocityY * 2.5;
+        ballVelocityX = velocityX * 2.5;
+        ballVelocityY = velocityY * 2.5;
+      }
     }
   }
 
@@ -404,7 +416,7 @@ async function start() {
 
   bricks.forEach((row, rowIndex) => {
     row.forEach((brick, brickIndex) => {
-        brick.problem = solutions.steps[rowIndex * 2 + brickIndex];
+      brick.problem = solutions.steps[rowIndex * 2 + brickIndex];
     });
   });
 
-- 
cgit v1.2.3-70-g09d2

