Add Hud component for UI management; display health, coins, and lives

This commit is contained in:
2025-08-13 03:19:23 +02:00
parent 9c74a1ffb5
commit 32a0311e3c
4 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1 @@
uid://dev2q1228otm2

View File

@@ -0,0 +1 @@
uid://daevj4uootmcw

View File

@@ -0,0 +1 @@
uid://u4qfsx4w72dv

43
scripts/UI/Hud.cs Normal file
View File

@@ -0,0 +1,43 @@
using Godot;
using Mr.BrickAdventures.Autoloads;
using Mr.BrickAdventures.scripts.components;
namespace Mr.BrickAdventures.scripts.UI;
public partial class Hud : Node
{
[Export] public HealthComponent Health { get; set; }
[Export] public Label CoinsLabel { get; set; }
[Export] public ProgressBar HealthBar { get; set; }
[Export] public Label LivesLabel { get; set; }
private GameManager _gameManager;
public override void _Ready()
{
_gameManager = GetNode<GameManager>("/root/GameManager");
}
public override void _Process(double delta)
{
SetHealthBar();
SetLivesLabel();
SetCoinsLabel();
}
private void SetCoinsLabel()
{
CoinsLabel.Text = Tr("COINS_LABEL") + ": " + _gameManager.GetCoins();
}
private void SetLivesLabel()
{
LivesLabel.Text = Tr("LIVES_LABEL") + ": " + _gameManager.GetLives();
}
private void SetHealthBar()
{
HealthBar.Value = Health.Health;
HealthBar.MaxValue = Health.MaxHealth;
}
}