using Godot; using Pong.Scripts.Data; namespace Pong.Scripts.Managers; public partial class WallManager : Area2D { [Export] internal PlayerNumber PlayerNumber; private GodotObject _scoreManager; private StringName _score = "score"; public override void _Ready() { _scoreManager = GetNode("/root/Pong/Score"); } /// /// code that runs when a ball collides the wall. /// /// the body of the collider. private void OnBodyEntered(Node2D body) { if (body is not Nodes.Ball ball) return; _scoreManager.Call(_score, (long)PlayerNumber); 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(); } }