mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 04:45:54 +00:00
Movement friction
This commit is contained in:
parent
946e7df71e
commit
b16e633451
19 changed files with 143 additions and 54 deletions
|
|
@ -8,43 +8,38 @@ public partial class Active : PlayerStateBase
|
|||
{
|
||||
public override PlayerState StateId => PlayerState.Active;
|
||||
private Vector2 _movementDirection { get; set; }
|
||||
|
||||
public Vector2 FacingDirection
|
||||
{
|
||||
get => _storageModule.FacingDirection;
|
||||
private set => _storageModule.FacingDirection = value;
|
||||
}
|
||||
|
||||
[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] public int Speed { get; set; } = 45;
|
||||
[Export] public int StrafeSpeed { get; set; } = 35;
|
||||
[Export] public float Acceleration = 8f;
|
||||
[Export] public float Deceleration = 8f;
|
||||
|
||||
[ExportCategory("Providers")] [Export] private PlayerWeaponProvider _weaponProvider;
|
||||
[Export] private PlayerAnimationProvider _animationProvider;
|
||||
[Export] private PlayerCrosshairProvider _crosshairProvider;
|
||||
[Export] private PlayerHitboxSpriteProvider _hitboxSpriteProvider;
|
||||
|
||||
[Export]
|
||||
private InputProvider _inputProvider;
|
||||
[Export] private InputProvider _inputProvider;
|
||||
|
||||
[Export] private PlayerDamageReceiver _damageReceiver;
|
||||
[Export] private ActivationProvider _activationProvider;
|
||||
|
||||
[Export] private InteractionController _interactionController;
|
||||
|
||||
|
||||
[Export] private PlayerStorageModule _storageModule;
|
||||
|
||||
private bool _isStrafing;
|
||||
|
||||
|
||||
public int MovementSpeed => _isStrafing ? StrafeSpeed : Speed;
|
||||
|
||||
private CharacterBody2D _player;
|
||||
|
||||
|
||||
private Hud _hud;
|
||||
|
||||
public override void Init(IStateMachine<PlayerState, CharacterBody2D> machine)
|
||||
|
|
@ -53,10 +48,7 @@ public partial class Active : PlayerStateBase
|
|||
|
||||
_hud = Hud.Instance;
|
||||
|
||||
_damageReceiver.Death += () =>
|
||||
{
|
||||
ChangeState(PlayerState.Dead);
|
||||
};
|
||||
_damageReceiver.Death += () => { ChangeState(PlayerState.Dead); };
|
||||
|
||||
_damageReceiver.HealthDecreased += (value, newValue, maxValue) =>
|
||||
{
|
||||
|
|
@ -69,14 +61,14 @@ public partial class Active : PlayerStateBase
|
|||
_animationProvider.PlayShieldAnimation();
|
||||
//_hud.UpdateShield(value, maxValue);
|
||||
};
|
||||
|
||||
|
||||
_damageReceiver.Init(StateMachine);
|
||||
|
||||
|
||||
_damageReceiver.RefillHealth();
|
||||
_damageReceiver.RefillShield();
|
||||
|
||||
|
||||
_activationProvider.Init(MainObject);
|
||||
|
||||
|
||||
//_weaponProvider = stateMachine.GetNode<PlayerWeaponProvider>("WeaponProvider");
|
||||
//_animationProvider = stateMachine.GetNode<PlayerAnimationProvider>("AnimationProvider");
|
||||
|
||||
|
|
@ -93,6 +85,9 @@ public partial class Active : PlayerStateBase
|
|||
_damageReceiver.Enabled = true;
|
||||
_activationProvider.Enabled = true;
|
||||
_interactionController.Enabled = true;
|
||||
|
||||
_accelerationPerSecond = Speed / Acceleration;
|
||||
_decelerationPerSecond = Speed / Deceleration;
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
|
|
@ -102,59 +97,79 @@ public partial class Active : PlayerStateBase
|
|||
//_animationProvider.SetAnimation(Vector2.Zero);
|
||||
_crosshairProvider.Hide();
|
||||
_hitboxSpriteProvider.Hide();
|
||||
|
||||
|
||||
_damageReceiver.Enabled = false;
|
||||
_activationProvider.Enabled = false;
|
||||
_interactionController.Enabled = false;
|
||||
}
|
||||
|
||||
private float _accelerationPerSecond;
|
||||
private float _decelerationPerSecond;
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
{
|
||||
// Reset at start of frame
|
||||
MainObject.Velocity = Vector2.Zero;
|
||||
|
||||
//MainObject.Velocity = Vector2.Zero;
|
||||
|
||||
// Process modules
|
||||
base.PhysicsProcessState(delta);
|
||||
|
||||
MainObject.Velocity += _movementDirection * MovementSpeed;
|
||||
if (_isStrafing)
|
||||
{
|
||||
// Instant movement at strafe speed
|
||||
MainObject.Velocity = _movementDirection * StrafeSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 targetVelocity = _movementDirection * Speed;
|
||||
|
||||
if (_movementDirection != Vector2.Zero)
|
||||
{
|
||||
MainObject.Velocity = MainObject.Velocity.MoveToward(targetVelocity, Acceleration * (float)delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
MainObject.Velocity = MainObject.Velocity.MoveToward(Vector2.Zero, Deceleration * (float)delta);
|
||||
}
|
||||
}
|
||||
|
||||
//MainObject.Velocity += _movementDirection * MovementSpeed;
|
||||
|
||||
MainObject.MoveAndSlide();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
base.ProcessState(delta);
|
||||
|
||||
|
||||
_movementDirection = _inputProvider.GetMovementInput().Normalized();
|
||||
_isStrafing = _inputProvider.GetStrafePressed();
|
||||
|
||||
// Toggle visibility of the hitbox sprite based on strafing
|
||||
_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;
|
||||
}
|
||||
else if (_movementDirection != Vector2.Zero) // Fall back to movement direction
|
||||
{
|
||||
FacingDirection = _movementDirection;
|
||||
}
|
||||
if (rightStickInput.Length() > 0.1f) // If the right stick is moved
|
||||
{
|
||||
FacingDirection = rightStickInput;
|
||||
}
|
||||
else if (_movementDirection != Vector2.Zero) // Fall back to movement direction
|
||||
{
|
||||
FacingDirection = _movementDirection;
|
||||
}
|
||||
// }
|
||||
|
||||
_animationProvider.SetAnimationSpeed(MainObject.Velocity);
|
||||
_animationProvider.SetAnimation(FacingDirection);
|
||||
|
||||
_crosshairProvider.UpdatePosition(FacingDirection);
|
||||
|
||||
|
||||
HandleShoot();
|
||||
|
||||
|
||||
HandleInteraction();
|
||||
// FindInteractable();
|
||||
|
||||
|
|
@ -199,4 +214,4 @@ public partial class Active : PlayerStateBase
|
|||
_weaponProvider.PreviousWeapon();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue