« get me outta code hell

csb-game - Pixelly spin-off of the Command Synergy Battle system used in Final Fantasy XIII
summary refs log tree commit diff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/index.js b/index.js
index b87cbcb..237a9e3 100644
--- a/index.js
+++ b/index.js
@@ -50,6 +50,8 @@ class Sprite {
     this.x = 0
     this.y = 0
     this.canvas = document.createElement('canvas')
+    this.canvas.width = 1
+    this.canvas.height = 1
     this.image = document.createElement('img')
   }
 
@@ -1261,9 +1263,21 @@ class BattleCamera extends Camera {
   }
 
   getSpriteFollowCoords(sprite) {
+    // TODO: Decide exactly how the sprite should be taken into account.. right now it's not at all.
     const bx = this.battle.battlefieldCenterX
     const by = this.battle.battlefieldCenterY
-    return {x: bx + (sprite.x - bx) / 3, y: by + (sprite.y - by) / 3}
+    // return {x: bx + (sprite.x - bx) / 3, y: by + (sprite.y - by) / 3}
+
+    const characters = this.battle.getAllBattleCharacters()
+
+    const leftmostX = characters.reduce((acc, c) => Math.min(acc, c.x), 0)
+    const rightmostX = characters.reduce((acc, c) => Math.max(acc, c.x), 0)
+    const distanceX = Math.abs(leftmostX - rightmostX)
+
+    return {
+      x: (leftmostX + rightmostX) / 2,
+      y: by
+    }
   }
 }