about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-12-27 08:12:33 -0500
committerelioat <elioat@tilde.institute>2024-12-27 08:12:33 -0500
commita7fea5f379187ea7e7ff643215b801832459ed67 (patch)
tree1071020c7e67eab53dc1de24592493930c546aca
parentcbec006c83cbd51a8586ec8b4360b3e197e5d634 (diff)
downloadtour-a7fea5f379187ea7e7ff643215b801832459ed67.tar.gz
*
-rw-r--r--html/rogue/js/camera.js23
-rw-r--r--html/rogue/js/config.js4
-rw-r--r--html/rogue/js/hexGrid.js2
-rw-r--r--html/rogue/js/player.js2
4 files changed, 24 insertions, 7 deletions
diff --git a/html/rogue/js/camera.js b/html/rogue/js/camera.js
index a5aae47..c389b6e 100644
--- a/html/rogue/js/camera.js
+++ b/html/rogue/js/camera.js
@@ -10,10 +10,25 @@ const Camera = {
 
     smoothFollow(target) {
         const targetPixel = HexGrid.toPixel(target);
-        const targetX = targetPixel.x - state.canvas.width / 2;
-        const targetY = targetPixel.y - state.canvas.height / 2;
+        const screenX = targetPixel.x - this.x;
+        const screenY = targetPixel.y - this.y;
         
-        this.x += (targetX - this.x) * Config.camera.FOLLOW_SPEED;
-        this.y += (targetY - this.y) * Config.camera.FOLLOW_SPEED;
+        const centerX = state.canvas.width / 2;
+        const centerY = state.canvas.height / 2;
+        
+        // Calculate distance from center of screen
+        const deltaX = screenX - centerX;
+        const deltaY = screenY - centerY;
+        
+        // Only move camera if player is outside deadzone
+        if (Math.abs(deltaX) > Config.camera.DEADZONE_X) {
+            const adjustX = deltaX - (deltaX > 0 ? Config.camera.DEADZONE_X : -Config.camera.DEADZONE_X);
+            this.x += adjustX * Config.camera.FOLLOW_SPEED;
+        }
+        
+        if (Math.abs(deltaY) > Config.camera.DEADZONE_Y) {
+            const adjustY = deltaY - (deltaY > 0 ? Config.camera.DEADZONE_Y : -Config.camera.DEADZONE_Y);
+            this.y += adjustY * Config.camera.FOLLOW_SPEED;
+        }
     }
 }; 
\ No newline at end of file
diff --git a/html/rogue/js/config.js b/html/rogue/js/config.js
index 284ad89..5a729e0 100644
--- a/html/rogue/js/config.js
+++ b/html/rogue/js/config.js
@@ -30,6 +30,8 @@ const Config = {
     },
 
     camera: {
-        FOLLOW_SPEED: 0.1          // Camera smoothing factor
+        FOLLOW_SPEED: 0.1,         // Camera smoothing factor
+        DEADZONE_X: 200,           // Horizontal deadzone in pixels
+        DEADZONE_Y: 150           // Vertical deadzone in pixels
     }
 }; 
\ No newline at end of file
diff --git a/html/rogue/js/hexGrid.js b/html/rogue/js/hexGrid.js
index 0d4d81f..0d1c2e5 100644
--- a/html/rogue/js/hexGrid.js
+++ b/html/rogue/js/hexGrid.js
@@ -62,6 +62,6 @@ const HexGrid = {
     // Add this method to check if a hex is passable
     isPassable(hex) {
         const halfGrid = Math.floor(this.GRID_SIZE / 2);
-        return Math.abs(hex.q) < halfGrid && Math.abs(hex.r) < halfGrid;
+        return Math.abs(hex.q) <= halfGrid && Math.abs(hex.r) <= halfGrid;
     }
 }; 
\ No newline at end of file
diff --git a/html/rogue/js/player.js b/html/rogue/js/player.js
index 803a6b7..e35db31 100644
--- a/html/rogue/js/player.js
+++ b/html/rogue/js/player.js
@@ -17,7 +17,7 @@ const player = {
     // Check if a hex coordinate is within grid bounds
     isValidHex(hex) {
         const halfGrid = Math.floor(HexGrid.GRID_SIZE / 2);
-        return Math.abs(hex.q) < halfGrid && Math.abs(hex.r) < halfGrid;
+        return Math.abs(hex.q) <= halfGrid && Math.abs(hex.r) <= halfGrid;
     },
 
     // Get neighbors that share an edge with the given hex