mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-12 12:15:54 +00:00
Migrated player state machine
This commit is contained in:
parent
bb3cdefaa2
commit
9c3f22760b
19 changed files with 108 additions and 69 deletions
|
|
@ -4,8 +4,9 @@ using Godot;
|
|||
|
||||
namespace Cirno.Scripts.Components.FSM.Player;
|
||||
|
||||
public partial class Active : PlayerFSMState
|
||||
public partial class Active : PlayerStateBase
|
||||
{
|
||||
public override PlayerState StateId => PlayerState.Active;
|
||||
private Vector2 _movementDirection { get; set; }
|
||||
public Vector2 FacingDirection { get; private set; } = Vector2.Down;
|
||||
|
||||
|
|
@ -36,18 +37,16 @@ public partial class Active : PlayerFSMState
|
|||
|
||||
public int MovementSpeed => _isStrafing ? StrafeSpeed : Speed;
|
||||
|
||||
private PlayerStateMachine _player;
|
||||
private CharacterBody2D _player;
|
||||
|
||||
private Hud _hud;
|
||||
|
||||
public override void Init(ActorStateMachine stateMachine)
|
||||
public override void Init(IStateMachine<PlayerState, CharacterBody2D> machine)
|
||||
{
|
||||
base.Init(stateMachine);
|
||||
base.Init(machine);
|
||||
|
||||
_hud = Hud.Instance;
|
||||
|
||||
_player = (PlayerStateMachine)stateMachine;
|
||||
|
||||
_damageReceiver.Death += () =>
|
||||
{
|
||||
ChangeState(PlayerState.Dead);
|
||||
|
|
@ -70,12 +69,12 @@ public partial class Active : PlayerFSMState
|
|||
_damageReceiver.RefillHealth();
|
||||
_damageReceiver.RefillShield();
|
||||
|
||||
_activationProvider.Init(stateMachine);
|
||||
_activationProvider.Init(MainObject);
|
||||
|
||||
//_weaponProvider = stateMachine.GetNode<PlayerWeaponProvider>("WeaponProvider");
|
||||
//_animationProvider = stateMachine.GetNode<PlayerAnimationProvider>("AnimationProvider");
|
||||
|
||||
_weaponProvider.Init(stateMachine);
|
||||
_weaponProvider.Init(MainObject);
|
||||
}
|
||||
|
||||
public override void EnterState()
|
||||
|
|
@ -102,9 +101,9 @@ public partial class Active : PlayerFSMState
|
|||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
_stateMachine.Velocity = _movementDirection * MovementSpeed;
|
||||
MainObject.Velocity = _movementDirection * MovementSpeed;
|
||||
|
||||
_stateMachine.MoveAndSlide();
|
||||
MainObject.MoveAndSlide();
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
|
|
@ -130,7 +129,7 @@ public partial class Active : PlayerFSMState
|
|||
}
|
||||
}
|
||||
|
||||
_animationProvider.SetAnimation(_stateMachine.Velocity);
|
||||
_animationProvider.SetAnimation(MainObject.Velocity);
|
||||
|
||||
_crosshairProvider.UpdatePosition(FacingDirection);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue