30 lines
655 B
C#
30 lines
655 B
C#
|
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);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// reset the ball to the starting position and flick it again.
|
||
|
/// </summary>
|
||
|
/// <param name="ball">a <see cref="Nodes.Ball"/> object that you want to reset.</param>
|
||
|
private async void ResetBall(Nodes.Ball ball)
|
||
|
{
|
||
|
ball.Velocity = Vector2.Zero;
|
||
|
ball.Position = Vector2.Zero;
|
||
|
await ToSignal(GetTree().CreateTimer(0.25), "timeout");
|
||
|
ball.FlickBall();
|
||
|
}
|
||
|
}
|