Pong/Scripts/Objects/Paddle.cs
Fries 7bae1587d2 add a scene wide scaling manager.
this is so i can scale all the objects to the proper positions and scales when the resolution changes.
2023-05-22 10:41:56 -07:00

44 lines
1,017 B
C#

namespace Pong.Scripts.Objects;
public partial class Paddle : RigidBody2D
{
[Export] private double _moveSpeed;
private double _verticalInput;
private readonly StringName _paddleUp = "paddle_up";
private readonly StringName _paddleDown = "paddle_down";
/// <summary>
/// property that multiples the moveSpeed by the <see cref="Constants.Meter">Meter</see> constant.
/// </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 double GetVerticalInput()
{
if (Input.IsActionPressed(_paddleUp))
{
return 1;
}
if (Input.IsActionPressed(_paddleDown))
{
return -1;
}
return 0;
}
}