mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-06 05:05:53 +00:00
Enemy blinking
This commit is contained in:
parent
79cac3ebae
commit
e5a60a6ccd
11 changed files with 172 additions and 30 deletions
61
Scripts/Components/FSM/Enemy/3D/EnemyAnimationModule3D.cs
Normal file
61
Scripts/Components/FSM/Enemy/3D/EnemyAnimationModule3D.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
using Cirno.Scripts.Components.Actors;
|
||||
using Cirno.Scripts.Components.Actors._3D;
|
||||
using Cirno.Scripts.Enums;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Enemy._3D;
|
||||
|
||||
public partial class EnemyAnimationModule3D : ModuleBase<EnemyState, CharacterBody3D>
|
||||
{
|
||||
private IStateMachine<EnemyState, CharacterBody3D> _machine;
|
||||
|
||||
[Export] public PlayerAnimationProvider3D AnimationProvider { get; private set; }
|
||||
|
||||
[Export] public EnemyStorage3D Storage { get; private set; }
|
||||
|
||||
[Export] public ActorResourceProvider HealthProvider { get; private set; }
|
||||
|
||||
public override void EnterState(EnemyState state)
|
||||
{
|
||||
AnimationProvider.SetAnimation(Storage.AimingDirection);
|
||||
AnimationProvider.SetAnimation(Vector2.Zero);
|
||||
if (HealthProvider is not null)
|
||||
{
|
||||
HealthProvider.ResourceDecreased += HealthProviderOnResourceDecreased;
|
||||
}
|
||||
}
|
||||
|
||||
private void HealthProviderOnResourceDecreased(float oldValue, float newValue, float maxValue)
|
||||
{
|
||||
AnimationProvider?.Blink();
|
||||
}
|
||||
|
||||
public override void ExitState(EnemyState state)
|
||||
{
|
||||
AnimationProvider.SetAnimation(Vector2.Zero);
|
||||
if (HealthProvider is not null)
|
||||
{
|
||||
HealthProvider.ResourceDecreased -= HealthProviderOnResourceDecreased;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init(IStateMachine<EnemyState, CharacterBody3D> machine)
|
||||
{
|
||||
_machine = machine;
|
||||
}
|
||||
|
||||
public override void Process(double delta)
|
||||
{
|
||||
AnimationProvider.SetAnimation(Storage.AimingDirection);
|
||||
|
||||
if (_machine.MainObject.Velocity == Vector3.Zero)
|
||||
{
|
||||
AnimationProvider.SetAnimation(Vector2.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PhysicsProcess(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue