more movement tweaks & energy interface upgrade

This commit is contained in:
Lilith Schier 2026-09-05 00:00:13 +02:00
parent 8ab8973894
commit bed5e49547
17 changed files with 96 additions and 161 deletions

View file

@ -59,6 +59,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
[Export] public float Health { get; set; }
[Export] public bool CanTurn { get; set; } = true;
[Export] public float MaxDashPoints { get; set; } = 2f;
[Export] public float DashPointRate { get; set; } = 0.5f;
private ulong MaxInputBufferTimeMicroseconds => (ulong)(MaxInputBufferTime * 1_000_000);
public bool IsJumping => !JumpTimer.IsStopped();
@ -68,6 +69,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
/// The direction the player is currently holding.
/// This vector's components should always be -1/0/1.
private Vector2 _currentDirection = Vector2.Zero;
/// The raw direction the player is currently holding, no guarantees.
private Vector2 _currentRawDirection = Vector2.Zero;
@ -151,6 +153,11 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
var dragAmount = 0f;
if (CanTurn) AdjustFacing();
// This one can be buffered indefinitely.
if (!WaterJumpAllowedTimer.IsStopped() && Input.IsActionPressed(ActionName.Jump))
{
WaterExitJump();
}
if (!DashTimer.IsStopped())
{
@ -160,7 +167,13 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
else if (IsInWater)
{
var velocityWasTooLarge = velocity.Length() > WaterMaxSpeed;
velocity += _currentDirection.Normalized() * WaterAccel * deltaF;
var inputDirection = _currentDirection;
if (Input.IsActionPressed(ActionName.Jump))
{
inputDirection.Y = -1f;
}
velocity += inputDirection.Normalized() * WaterAccel * deltaF;
var velocityIsTooLarge = velocity.Length() > WaterMaxSpeed;
if (velocityWasTooLarge && velocityIsTooLarge)
{
@ -172,10 +185,10 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
velocity = velocity.LimitLength(WaterMaxSpeed);
}
if (!velocityIsTooLarge && _currentDirection.IsZeroApprox())
if (!velocityIsTooLarge && inputDirection.IsZeroApprox())
{
dragAmount = 0.1f;
velocity = velocity.MoveToward(Vector2.Zero, 0.1f * deltaF);
velocity = velocity.MoveToward(Vector2.Zero, 5f * deltaF);
}
}
// Walking on the floor
@ -204,11 +217,13 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
{
velocity.X += Mathf.Sign(_currentDirection.X) * AirAccel * deltaF;
}
var velocityIsTooLarge = Mathf.Abs(velocity.X) > AirMaxSpeed;
if (!velocityWasTooLarge && velocityIsTooLarge)
{
velocity.X = Mathf.Clamp(velocity.X, -AirMaxSpeed, AirMaxSpeed);
}
dragAmount = _currentDirection.IsZeroApprox() ? 0.015f : 0.009f;
}
@ -263,17 +278,17 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
}
}
if (IsOnFloor())
if (IsOnFloor() && !IsInWater)
JumpAllowedTimer.Start();
{
var addedDashPoints = 3f * deltaF;
var addedDashPoints = DashPointRate * deltaF;
if (IsInWater)
{
DashPoints += BankedDashPoints;
BankedDashPoints = 0;
DashPoints = Mathf.Min(MaxDashPoints, DashPoints + addedDashPoints);
}
else BankedDashPoints = Mathf.Min(1, BankedDashPoints + 3f * addedDashPoints);
else BankedDashPoints = Mathf.Min(1f, BankedDashPoints + addedDashPoints);
}
if (IsOnCeiling()) JumpTimer.Stop();
@ -436,6 +451,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
if (Velocity.Y < 0)
Velocity *= new Vector2(1f, 0.1f);
}
if (!WallJumpTimer.IsStopped())
{
WallJumpTimer.Stop();