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:08:29 -0500
committerelioat <elioat@tilde.institute>2024-12-27 08:08:29 -0500
commitea50f9ee0875b9230174996af0f92922f747b974 (patch)
tree9c419f1af57bd6195a559137d9a004aabc4fb96a /html/rogue/js/camera.js
parent6ea87b4e0a8cddca95c0a4f2b36264e7430e74aa (diff)
downloadtour-ea50f9ee0875b9230174996af0f92922f747b974.tar.gz
*
Diffstat (limited to 'html/rogue/js/camera.js')
-rw-r--r--html/rogue/js/camera.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/html/rogue/js/camera.js b/html/rogue/js/camera.js
new file mode 100644
index 0000000..e7b2475
--- /dev/null
+++ b/html/rogue/js/camera.js
@@ -0,0 +1,19 @@
+const Camera = {
+    x: 0,
+    y: 0,
+    
+    centerOn(hex) {
+        const pixelCoord = HexGrid.toPixel(hex);
+        this.x = pixelCoord.x - state.canvas.width / 2;
+        this.y = pixelCoord.y - state.canvas.height / 2;
+    },
+
+    smoothFollow(target) {
+        const targetPixel = HexGrid.toPixel(target);
+        const targetX = targetPixel.x - state.canvas.width / 2;
+        const targetY = targetPixel.y - state.canvas.height / 2;
+        
+        this.x += (targetX - this.x) * 0.1;
+        this.y += (targetY - this.y) * 0.1;
+    }
+}; 
\ No newline at end of file