36 lines
982 B
C#
36 lines
982 B
C#
using Godot;
|
|
|
|
namespace Mr.BrickAdventures.scripts.components;
|
|
|
|
[GlobalClass]
|
|
public partial class DoubleJumpAbility : MovementAbility
|
|
{
|
|
[Export] public float JumpHeight { get; set; } = 100f;
|
|
[Export] public float JumpTimeToPeak { get; set; } = 0.5f;
|
|
|
|
private bool _hasDoubleJumped = false;
|
|
private float _jumpVelocity;
|
|
|
|
public override void Initialize(PlayerController controller)
|
|
{
|
|
base.Initialize(controller);
|
|
_jumpVelocity = (2.0f * JumpHeight) / JumpTimeToPeak * -1.0f;
|
|
}
|
|
|
|
public override Vector2 ProcessMovement(Vector2 velocity, double delta)
|
|
{
|
|
if (_body.IsOnFloor())
|
|
{
|
|
_hasDoubleJumped = false;
|
|
}
|
|
|
|
if (_input.JumpPressed && !_body.IsOnFloor() && !_hasDoubleJumped)
|
|
{
|
|
velocity.Y = _jumpVelocity;
|
|
_controller.EmitSignal(PlayerController.SignalName.JumpInitiated);
|
|
_hasDoubleJumped = true;
|
|
}
|
|
|
|
return velocity;
|
|
}
|
|
} |