2023-05-17 06:15:31 +00:00
|
|
|
using Godot;
|
|
|
|
|
2023-05-21 04:42:38 +00:00
|
|
|
namespace Pong.Scripts.Objects;
|
2023-05-17 06:15:31 +00:00
|
|
|
|
|
|
|
public partial class Paddle : RigidBody2D
|
|
|
|
{
|
|
|
|
[Export] private double _moveSpeed;
|
|
|
|
|
|
|
|
private double _verticalInput;
|
|
|
|
|
|
|
|
/// <summary>
|
2023-05-18 06:41:26 +00:00
|
|
|
/// property that multiples the moveSpeed by the <see cref="Constants.Meter">Meter</see> constant.
|
2023-05-17 06:15:31 +00:00
|
|
|
/// </summary>
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// a method that returns a number that represents input on the vertical axis.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>1 for up, -1 for down, 0 for nothing.</returns>
|
|
|
|
private static double GetVerticalInput()
|
|
|
|
{
|
|
|
|
if (Input.IsActionPressed("paddle_up"))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input.IsActionPressed("paddle_down"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|