mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Strafing and crosshair for FSM player
This commit is contained in:
parent
5073cfea70
commit
af0261ce8e
6 changed files with 170 additions and 23 deletions
|
|
@ -7,24 +7,29 @@ namespace Cirno.Scripts.Components.FSM.Player;
|
|||
public partial class Active : PlayerFSMState
|
||||
{
|
||||
private Vector2 _movementDirection { get; set; }
|
||||
private Vector2 _facingDirection { get; set; }
|
||||
[Export] public Sprite2D HitboxSprite { get; set; }
|
||||
|
||||
[Export]
|
||||
private PlayerWeaponProvider _weaponProvider;
|
||||
[Export]
|
||||
private PlayerAnimationProvider _animationProvider;
|
||||
|
||||
[Export]
|
||||
private InputProvider _inputProvider;
|
||||
|
||||
private bool _isStrafing { get; set; }
|
||||
|
||||
public Vector2 FacingDirection { get; private set; }
|
||||
|
||||
[Export]
|
||||
public int Speed { get; set; } = 45;
|
||||
|
||||
[Export]
|
||||
public int StrafeSpeed { get; set; } = 35;
|
||||
|
||||
[ExportCategory("Providers")]
|
||||
[Export]
|
||||
private PlayerWeaponProvider _weaponProvider;
|
||||
[Export]
|
||||
private PlayerAnimationProvider _animationProvider;
|
||||
[Export]
|
||||
private PlayerCrosshairProvider _crosshairProvider;
|
||||
[Export] private PlayerHitboxSpriteProvider _hitboxSpriteProvider;
|
||||
|
||||
[Export]
|
||||
private InputProvider _inputProvider;
|
||||
|
||||
private bool _isStrafing;
|
||||
|
||||
|
||||
|
||||
public int MovementSpeed => _isStrafing ? StrafeSpeed : Speed;
|
||||
|
||||
|
|
@ -42,12 +47,14 @@ public partial class Active : PlayerFSMState
|
|||
{
|
||||
// enable sprite
|
||||
// enable crosshair
|
||||
GD.Print(this.State.ToString());
|
||||
_crosshairProvider.Show();
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
_animationProvider.SetAnimation(Vector2.Zero);
|
||||
_crosshairProvider.Hide();
|
||||
_hitboxSpriteProvider.Hide();
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
|
|
@ -59,34 +66,31 @@ public partial class Active : PlayerFSMState
|
|||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
|
||||
|
||||
_movementDirection = _inputProvider.GetMovementInput();
|
||||
_movementDirection = _inputProvider.GetMovementInput().Normalized();
|
||||
_isStrafing = _inputProvider.GetStrafePressed();
|
||||
|
||||
// Toggle visibility of the hitbox sprite based on strafing
|
||||
if (HitboxSprite != null)
|
||||
{
|
||||
HitboxSprite.Visible = _isStrafing;
|
||||
}
|
||||
|
||||
var rightStickInput = _inputProvider.GetAimInput();
|
||||
_hitboxSpriteProvider.SetVisibility(_isStrafing);
|
||||
|
||||
var rightStickInput = _inputProvider.GetAimInput().Normalized();
|
||||
|
||||
// Update Facing Direction
|
||||
if (!_isStrafing)
|
||||
{
|
||||
if (rightStickInput.Length() > 0.1f) // If the right stick is moved
|
||||
{
|
||||
_facingDirection = rightStickInput.Normalized();
|
||||
FacingDirection = rightStickInput.Normalized();
|
||||
}
|
||||
else if (_movementDirection != Vector2.Zero) // Fall back to movement direction
|
||||
{
|
||||
_facingDirection = _movementDirection;
|
||||
FacingDirection = _movementDirection;
|
||||
}
|
||||
}
|
||||
|
||||
_animationProvider.SetAnimation(_stateMachine.Velocity);
|
||||
|
||||
_crosshairProvider.UpdatePosition(FacingDirection);
|
||||
|
||||
HandleShoot();
|
||||
// FindInteractable();
|
||||
|
||||
|
|
@ -97,7 +101,7 @@ public partial class Active : PlayerFSMState
|
|||
private void HandleShoot()
|
||||
{
|
||||
if (!_inputProvider.GetShootPressed()) return;
|
||||
_weaponProvider.Shoot(this._facingDirection);
|
||||
_weaponProvider.Shoot(this.FacingDirection);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue