Prevent movement when escape menu is open

- Add static EscapeMenu.Instance property
main
copygirl 5 years ago
parent 7a5d8ac29e
commit 8c19cf919a
  1. 4
      src/EscapeMenu.cs
  2. 14
      src/LocalPlayer.cs

@ -2,9 +2,13 @@ using Godot;
public class EscapeMenu : Control public class EscapeMenu : Control
{ {
public static EscapeMenu Instance { get; private set; }
[Export] public NodePath ReturnPath { get; set; } [Export] public NodePath ReturnPath { get; set; }
public Button Return { get; private set; } public Button Return { get; private set; }
public EscapeMenu() => Instance = this;
public override void _Ready() public override void _Ready()
{ {
Return = GetNode<Button>(ReturnPath); Return = GetNode<Button>(ReturnPath);

@ -26,16 +26,20 @@ public class LocalPlayer : Player
public override void _PhysicsProcess(float delta) public override void _PhysicsProcess(float delta)
{ {
var moveDir = Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left"); var moveDir = 0.0F;
var jumpPressed = false;
if (!EscapeMenu.Instance.Visible) {
moveDir = Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left");
jumpPressed = Input.IsActionJustPressed("move_jump");
}
Velocity.x = (moveDir != 0) ? Mathf.Lerp(Velocity.x, moveDir * Speed, Acceleration) Velocity.x = (moveDir != 0) ? Mathf.Lerp(Velocity.x, moveDir * Speed, Acceleration)
: Mathf.Lerp(Velocity.x, 0, Friction); : Mathf.Lerp(Velocity.x, 0, Friction);
Velocity.y += Gravity * delta; Velocity.y += Gravity * delta;
Velocity = MoveAndSlide(Velocity, Vector2.Up); Velocity = MoveAndSlide(Velocity, Vector2.Up);
if (Input.IsActionJustPressed("move_jump")) if (jumpPressed) _jumpPressed = DateTime.Now;
_jumpPressed = DateTime.Now; if (IsOnFloor()) _lastOnFloor = DateTime.Now;
if (IsOnFloor())
_lastOnFloor = DateTime.Now;
if (((DateTime.Now - _jumpPressed) <= JumpEarlyTime) && if (((DateTime.Now - _jumpPressed) <= JumpEarlyTime) &&
((DateTime.Now - _lastOnFloor) <= JumpCoyoteTime)) { ((DateTime.Now - _lastOnFloor) <= JumpCoyoteTime)) {

Loading…
Cancel
Save