FSM Player health and animations

This commit is contained in:
Marco 2025-03-01 14:08:31 +01:00
commit f91df43caa
13 changed files with 317 additions and 32 deletions

View file

@ -1,10 +1,19 @@
using System.Threading.Tasks;
using Cirno.Scripts;
using Cirno.Scripts.Components;
using Godot;
using GTweens.Builders;
using GTweens.Tweens;
using GTweensGodot.Extensions;
public partial class PlayerAnimationProvider : Node2D
{
[Export]
public AnimatedSprite2D _animatedSprite {get; private set;}
[Export] private PackedScene _deathParticles;
[Export] private GpuParticles2D _shieldParticles;
[ExportCategory("Animation Names")]
[Export]
public string WalkRightAnimationName {get; private set;} = "walk_right";
@ -16,6 +25,13 @@ public partial class PlayerAnimationProvider : Node2D
[Export]
public string WalkUpAnimationName {get; private set;} = "walk_up";
[ExportCategory("Shaders")]
[Export] public ShaderMaterial BlinkMaterial {get; private set;}
[Export] public StringName BlinkShaderPropertyName { get; private set; } = new StringName("blink_intensity");
private GTween _blinkTween;
public void SetAnimation(Vector2 velocity)
{
if (velocity.X == 0 && velocity.Y == 0)
@ -45,4 +61,46 @@ public partial class PlayerAnimationProvider : Node2D
}
}
public void Blink()
{
if (BlinkMaterial == null) return;
_animatedSprite.Material = BlinkMaterial;
var material = ((ShaderMaterial)_animatedSprite.Material);
_blinkTween?.Kill();
_blinkTween = GTweenSequenceBuilder.New()
.Append(material.TweenPropertyFloat(BlinkShaderPropertyName, 1f, 0f))
.Append(material.TweenPropertyFloat(BlinkShaderPropertyName, 0f, 0.5f))
.Build();
_blinkTween.Play();
}
private void SetShaderTeleportProgress(float value)
{
((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("teleport_progress", value);
}
private void SetShaderScanlineDensity(float value)
{
((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("scanline_density", value);
}
private void SetShaderBlinkIntensity(float newValue)
{
((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("blink_intensity", newValue);
}
public void PlayDeathAnimation()
{
this.CreateSibling<AutodeleteParticle>(_deathParticles, this.GlobalPosition);
_animatedSprite.Visible = false;
}
public void PlayShieldAnimation()
{
_shieldParticles.Emitting = true;
}
}