mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 02:25:54 +00:00
FSM Player input
This commit is contained in:
parent
c59a480ffd
commit
cc0d698bb5
7 changed files with 180 additions and 106 deletions
|
|
@ -8,17 +8,15 @@ public partial class Active : PlayerFSMState
|
|||
{
|
||||
private Vector2 _movementDirection { get; set; }
|
||||
private Vector2 _facingDirection { get; set; }
|
||||
|
||||
[Export] public Sprite2D HitboxSprite { get; set; }
|
||||
|
||||
[ExportGroup("Action Names")]
|
||||
[Export] private string _shootActionName = "shoot";
|
||||
[Export] private string _useActionName = "Use";
|
||||
[Export] private string _strafeActionName = "strafe";
|
||||
[Export] private string _nextWeaponActionName = "next_weapon";
|
||||
[Export] private string _previousWeaponActionName = "previous_weapon";
|
||||
|
||||
[Export]
|
||||
private PlayerWeaponProvider _weaponProvider;
|
||||
[Export]
|
||||
private PlayerAnimationProvider _animationProvider;
|
||||
|
||||
[Export]
|
||||
private InputProvider _inputProvider;
|
||||
|
||||
private bool _isStrafing { get; set; }
|
||||
|
||||
|
|
@ -34,7 +32,8 @@ public partial class Active : PlayerFSMState
|
|||
{
|
||||
base.Init(stateMachine);
|
||||
|
||||
_weaponProvider = stateMachine.GetNode<PlayerWeaponProvider>("WeaponProvider");
|
||||
//_weaponProvider = stateMachine.GetNode<PlayerWeaponProvider>("WeaponProvider");
|
||||
//_animationProvider = stateMachine.GetNode<PlayerAnimationProvider>("AnimationProvider");
|
||||
|
||||
_weaponProvider.Init(stateMachine);
|
||||
}
|
||||
|
|
@ -48,7 +47,7 @@ public partial class Active : PlayerFSMState
|
|||
|
||||
public override void ExitState()
|
||||
{
|
||||
|
||||
_animationProvider.SetAnimation(Vector2.Zero);
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
|
|
@ -60,10 +59,10 @@ public partial class Active : PlayerFSMState
|
|||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
SetAnimation();
|
||||
|
||||
|
||||
_movementDirection = GetInput();
|
||||
_isStrafing = Input.IsActionPressed(_strafeActionName);
|
||||
_movementDirection = _inputProvider.GetMovementInput();
|
||||
_isStrafing = _inputProvider.GetStrafePressed();
|
||||
|
||||
// Toggle visibility of the hitbox sprite based on strafing
|
||||
if (HitboxSprite != null)
|
||||
|
|
@ -71,7 +70,7 @@ public partial class Active : PlayerFSMState
|
|||
HitboxSprite.Visible = _isStrafing;
|
||||
}
|
||||
|
||||
var rightStickInput = GetRightStickInput();
|
||||
var rightStickInput = _inputProvider.GetAimInput();
|
||||
|
||||
// Update Facing Direction
|
||||
if (!_isStrafing)
|
||||
|
|
@ -86,72 +85,20 @@ public partial class Active : PlayerFSMState
|
|||
}
|
||||
}
|
||||
|
||||
_animationProvider.SetAnimation(_stateMachine.Velocity);
|
||||
|
||||
HandleShoot();
|
||||
// FindInteractable();
|
||||
|
||||
// if (Input.IsActionJustPressed(_nextWeaponActionName))
|
||||
// {
|
||||
// NextWeapon();
|
||||
// }
|
||||
|
||||
// if (Input.IsActionJustPressed(_previousWeaponActionName))
|
||||
// {
|
||||
// PreviousWeapon();
|
||||
// }
|
||||
|
||||
// _crosshair.Position = CalculateCrosshairPosition();
|
||||
|
||||
}
|
||||
|
||||
private void SetAnimation()
|
||||
{
|
||||
|
||||
// if (Velocity.X == 0 && Velocity.Y == 0)
|
||||
// {
|
||||
// _animatedSprite.SpeedScale = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _animatedSprite.SpeedScale = 1;
|
||||
// }
|
||||
|
||||
// if (Velocity.X > 0)
|
||||
// {
|
||||
// _animatedSprite.Play("walk_right");
|
||||
// }
|
||||
// else if (Velocity.X < 0)
|
||||
// {
|
||||
// _animatedSprite.Play("walk_left");
|
||||
// }
|
||||
// else if (Velocity.Y > 0)
|
||||
// {
|
||||
// _animatedSprite.Play("walk_down");
|
||||
// }
|
||||
// else if (Velocity.Y < 0)
|
||||
// {
|
||||
// _animatedSprite.Play("walk_up");
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void HandleShoot()
|
||||
{
|
||||
if (!Input.IsActionPressed(_shootActionName)) return;
|
||||
if (!_inputProvider.GetShootPressed()) return;
|
||||
_weaponProvider.Shoot(this._facingDirection);
|
||||
}
|
||||
|
||||
public Vector2 GetInput()
|
||||
{
|
||||
return Input.GetVector("left", "right", "up", "down");
|
||||
}
|
||||
|
||||
private Vector2 GetRightStickInput()
|
||||
{
|
||||
return new Vector2(
|
||||
Input.GetAxis("aim_left", "aim_right"),
|
||||
Input.GetAxis("aim_up", "aim_down")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue