From ebabe0309861fd92128edb6ec2c60bc8ae32a80d Mon Sep 17 00:00:00 2001 From: Renge Date: Wed, 20 Apr 2022 17:57:14 -0400 Subject: [PATCH] feat: implemented status bars for player --- src/Wolfie2D/Nodes/Graphics/Rect.ts | 3 ++ .../CanvasRendering/GraphicRenderer.ts | 6 ++- src/shattered_sword/Scenes/GameLevel.ts | 45 ++++++++++++++++--- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/Wolfie2D/Nodes/Graphics/Rect.ts b/src/Wolfie2D/Nodes/Graphics/Rect.ts index 7bac72a..ec6eada 100644 --- a/src/Wolfie2D/Nodes/Graphics/Rect.ts +++ b/src/Wolfie2D/Nodes/Graphics/Rect.ts @@ -11,12 +11,15 @@ export default class Rect extends Graphic { /** The width of the border */ borderWidth: number; + fillWidth: number; + constructor(position: Vec2, size: Vec2){ super(); this.position = position; this.size = size; this.borderColor = Color.TRANSPARENT; this.borderWidth = 0; + this.fillWidth = null; } /** diff --git a/src/Wolfie2D/Rendering/CanvasRendering/GraphicRenderer.ts b/src/Wolfie2D/Rendering/CanvasRendering/GraphicRenderer.ts index 230249d..423525d 100644 --- a/src/Wolfie2D/Rendering/CanvasRendering/GraphicRenderer.ts +++ b/src/Wolfie2D/Rendering/CanvasRendering/GraphicRenderer.ts @@ -59,7 +59,11 @@ export default class GraphicRenderer { // Draw the interior of the rect if(rect.color.a !== 0){ this.ctx.fillStyle = rect.color.toStringRGB(); - this.ctx.fillRect((-rect.size.x/2)*zoom, (-rect.size.y/2)*zoom, rect.size.x*zoom, rect.size.y*zoom); + if (rect.fillWidth !== null) { + this.ctx.fillRect((-rect.size.x/2)*zoom, (-rect.size.y/2)*zoom, rect.fillWidth*zoom, rect.size.y*zoom); + } else { + this.ctx.fillRect((-rect.size.x/2)*zoom, (-rect.size.y/2)*zoom, rect.size.x*zoom, rect.size.y*zoom); + } } // Draw the border of the rect if it isn't transparent diff --git a/src/shattered_sword/Scenes/GameLevel.ts b/src/shattered_sword/Scenes/GameLevel.ts index fb44a8a..4b2c6a0 100644 --- a/src/shattered_sword/Scenes/GameLevel.ts +++ b/src/shattered_sword/Scenes/GameLevel.ts @@ -70,11 +70,14 @@ export default class GameLevel extends Scene { // Health UI protected healthLabel: Label; + protected healthBar: Rect; //exp label protected expLabel : Label; + protected expBar: Rect; //shield label protected shieldLabel : Label; + protected shieldBar: Rect; //seed UI protected seedLabel: Label; @@ -333,14 +336,32 @@ export default class GameLevel extends Scene { //update health UI let playerAI = (this.player.ai); this.healthLabel.text = "Health: "+ playerAI.CURRENT_HP +'/' + (playerAI.MAX_HP +playerAI.CURRENT_BUFFS.hp ); + this.healthBar.size.set(playerAI.MAX_HP*2, 10); + this.healthBar.position.set(playerAI.MAX_HP+50, 20); + this.healthBar.fillWidth = playerAI.CURRENT_HP*2; + if (playerAI.CURRENT_HP/playerAI.MAX_HP >= 2/3) { + this.healthBar.color = Color.GREEN; + this.healthLabel.textColor = Color.GREEN; + } + else if (playerAI.CURRENT_HP/playerAI.MAX_HP >= 1/3) { + this.healthBar.color = Color.YELLOW; + this.healthLabel.textColor = Color.YELLOW; + } + else { + this.healthBar.color = Color.RED; + this.healthLabel.textColor = Color.RED; + } // this.healthLabel.sizeToText(); //update shield ui this.shieldLabel.text = "Shield: "+ playerAI.CURRENT_SHIELD +'/' + (playerAI.MAX_SHIELD); + this.shieldBar.size.set(playerAI.CURRENT_SHIELD*2, 10); + this.shieldBar.position.set(playerAI.CURRENT_SHIELD+50, 60); // this.shieldLabel.sizeToText(); //update exp ui this.expLabel.text = "EXP: "+ playerAI.CURRENT_EXP +'/' + (playerAI.MAX_EXP); + this.expBar.fillWidth = (playerAI.CURRENT_EXP/playerAI.MAX_EXP)*200; // this.expLabel.sizeToText(); @@ -448,23 +469,35 @@ export default class GameLevel extends Scene { */ protected addUI(){ // In-game labels - this.healthLabel =