mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-06 01:55:54 +00:00
Health and shield gauges
This commit is contained in:
parent
9e04056800
commit
3682de18d5
14 changed files with 188 additions and 22 deletions
|
|
@ -94,6 +94,8 @@ public partial class GameManager : Node2D
|
|||
if (_player != null && _hud != null)
|
||||
{
|
||||
_player.HealthChanged += (newHealth, maxHealth) => _hud.UpdateHealth(newHealth, maxHealth);
|
||||
|
||||
_player.ShieldChanged += (newShield, maxShield) => _hud.UpdateShield(newShield, maxShield);
|
||||
|
||||
_player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,14 @@ public partial class Hud : CanvasLayer
|
|||
private Node2D _selector;
|
||||
|
||||
[Export] private Label _healthLabel;
|
||||
[Export] private ProgressBar _healthBar;
|
||||
|
||||
[Export] private Label _shieldLabel;
|
||||
[Export] private ProgressBar _shieldBar;
|
||||
|
||||
[Export] private Container _itemsContainer;
|
||||
|
||||
[Export] private LabelSettings _labelSettings;
|
||||
|
||||
private Dictionary<string, HudItem> _items = new();
|
||||
|
||||
|
|
@ -56,6 +63,19 @@ public partial class Hud : CanvasLayer
|
|||
public void UpdateHealth(float newHealth, float maxHealth)
|
||||
{
|
||||
_healthLabel.Text = $"{newHealth}/{maxHealth}";
|
||||
if (_healthBar != null)
|
||||
{
|
||||
_healthBar.Value = newHealth;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateShield(float newValue, float maxValue)
|
||||
{
|
||||
_shieldLabel.Text = $"{newValue}/{maxValue}";
|
||||
if (_shieldBar != null)
|
||||
{
|
||||
_shieldBar.Value = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateInteractable(Interactable interactable) {
|
||||
|
|
@ -109,11 +129,8 @@ public partial class Hud : CanvasLayer
|
|||
// {
|
||||
// label.Text = currentAmount.ToString();
|
||||
// }
|
||||
|
||||
label.LabelSettings = new LabelSettings()
|
||||
{
|
||||
FontSize = 8
|
||||
};
|
||||
|
||||
label.LabelSettings = _labelSettings;
|
||||
hbox.AddChild(label);
|
||||
|
||||
hudItem.Label = label;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
private AnimatedSprite2D _animatedSprite;
|
||||
|
||||
private Vector2 _movementDirection { get; set; }
|
||||
|
||||
private Vector2 _facingDirection { get; set; }
|
||||
|
||||
private Vector2 _rightStickInput { get; set; }
|
||||
|
|
@ -43,6 +42,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
private Sprite2D _crosshair;
|
||||
|
||||
[Export] public float MaxHealth = 32f;
|
||||
[Export] public float MaxShield = 32f;
|
||||
|
||||
public Weapon EquippedWeapon { get; set; }
|
||||
|
||||
|
|
@ -51,6 +51,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
public int CurrentWeaponIndex { get; set; } = 0;
|
||||
|
||||
private float _currentHealth = 0f;
|
||||
private float _currentShield = 0f;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
|
|
@ -66,6 +67,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
[Signal]
|
||||
public delegate void HealthChangedEventHandler(float newHealth, float MaxHealth);
|
||||
|
||||
[Signal]
|
||||
public delegate void ShieldChangedEventHandler(float newShield, float maxShield);
|
||||
|
||||
[Signal]
|
||||
public delegate void InteractableAreaEnteredEventHandler(Interactable interactable);
|
||||
|
|
@ -86,11 +90,25 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
}
|
||||
}
|
||||
|
||||
public float CurrentShield
|
||||
{
|
||||
get => _currentShield;
|
||||
set
|
||||
{
|
||||
if (_currentShield != value)
|
||||
{
|
||||
_currentShield = value;
|
||||
EmitSignal(nameof(ShieldChanged), _currentShield, MaxShield);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//private InventoryManager _inventoryManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CurrentHealth = MaxHealth;
|
||||
CurrentShield = MaxShield;
|
||||
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("./Smoothing2D/AnimatedSprite2D");
|
||||
_crosshair = GetNode<Sprite2D>("./Smoothing2D/Crosshair");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue