diff options
author | elioat <elioat@tilde.institute> | 2024-12-27 08:12:33 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2024-12-27 08:12:33 -0500 |
commit | a7fea5f379187ea7e7ff643215b801832459ed67 (patch) | |
tree | 1071020c7e67eab53dc1de24592493930c546aca /html/rogue/js/camera.js | |
parent | cbec006c83cbd51a8586ec8b4360b3e197e5d634 (diff) | |
download | tour-a7fea5f379187ea7e7ff643215b801832459ed67.tar.gz |
*
Diffstat (limited to 'html/rogue/js/camera.js')
-rw-r--r-- | html/rogue/js/camera.js | 23 |
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 |