« get me outta code hell

Don't let HP bars go off right/bottom edge - csb-game - Pixelly spin-off of the Command Synergy Battle system used in Final Fantasy XIII
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-08-20 11:11:21 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-20 11:11:21 -0300
commit311a15333d9fbb9a5b0cc249d6bd0c45d29a4782 (patch)
tree8535fa338bfdcfb4026ad865e5f75b6ad5a35883
parent8f331f13feeff576c36b1c0afd398a261ee3fb43 (diff)
Don't let HP bars go off right/bottom edge
-rw-r--r--index.js4
1 files changed, 2 insertions, 2 deletions
diff --git a/index.js b/index.js
index ad0f71a..d9796ed 100644
--- a/index.js
+++ b/index.js
@@ -1031,8 +1031,8 @@ class Battle {
     for (const { x, y, battleCharacter } of overlayHPBars) {
       const hpBar = battleCharacter.hpBar
       hpBar.draw()
-      const drawX = Math.max(10 + hpBar.labelCanvas.width, Math.round(x - hpBar.canvas.width / 2))
-      const drawY = Math.max(10, Math.round(y - hpBar.canvas.height))
+      const drawX = Math.min(this.canvas.width - 10 - hpBar.canvas.width, Math.max(10 + hpBar.labelCanvas.width, Math.round(x - hpBar.canvas.width / 2)))
+      const drawY = Math.min(this.canvas.height - 20, Math.max(10, Math.round(y - hpBar.canvas.height)))
       ctx.drawImage(hpBar.canvas, drawX, drawY)
       ctx.drawImage(hpBar.labelCanvas, drawX - hpBar.labelCanvas.width - 2, drawY - 1)
     }