about summary refs log tree commit diff stats
path: root/html/rogue/js/camera.js
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 /html/rogue/js/camera.js
parentcbec006c83cbd51a8586ec8b4360b3e197e5d634 (diff)
downloadtour-a7fea5f379187ea7e7ff643215b801832459ed67.tar.gz
*
Diffstat (limited to 'html/rogue/js/camera.js')
-rw-r--r--html/rogue/js/camera.js23
1 files changed, 19 insertions, 4 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