using Godot;
namespace Pong.Scripts.Nodes;
public partial class Paddle : RigidBody2D
{
[Export] private double _moveSpeed;
private double _verticalInput;
///
/// property that multiples the moveSpeed by the Meter constant.
///
private double MoveSpeed => _moveSpeed * Constants.Meter;
public override void _Process(double delta)
{
_verticalInput = GetVerticalInput();
}
public override void _PhysicsProcess(double delta)
{
LinearVelocity = Vector2.Up * MoveSpeed * _verticalInput;
}
///
/// a method that returns a number that represents input on the vertical axis.
///
/// 1 for up, -1 for down, 0 for nothing.
private static double GetVerticalInput()
{
if (Input.IsActionPressed("paddle_up"))
{
return 1;
}
if (Input.IsActionPressed("paddle_down"))
{
return -1;
}
return 0;
}
}