using Godot;
namespace Pong.Scripts.Managers;
public partial class WallManager : Area2D
{
public override void _Ready()
{
BodyEntered += OnBodyEntered;
}
private void OnBodyEntered(Node2D body)
{
if (body is not Nodes.Ball ball) return;
ResetBall(ball);
}
///
/// reset the ball to the starting position and flick it again.
///
/// a object that you want to reset.
private async void ResetBall(Nodes.Ball ball)
{
ball.Velocity = Vector2.Zero;
ball.Position = Vector2.Zero;
await ToSignal(GetTree().CreateTimer(0.25), "timeout");
ball.FlickBall();
}
}