added basic out of water jump

This commit is contained in:
Lilith Schier 2026-07-14 15:48:28 +02:00
parent 0e68f347d6
commit 003cc7c589

View file

@ -66,14 +66,17 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
public float JumpAscentRemainingTime { get; private set; }
public bool IsJumping { get; private set; }
public float JumpAllowedTime { get; private set; }
/// The direction the player is currently holding.
/// This vectors components should always be -1/0/1.
private Vector2 _currentDirection = Vector2.Zero;
private bool _isFacingRight = true;
private AnimationNodeStateMachinePlayback _playback = null!;
private List<BufferedInput> _inputBuffer = [];
private bool _isInWater;
private float PlatformIgnoreTime { get; set; }
private float WaterJumpAllowedTime { get; set; }
[Node] private AnimationTree AnimationTree { get; set; } = null!;
[Node] private Area2D SubmersedSensor { get; set; } = null!;
@ -199,6 +202,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
if (IsOnFloor())
JumpAllowedTime = LateJumpTimeLimit;
WaterJumpAllowedTime = Mathf.Max(0, WaterJumpAllowedTime - deltaF);
if (IsOnCeiling())
{
IsJumping = false;
@ -206,18 +211,13 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
}
}
public void EnteredWater(Node2D body)
{
if (_isInWater) return;
_isInWater = true;
GD.Print("Entered water!");
}
public void EnteredWater(Node2D body) => _isInWater = true;
public void LeftWater(Node2D body)
{
if (!_isInWater || SubmersedSensor.HasOverlappingBodies()) return;
GD.Print("Left water!");
_isInWater = false;
WaterJumpAllowedTime = LateJumpTimeLimit;
}
private void AdjustFacing()
@ -271,7 +271,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
else if (
input.Event.IsPressed()
&& JumpAllowedTime > 0
&& (!IsOnFloor() || input.Direction.Y <= 0))
&& (!IsOnFloor() || input.Direction.Y <= 0)
&& !_isInWater)
{
inputFound = true;
GroundJump();
@ -281,6 +282,11 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
inputFound = true;
WallJump();
}
else if (input.Event.IsPressed() && WaterJumpAllowedTime > 0)
{
inputFound = true;
WaterExitJump();
}
else if (input.Event.IsReleased() && IsJumping)
{
JumpCut();
@ -337,14 +343,12 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
_playback.Travel("front_kick");
}
private bool IsAtWaterSurface()
{
throw new NotImplementedException();
}
private void WaterExitJump()
{
throw new NotImplementedException();
AdjustFacing();
JumpAllowedTime = 0.0f;
JumpAscentRemainingTime = JumpAscentMaxTime * 1.5f;
IsJumping = true;
}
private static Vector2 To8DirectionVector(Vector2 input)