diff options
author | Florrie <towerofnix@gmail.com> | 2018-08-20 10:57:56 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-08-20 10:57:56 -0300 |
commit | 267c3ea764a851fe50d24feaf0d8a9612c14af43 (patch) | |
tree | de1991b86ccdb9112b677905e11411cdf932fdec /index.js | |
parent | c3b4584e5dcd578ecfd1840b7f2b9023d46fdbb6 (diff) |
Camera stuff
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 16 |
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 + } } } |