Shield particles

This commit is contained in:
MaddoScientisto 2025-02-22 17:08:19 +01:00
commit fc833ae300
2 changed files with 42 additions and 38 deletions

View file

@ -49,20 +49,19 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
[Export] public float MaxHealth = 32f;
[Export] public float MaxShield = 32f;
[Export] public Shader BlinkShader {get;set;}
[Export] public Sprite2D HitboxSprite { get; set; }
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.Player;
[ExportGroup("Action Names")]
[Export] private string _shootActionName = "shoot";
[ExportGroup("Action Names")]
[Export] private string _useActionName = "Use";
[ExportGroup("Action Names")]
[Export] private string _strafeActionName = "strafe";
[ExportGroup("Action Names")]
[Export] private string _nextWeaponActionName = "next_weapon";
[ExportGroup("Action Names")]
[Export] private string _previousWeaponActionName = "previous_weapon";
[ExportCategory("Particles")]
[Export] private PackedScene _deathParticles;
[Export] private GpuParticles2D _shieldParticles;
public Weapon EquippedWeapon { get; set; }
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
@ -81,10 +80,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
private ActorResourceProvider _healthProvider;
private ActorResourceProvider _shieldProvider;
[Export] public Sprite2D HitboxSprite { get; set; }
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.Player;
[Export] private PackedScene _deathParticles;
private bool _isStrafing { get; set; }
private bool _canMove = true;
@ -104,24 +99,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
[Signal]
public delegate void DeathEventHandler();
// public float CurrentHealth
// {
// get => _currentHealth;
// set
// {
// if (_currentHealth != value)
// {
// _currentHealth = value;
//
// if (_currentHealth > MaxHealth) {
// _currentHealth = MaxHealth;
// }
//
// EmitSignal(nameof(HealthChanged), _currentHealth, MaxHealth);
// }
// }
// }
public float CurrentHealth
{
get => _healthProvider.CurrentResource;
@ -473,6 +450,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
if (CurrentShield > 0 && type is not DamageType.Explosive or DamageType.Acid) {
// Reduce shield
PlayShieldAnimation();
CurrentShield -= damage;
if (CurrentShield < 0 ) {
CurrentHealth -= Math.Abs(CurrentShield);
@ -486,13 +464,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
else {
CurrentHealth -= damage;
}
}
// Blink
//_animatedSprite
if (BlinkShader != null)
{
_ = Blink();
Blink();
}
if (!(CurrentHealth <= 0)) return;
@ -500,7 +473,21 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
Explode();
}
private async Task Blink()
private void PlayShieldAnimation()
{
if (_shieldParticles is null) return;
_shieldParticles.Emitting = true;
}
public void Blink()
{
if (BlinkShader != null)
{
_ = BlinkAsync();
}
}
private async Task BlinkAsync()
{
((ShaderMaterial)_animatedSprite.Material).Shader = BlinkShader;