From 267c3ea764a851fe50d24feaf0d8a9612c14af43 Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 20 Aug 2018 10:57:56 -0300 Subject: Camera stuff --- index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'index.js') 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 + } } } -- cgit 1.3.0-6-gf8a5