summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scenes/Game.tscn5
-rw-r--r--scenes/ui.tscn3
-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
6 files changed, 36 insertions, 4 deletions
diff --git a/scenes/Game.tscn b/scenes/Game.tscn
index 2003472..326373a 100644
--- a/scenes/Game.tscn
+++ b/scenes/Game.tscn
@@ -1,10 +1,11 @@
-[gd_scene load_steps=6 format=3 uid="uid://u5h6iqyi8wd0"]
+[gd_scene load_steps=7 format=3 uid="uid://u5h6iqyi8wd0"]
[ext_resource type="Script" uid="uid://dwubb28wt4bhe" path="res://scripts/Game.cs" id="1_cpr0p"]
[ext_resource type="Script" uid="uid://fe2h4is11tnw" path="res://scripts/map/Map.cs" id="3_cpr0p"]
[ext_resource type="Script" uid="uid://ejqmdbc0524i" path="res://scripts/input/InputHandler.cs" id="3_s0nni"]
[ext_resource type="Script" uid="uid://dwyr067lwqcsj" path="res://scripts/map/DungeonGenerator.cs" id="4_78awf"]
[ext_resource type="Script" uid="uid://bereyrj1s46y5" path="res://scripts/map/FieldOfView.cs" id="5_s0nni"]
+[ext_resource type="PackedScene" uid="uid://bnuyp1ahv7q0h" path="res://scenes/ui.tscn" id="6_aug50"]
[node name="Game" type="Node"]
script = ExtResource("1_cpr0p")
@@ -31,3 +32,5 @@ script = ExtResource("5_s0nni")
[node name="Camera2D" type="Camera2D" parent="."]
offset = Vector2(8, 8)
zoom = Vector2(2, 2)
+
+[node name="UI" parent="." instance=ExtResource("6_aug50")]
diff --git a/scenes/ui.tscn b/scenes/ui.tscn
index b71e544..47fdf59 100644
--- a/scenes/ui.tscn
+++ b/scenes/ui.tscn
@@ -1,5 +1,6 @@
[gd_scene load_steps=7 format=3 uid="uid://b4h4xyr1g8o50"]
+[ext_resource type="Script" uid="uid://br7w3abe0boqb" path="res://scripts/UI.cs" id="1_gdt2y"]
[ext_resource type="Texture2D" uid="uid://ch6rupow513ab" path="res://assets/sprites/inter-face/HP/HealthBarUnder.png" id="1_yev5y"]
[ext_resource type="Texture2D" uid="uid://c0vvfwqjxqjcv" path="res://assets/sprites/inter-face/HP/HealthBarOverlay.png" id="2_gdt2y"]
[ext_resource type="Texture2D" uid="uid://ckbvtym6yywf0" path="res://assets/sprites/inter-face/HP/HealthBar.png" id="3_wm3ai"]
@@ -8,12 +9,14 @@
[ext_resource type="Texture2D" uid="uid://b1rotmrfynpau" path="res://assets/sprites/inter-face/MP/ManaBar.png" id="6_ktti3"]
[node name="UI" type="Node2D"]
+script = ExtResource("1_gdt2y")
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="HPbar" type="TextureProgressBar" parent="CanvasLayer"]
offset_right = 50.0
offset_bottom = 10.0
+scale = Vector2(6, 6)
value = 100.0
texture_under = ExtResource("1_yev5y")
texture_over = ExtResource("2_gdt2y")
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();
}