mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Drown animation
This commit is contained in:
parent
be88896252
commit
aa2de85f9a
16 changed files with 264 additions and 14 deletions
|
|
@ -24,6 +24,9 @@ public partial class PlayerAnimationProvider : Node2D
|
|||
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;}
|
||||
|
|
@ -33,6 +36,13 @@ public partial class PlayerAnimationProvider : Node2D
|
|||
[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()
|
||||
{
|
||||
|
|
@ -142,6 +152,13 @@ public partial class PlayerAnimationProvider : Node2D
|
|||
this.CreateSibling<AutodeleteParticle>(_deathParticles, this.GlobalPosition);
|
||||
_animatedSprite.Visible = false;
|
||||
}
|
||||
|
||||
public void PlayDrowningAnimation()
|
||||
{
|
||||
_animatedSprite.Visible = true;
|
||||
_animatedSprite.Play(DrowningAnimationName);
|
||||
_animatedSprite.SpeedScale = 1;
|
||||
}
|
||||
|
||||
public void PlayShieldAnimation()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Cirno.Scripts.Components.FSM;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
|
@ -42,9 +43,13 @@ public partial class PlayerDamageReceiver : Area2D
|
|||
get => _shieldProvider.CurrentResource;
|
||||
set => _shieldProvider.CurrentResource = value;
|
||||
}
|
||||
|
||||
private IStateMachine<PlayerState, CharacterBody2D> _stateMachine;
|
||||
|
||||
public void Init()
|
||||
public void Init(IStateMachine<PlayerState, CharacterBody2D> machine)
|
||||
{
|
||||
_stateMachine = machine;
|
||||
|
||||
Invulnerable = GlobalState.Instance.SessionSettings.GodMode;
|
||||
|
||||
_healthProvider.ResourceChanged += ((value, maxValue) =>
|
||||
|
|
@ -107,7 +112,8 @@ public partial class PlayerDamageReceiver : Area2D
|
|||
{
|
||||
if (!Enabled) return;
|
||||
GD.Print("Acid death");
|
||||
_healthProvider.CurrentResource = 0;
|
||||
_stateMachine.SetState(PlayerState.Drowning);
|
||||
//_healthProvider.CurrentResource = 0;
|
||||
}
|
||||
|
||||
public void Hit(float damage, DamageType type = DamageType.Neutral)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public partial class Active : PlayerStateBase
|
|||
//_hud.UpdateShield(value, maxValue);
|
||||
};
|
||||
|
||||
_damageReceiver.Init();
|
||||
_damageReceiver.Init(StateMachine);
|
||||
|
||||
_damageReceiver.RefillHealth();
|
||||
_damageReceiver.RefillShield();
|
||||
|
|
|
|||
31
Scripts/Components/FSM/Player/Drowning.cs
Normal file
31
Scripts/Components/FSM/Player/Drowning.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Player;
|
||||
|
||||
public partial class Drowning : PlayerStateBase
|
||||
{
|
||||
public override PlayerState StateId => PlayerState.Drowning;
|
||||
|
||||
[Export]
|
||||
private PlayerAnimationProvider _animationProvider;
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
_animationProvider.PlayDrowningAnimation();
|
||||
|
||||
_animationProvider.OnAnimationEnded += AnimationProviderOnOnAnimationEnded;
|
||||
// Wait for animation over and switch to death
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void AnimationProviderOnOnAnimationEnded(StringName animationName)
|
||||
{
|
||||
if (animationName != _animationProvider.DrowningAnimationName) return;
|
||||
|
||||
_animationProvider.OnAnimationEnded -= AnimationProviderOnOnAnimationEnded;
|
||||
|
||||
StateMachine.SetState(PlayerState.Dead);
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/Player/Drowning.cs.uid
Normal file
1
Scripts/Components/FSM/Player/Drowning.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bgve2lktony00
|
||||
Loading…
Add table
Add a link
Reference in a new issue