Pong/Scripts/Objects/Paddle.cs
Fries 425bf2ad27 make a settings menu and general refactoring
i added more to the main menu, as it has a settings menu now, that stores its files with json. i also changed the font to atkinson hyperlegible and made a BaseMenu class that takes care of the screen scaling for menus.

i also refactored the project folder structure to make it more organized.
2023-05-20 21:42:38 -07:00

44 lines
931 B
C#

using Godot;
namespace Pong.Scripts.Objects;
public partial class Paddle : RigidBody2D
{
[Export] private double _moveSpeed;
private double _verticalInput;
/// <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 static double GetVerticalInput()
{
if (Input.IsActionPressed("paddle_up"))
{
return 1;
}
if (Input.IsActionPressed("paddle_down"))
{
return -1;
}
return 0;
}
}