Pong/Scripts/Managers/Walls.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

42 lines
1 KiB
C#

using Godot;
using Pong.Scripts.Data;
using Pong.Scripts.Objects;
namespace Pong.Scripts.Managers;
public partial class Walls : Area2D
{
[Export] internal PlayerNumber PlayerNumber;
private GodotObject _scoreManager;
private StringName _score = "score";
public override void _Ready()
{
_scoreManager = GetNode<GodotObject>("/root/Pong/Score");
}
/// <summary>
/// code that runs when a ball collides the wall.
/// </summary>
/// <param name="body">the body of the collider.</param>
private void OnBodyEntered(Node2D body)
{
if (body is not Ball ball) return;
_scoreManager.Call(_score, (long)PlayerNumber);
ResetBall(ball);
}
/// <summary>
/// reset the ball to the starting position and flick it again.
/// </summary>
/// <param name="ball">a <see cref="Ball"/> object that you want to reset.</param>
private async void ResetBall(Ball ball)
{
ball.Velocity = Vector2.Zero;
ball.Position = Vector2.Zero;
await ToSignal(GetTree().CreateTimer(0.25), "timeout");
ball.FlickBall();
}
}