about summary refs log tree commit diff stats
path: root/html/rogue/js/camera.js
diff options
context:
space:
mode:
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