summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Game.cs4
-rw-r--r--scripts/UI.cs17
-rw-r--r--scripts/UI.cs.uid1
-rw-r--r--scripts/actors/Actor.cs10
4 files changed, 29 insertions, 3 deletions
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 {
/// </summary>
private InputHandler inputHandler;
+ private UI ui;
+
public override void _Ready() {
base._Ready();
Map = GetNode<Map>("Map");
inputHandler = GetNode<InputHandler>("InputHandler");
+ ui = GetNode<UI>("UI");
// O jogador é criado pelo jogo.
Player player = new Player(Vector2I.Zero, null, playerDefinition);
Camera2D camera = GetNode<Camera2D>("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<TextureProgressBar>("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);
+
/// <summary>
- /// A definição do ator possui caracterísitcas padrões que definem
- /// o ator em questão.
- /// </summary>
+ /// A definição do ator possui caracterísitcas padrões que definem
+ /// o ator em questão.
+ /// </summary>
protected ActorDefinition definition;
/// <summary>
/// É 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();
}