From 3c9192b24c09146df066fd986f34d269c50648e8 Mon Sep 17 00:00:00 2001 From: Matheus Date: Thu, 28 Aug 2025 20:34:00 -0300 Subject: HP alterado --- scripts/Game.cs | 4 ++++ scripts/UI.cs | 17 +++++++++++++++++ scripts/UI.cs.uid | 1 + scripts/actors/Actor.cs | 10 +++++++--- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 scripts/UI.cs create mode 100644 scripts/UI.cs.uid (limited to 'scripts') diff --git a/scripts/Game.cs b/scripts/Game.cs index ab4bd8e..4dc7a34 100644 --- a/scripts/Game.cs +++ b/scripts/Game.cs @@ -19,17 +19,21 @@ public partial class Game : Node { /// private InputHandler inputHandler; + private UI ui; + public override void _Ready() { base._Ready(); Map = GetNode("Map"); inputHandler = GetNode("InputHandler"); + ui = GetNode("UI"); // O jogador é criado pelo jogo. Player player = new Player(Vector2I.Zero, null, playerDefinition); Camera2D camera = GetNode("Camera2D"); RemoveChild(camera); + player.HealthChanged += (int hp, int maxHp) => ui.OnHealthChanged(hp, maxHp); player.AddChild(camera); diff --git a/scripts/UI.cs b/scripts/UI.cs new file mode 100644 index 0000000..fada956 --- /dev/null +++ b/scripts/UI.cs @@ -0,0 +1,17 @@ +using Godot; +using System; + +public partial class UI : Node2D +{ + private TextureProgressBar hpBar; + + public override void _Ready() { + base._Ready(); + hpBar = GetNode("CanvasLayer/HPbar"); + } + + public void OnHealthChanged(int hp, int maxHp) { + hpBar.Value = hp; + hpBar.MaxValue = maxHp; + } +} diff --git a/scripts/UI.cs.uid b/scripts/UI.cs.uid new file mode 100644 index 0000000..2ee1ac6 --- /dev/null +++ b/scripts/UI.cs.uid @@ -0,0 +1 @@ +uid://br7w3abe0boqb diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs index b651286..afa6989 100644 --- a/scripts/actors/Actor.cs +++ b/scripts/actors/Actor.cs @@ -6,10 +6,13 @@ using Godot; [GlobalClass] public abstract partial class Actor : Sprite2D { + [Signal] + public delegate void HealthChangedEventHandler(int hp, int maxHp); + /// - /// A definição do ator possui caracterísitcas padrões que definem - /// o ator em questão. - /// + /// A definição do ator possui caracterísitcas padrões que definem + /// o ator em questão. + /// protected ActorDefinition definition; /// /// É conveniente ter acesso ao mapa dentro do ator. Isto porque suas ações são feitas dentro @@ -95,6 +98,7 @@ public abstract partial class Actor : Sprite2D set { // Esta propriedade impede que o HP seja maior que o máximo. hp = int.Clamp(value, 0, MaxHp); + EmitSignal(SignalName.HealthChanged, Hp, MaxHp); if (hp <= 0) { Die(); } -- cgit v1.2.3