From 2b752c25d8940190e4c85423c6e57a44fe21705f Mon Sep 17 00:00:00 2001
From: Bye <bye@byecorps.com>
Date: Thu, 24 Aug 2023 12:45:52 +0100
Subject: [PATCH] [FEATURE] Start building hitbox for island.

- Add strokeRect() method to canvas (canvas.js)
- Add hitbox drawing code to game.js
---
 src/js/canvas.js |  5 +++++
 src/js/game.js   | 10 ++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/js/canvas.js b/src/js/canvas.js
index 2b3eb0d..71db888 100644
--- a/src/js/canvas.js
+++ b/src/js/canvas.js
@@ -63,6 +63,11 @@ class Canvas {
         this.ctx.fillStyle = c;
         this.ctx.fillRect(x-this.cX, y-this.cY, w, h);
     }
+
+    strokeRect(x, y, w, h, c="white") {
+        this.ctx.strokeStyle = c;
+        this.ctx.strokeRect(x-this.cX, y-this.cY, w, h);
+    }
     
 }
 
diff --git a/src/js/game.js b/src/js/game.js
index e289fe2..5094891 100644
--- a/src/js/game.js
+++ b/src/js/game.js
@@ -195,7 +195,7 @@ class Boat extends Entity {
         this.sprite = sprite;
         this.speed = speed;
         if (speed === 0) speed = 0.5;
-        this.stepspeed = randomInt(Math.floor(100/speed), Math.floor(1000/speed));
+        this.stepspeed = randomInt(Math.floor(500/speed), Math.floor(1500/speed));
         this.target = target;
     }
 
@@ -248,7 +248,9 @@ gameRoom.wavePendingStart = 0;
 gameRoom.boatCount = 0;
 gameRoom.boatSpeed = 0;
 
-gameRoom.boatAvoid = {}
+gameRoom.boatAvoid = [
+    {x: 35, y: 100, w: 32, h: 75}
+];
 
 console.log(typeof(gameRoom.remove))
 
@@ -277,6 +279,10 @@ gameRoom.draw = () => {
     for (const item of gameRoom.objects) {
         item.draw();
     }
+
+    for (const hitbox of gameRoom.boatAvoid) {
+        canvas.strokeRect(hitbox.x, hitbox.y, hitbox.w, hitbox.h, "red");
+    }
 }
 gameRoom.step = _ => {
     let numberOfBoats = 0;
-- 
GitLab