mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Enemy FSM Animation
This commit is contained in:
parent
dd3d427ac3
commit
e7c1814d98
12 changed files with 161 additions and 6 deletions
|
|
@ -149,6 +149,7 @@ public partial class PlayerAnimationProvider : Node2D
|
|||
|
||||
public void PlayDeathAnimation()
|
||||
{
|
||||
if (_deathParticles is null) return;
|
||||
this.CreateSibling<AutodeleteParticle>(_deathParticles, this.GlobalPosition);
|
||||
_animatedSprite.Visible = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@ public partial class Alert : EnemyStateBase
|
|||
}
|
||||
|
||||
NavigationModule.Move();
|
||||
|
||||
StorageModule.FacingDirection = MainObject.Velocity.SnapToCardinal().Normalized();
|
||||
}
|
||||
|
||||
private void MoveTowardsPosition(Vector2 position)
|
||||
|
|
|
|||
44
Scripts/Components/FSM/Enemy/AnimationModule.cs
Normal file
44
Scripts/Components/FSM/Enemy/AnimationModule.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using Cirno.Scripts.Enums;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Enemy;
|
||||
|
||||
public partial class AnimationModule : ModuleBase<EnemyState, CharacterBody2D>
|
||||
{
|
||||
private IStateMachine<EnemyState, CharacterBody2D> _machine;
|
||||
|
||||
[Export] public PlayerAnimationProvider AnimationProvider { get; set; }
|
||||
|
||||
[Export] public EnemyStorageModule StorageModule { get; set; }
|
||||
|
||||
public override void EnterState(EnemyState state)
|
||||
{
|
||||
AnimationProvider.SetAnimation(StorageModule.FacingDirection);
|
||||
AnimationProvider.SetAnimation(Vector2.Zero);
|
||||
}
|
||||
|
||||
public override void ExitState(EnemyState state)
|
||||
{
|
||||
AnimationProvider.SetAnimation(Vector2.Zero);
|
||||
}
|
||||
|
||||
public override void Init(IStateMachine<EnemyState, CharacterBody2D> machine)
|
||||
{
|
||||
_machine = machine;
|
||||
}
|
||||
|
||||
public override void Process(double delta)
|
||||
{
|
||||
AnimationProvider.SetAnimation(StorageModule.FacingDirection);
|
||||
|
||||
if (_machine.MainObject.Velocity == Vector2.Zero)
|
||||
{
|
||||
AnimationProvider.SetAnimation(Vector2.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PhysicsProcess(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/Enemy/AnimationModule.cs.uid
Normal file
1
Scripts/Components/FSM/Enemy/AnimationModule.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dncdgq843sj2f
|
||||
|
|
@ -95,7 +95,8 @@ public partial class Shooting : EnemyStateBase
|
|||
|
||||
// Shoot at the player's last known position
|
||||
EquippedWeapon.ShootDirection = direction;
|
||||
StorageModule.FacingDirection = direction;
|
||||
//StorageModule.FacingDirection = direction;
|
||||
StorageModule.FacingDirection = direction.SnapToCardinal().Normalized();
|
||||
|
||||
EquippedWeapon.Shoot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,4 +89,16 @@ public static class Tools
|
|||
|
||||
return angles[Mathf.PosMod((int)(direction.X + 4), 8)].Normalized();
|
||||
}
|
||||
|
||||
public static Vector2 SnapToCardinal(this Vector2 input)
|
||||
{
|
||||
if (Mathf.Abs(input.X) > Mathf.Abs(input.Y))
|
||||
{
|
||||
return new Vector2(Mathf.Sign(input.X), 0); // Left or Right
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector2(0, Mathf.Sign(input.Y)); // Up or Down
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue