mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 01:15:53 +00:00
Health in HUD
This commit is contained in:
parent
60f2797541
commit
4b4cbc037a
5 changed files with 45 additions and 10 deletions
|
|
@ -34,7 +34,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private Sprite2D _crosshair;
|
||||
|
||||
[Export] public float Health = 4f;
|
||||
[Export] public float MaxHealth = 32f;
|
||||
|
||||
[Export] public Weapon EquippedWeapon;
|
||||
|
||||
|
|
@ -46,11 +46,27 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private bool _isStrafing { get; set; }
|
||||
|
||||
[Signal]
|
||||
public delegate void HealthChangedEventHandler(float newHealth, float MaxHealth);
|
||||
|
||||
public float CurrentHealth
|
||||
{
|
||||
get => _currentHealth;
|
||||
set
|
||||
{
|
||||
if (_currentHealth != value)
|
||||
{
|
||||
_currentHealth = value;
|
||||
EmitSignal(nameof(HealthChanged), _currentHealth, MaxHealth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//private InventoryManager _inventoryManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_currentHealth = Health;
|
||||
CurrentHealth = MaxHealth;
|
||||
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("./Smoothing2D/AnimatedSprite2D");
|
||||
_crosshair = GetNode<Sprite2D>("./Smoothing2D/Crosshair");
|
||||
|
|
@ -245,8 +261,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
GD.Print($"Player damaged for {damage}");
|
||||
if (_isDestroyed) return;
|
||||
|
||||
_currentHealth -= damage;
|
||||
if (!(_currentHealth <= 0)) return;
|
||||
CurrentHealth -= damage;
|
||||
if (!(CurrentHealth <= 0)) return;
|
||||
_isDestroyed = true;
|
||||
Explode();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue