|
|
|
|
@ -12,42 +12,76 @@ public partial class InputManager : Node
|
|
|
|
|
private const string PLAYER_MOVE_RIGHT = "Player_Move_Right";
|
|
|
|
|
private const string PLAYER_FIRE = "Player_Fire";
|
|
|
|
|
|
|
|
|
|
private Vector3 moveDirection;
|
|
|
|
|
private Vector3 rotationDirection;
|
|
|
|
|
|
|
|
|
|
private float speed;
|
|
|
|
|
private Vector3 moveDirection = Vector3.Zero;
|
|
|
|
|
private Vector3 rotationDirection = Vector3.Zero;
|
|
|
|
|
|
|
|
|
|
public event EventHandler StartCountdown;
|
|
|
|
|
|
|
|
|
|
public static InputManager Instance { get; private set; }
|
|
|
|
|
|
|
|
|
|
public override void _Ready() => Instance = this;
|
|
|
|
|
|
|
|
|
|
public override void _UnhandledInput(InputEvent @event) {
|
|
|
|
|
public override void _Input(InputEvent @event) {
|
|
|
|
|
float acceleration = PlayerShip.Instance.Acceleration;
|
|
|
|
|
|
|
|
|
|
//Countdown
|
|
|
|
|
if (GameManager.Instance.Countdown && Input.IsAnythingPressed()) StartCountdown?.Invoke(this,EventArgs.Empty);
|
|
|
|
|
|
|
|
|
|
//Pause
|
|
|
|
|
if (Input.IsActionJustReleased(GAME_PAUSE)) GameManager.Instance.GamePaused = GameManager.Instance.GamePaused switch { true => false, false => true };
|
|
|
|
|
|
|
|
|
|
if (GameManager.Instance.GamePaused || GameManager.Instance.Countdown || GameManager.Instance.GameOver) return;
|
|
|
|
|
|
|
|
|
|
//Movement
|
|
|
|
|
float moveVelocity = PlayerShip.Instance.MoveVelocity;
|
|
|
|
|
float rotationVelocity = PlayerShip.Instance.RotationVelocity;
|
|
|
|
|
if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) {
|
|
|
|
|
moveDirection.Z = -1;
|
|
|
|
|
speed += acceleration;
|
|
|
|
|
rotationDirection.X = -1;
|
|
|
|
|
}
|
|
|
|
|
if (Input.IsActionJustReleased(PLAYER_MOVE_FORWARD)) {
|
|
|
|
|
moveDirection.Z = 0f;
|
|
|
|
|
rotationDirection.X = 0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moveDirection = Vector3.Zero;
|
|
|
|
|
rotationDirection = Vector3.Zero;
|
|
|
|
|
|
|
|
|
|
if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) moveDirection.Z = -moveVelocity;
|
|
|
|
|
if (Input.IsActionJustPressed(PLAYER_MOVE_FORWARD)) rotationDirection.X = -rotationVelocity;
|
|
|
|
|
if (Input.IsActionPressed(PLAYER_MOVE_BACKWARDS)) moveDirection.Z = +moveVelocity;
|
|
|
|
|
if (Input.IsActionJustPressed(PLAYER_MOVE_BACKWARDS)) rotationDirection.X = +rotationVelocity;
|
|
|
|
|
if (Input.IsActionPressed(PLAYER_MOVE_LEFT)) moveDirection.X = -moveVelocity;
|
|
|
|
|
if (Input.IsActionJustPressed(PLAYER_MOVE_LEFT)) rotationDirection.Z = -rotationVelocity * 2;
|
|
|
|
|
if (Input.IsActionPressed(PLAYER_MOVE_RIGHT)) moveDirection.X = moveVelocity;
|
|
|
|
|
if (Input.IsActionJustPressed(PLAYER_MOVE_RIGHT)) rotationDirection.Z = +rotationVelocity * 2;
|
|
|
|
|
if (Input.IsActionJustReleased(PLAYER_MOVE_LEFT) || Input.IsActionJustReleased(PLAYER_MOVE_RIGHT)) rotationDirection = Vector3.Zero;
|
|
|
|
|
|
|
|
|
|
PlayerShip.Instance.MoveDirection = moveDirection;
|
|
|
|
|
PlayerShip.Instance.RotationDirection = rotationDirection;
|
|
|
|
|
if (Input.IsActionPressed(PLAYER_MOVE_BACKWARDS)) {
|
|
|
|
|
moveDirection.Z = 1;
|
|
|
|
|
speed += acceleration;
|
|
|
|
|
rotationDirection.X = 1;
|
|
|
|
|
}
|
|
|
|
|
if (Input.IsActionJustReleased(PLAYER_MOVE_BACKWARDS)) {
|
|
|
|
|
moveDirection.Z = 0f;
|
|
|
|
|
rotationDirection.X = 0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.IsActionPressed(PLAYER_MOVE_LEFT)) {
|
|
|
|
|
moveDirection.X = -1;
|
|
|
|
|
speed += acceleration;
|
|
|
|
|
rotationDirection.Z = -1;
|
|
|
|
|
}
|
|
|
|
|
if (Input.IsActionJustReleased(PLAYER_MOVE_LEFT)) {
|
|
|
|
|
moveDirection.X = 0f;
|
|
|
|
|
rotationDirection.Z = 0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.IsActionPressed(PLAYER_MOVE_RIGHT)) {
|
|
|
|
|
moveDirection.X = 1;
|
|
|
|
|
speed += acceleration;
|
|
|
|
|
rotationDirection.Z = 1;
|
|
|
|
|
}
|
|
|
|
|
if (Input.IsActionJustReleased(PLAYER_MOVE_RIGHT)) {
|
|
|
|
|
moveDirection.X = 0f;
|
|
|
|
|
rotationDirection.Z = 0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (Input.IsActionJustReleased(PLAYER_MOVE_FORWARD) || Input.IsActionJustReleased(PLAYER_MOVE_BACKWARDS) || Input.IsActionJustReleased(PLAYER_MOVE_LEFT) || Input.IsActionJustReleased(PLAYER_MOVE_RIGHT)) {
|
|
|
|
|
// moveDirection = Vector3.Zero;
|
|
|
|
|
// rotationDirection = Vector3.Zero;
|
|
|
|
|
// speed = 0f;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
PlayerShip.Instance.MoveDirection = moveDirection.Normalized();
|
|
|
|
|
PlayerShip.Instance.RotationDirection = rotationDirection.Normalized();
|
|
|
|
|
PlayerShip.Instance.Speed = speed;
|
|
|
|
|
|
|
|
|
|
//Shooting
|
|
|
|
|
if (Input.IsActionJustPressed(PLAYER_FIRE)) PlayerShip.Instance.Shooting = true;
|
|
|
|
|
|