mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:45:33 +00:00
180 lines
No EOL
5.6 KiB
C#
180 lines
No EOL
5.6 KiB
C#
using Godot;
|
|
using GTweens.Builders;
|
|
using GTweens.Tweens;
|
|
using GTweensGodot.Extensions;
|
|
|
|
namespace Cirno.Scripts.Components.Actors._3D;
|
|
|
|
public partial class PlayerAnimationProvider3D : Node3D
|
|
{
|
|
[Export] public AnimatedSprite3D AnimatedSprite {get; private set;}
|
|
|
|
[ExportCategory("Animation Names")]
|
|
[Export]
|
|
public StringName WalkRightAnimationName {get; private set;} = "walk_right";
|
|
|
|
[Export]
|
|
public StringName WalkLeftAnimationName {get; private set;} = "walk_left";
|
|
[Export]
|
|
public StringName WalkDownAnimationName {get; private set;} = "walk_down";
|
|
[Export]
|
|
public StringName WalkUpAnimationName {get; private set;} = "walk_up";
|
|
|
|
[Export]
|
|
public StringName DrowningAnimationName {get; private set;} = "Drowning";
|
|
|
|
[ExportCategory("Shaders")]
|
|
[Export] public ShaderMaterial BlinkMaterial {get; private set;}
|
|
|
|
[Export] public StringName BlinkShaderPropertyName { get; private set; } = new("blink_intensity");
|
|
[Export] public StringName TeleportProgressPropertyName { get; private set; } = new("teleport_progress");
|
|
[Export] public StringName ScanlineDensityPropertyName { get; private set; } = new("scanline_density");
|
|
|
|
private GTween _blinkTween;
|
|
|
|
[Signal] public delegate void OnAnimationEndedEventHandler(StringName animationName);
|
|
|
|
public override void _Ready()
|
|
{
|
|
AnimatedSprite.AnimationFinished += () => EmitSignal(SignalName.OnAnimationEnded, AnimatedSprite.Animation);
|
|
}
|
|
|
|
public void ShowSprite()
|
|
{
|
|
this.Show();
|
|
}
|
|
|
|
public void HideSprite()
|
|
{
|
|
this.Hide();
|
|
}
|
|
|
|
public void SetAnimationSpeed(Vector2 velocity)
|
|
{
|
|
if (velocity.Length() == 0)
|
|
{
|
|
AnimatedSprite.SpeedScale = 0;
|
|
}
|
|
else
|
|
{
|
|
if (velocity.Length() > 40)
|
|
{
|
|
AnimatedSprite.SpeedScale = 1;
|
|
}
|
|
else
|
|
{
|
|
AnimatedSprite.SpeedScale = 0.8f;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public void SetAnimation(Vector2 direction)
|
|
{
|
|
if (direction == Vector2.Zero)
|
|
return;
|
|
|
|
float angle = Mathf.RadToDeg(direction.Angle());
|
|
|
|
// Normalize to 0-360
|
|
if (angle < 0)
|
|
angle += 360;
|
|
|
|
string animToPlay;
|
|
|
|
switch (angle)
|
|
{
|
|
case >= 45 and < 135:
|
|
AnimatedSprite.Play(WalkDownAnimationName);
|
|
break;
|
|
case >= 135 and < 225:
|
|
AnimatedSprite.Play(WalkLeftAnimationName);
|
|
break;
|
|
case >= 225 and < 315:
|
|
AnimatedSprite.Play(WalkUpAnimationName);
|
|
break;
|
|
default:
|
|
AnimatedSprite.Play(WalkRightAnimationName);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
public void PlayDeathAnimation()
|
|
{
|
|
// if (_deathParticles is null) return;
|
|
// this.CreateSibling<AutodeleteParticle>(_deathParticles, this.GlobalPosition);
|
|
// _animatedSprite.Visible = false;
|
|
}
|
|
|
|
public void PlayDrowningAnimation()
|
|
{
|
|
this.Visible = true;
|
|
AnimatedSprite.Play(DrowningAnimationName);
|
|
AnimatedSprite.SpeedScale = 1;
|
|
}
|
|
|
|
public void Blink()
|
|
{
|
|
if (BlinkMaterial == null) return;
|
|
AnimatedSprite.MaterialOverride = BlinkMaterial;
|
|
|
|
var material = ((ShaderMaterial)AnimatedSprite.MaterialOverride);
|
|
|
|
_blinkTween?.Kill();
|
|
|
|
_blinkTween = GTweenSequenceBuilder.New()
|
|
.Append(material.TweenPropertyFloat(BlinkShaderPropertyName, 1f, 0f))
|
|
.Append(material.TweenPropertyFloat(BlinkShaderPropertyName, 0f, 0.5f))
|
|
.Build();
|
|
|
|
_blinkTween.Play();
|
|
}
|
|
|
|
public void PlayTeleportAnimation()
|
|
{
|
|
if (BlinkMaterial == null) return;
|
|
AnimatedSprite.MaterialOverride = BlinkMaterial;
|
|
var material = ((ShaderMaterial)AnimatedSprite.MaterialOverride);
|
|
_blinkTween?.Kill();
|
|
_blinkTween = GTweenSequenceBuilder.New()
|
|
.Append(material.TweenPropertyFloat(TeleportProgressPropertyName, 0f, 0f))
|
|
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName, 0f, 0f))
|
|
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName,50f,0.5f))
|
|
.Join(material.TweenPropertyFloat(TeleportProgressPropertyName, 1f,0.5f))
|
|
.Build();
|
|
|
|
_blinkTween.Play();
|
|
}
|
|
|
|
public void PlayUnteleportAnimation()
|
|
{
|
|
if (BlinkMaterial == null) return;
|
|
AnimatedSprite.MaterialOverride = BlinkMaterial;
|
|
var material = ((ShaderMaterial)AnimatedSprite.MaterialOverride);
|
|
_blinkTween?.Kill();
|
|
_blinkTween = GTweenSequenceBuilder.New()
|
|
.Append(material.TweenPropertyFloat(TeleportProgressPropertyName, 1f, 0f))
|
|
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName, 50f, 0f))
|
|
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName,0f,0.5f))
|
|
.Join(material.TweenPropertyFloat(TeleportProgressPropertyName, 0f,0.5f))
|
|
.Build();
|
|
|
|
_blinkTween.Play();
|
|
}
|
|
|
|
private void SetShaderTeleportProgress(float value)
|
|
{
|
|
((ShaderMaterial)AnimatedSprite.MaterialOverride).SetShaderParameter("teleport_progress", value);
|
|
}
|
|
|
|
private void SetShaderScanlineDensity(float value)
|
|
{
|
|
((ShaderMaterial)AnimatedSprite.MaterialOverride).SetShaderParameter("scanline_density", value);
|
|
}
|
|
|
|
private void SetShaderBlinkIntensity(float newValue)
|
|
{
|
|
((ShaderMaterial)AnimatedSprite.MaterialOverride).SetShaderParameter("blink_intensity", newValue);
|
|
}
|
|
} |