using Godot; public partial class PlayZone : Node2D { [Export] public Node2D TopLeftCorner; [Export] public Node2D BottomRightCorner; [Export] public Node2D PlayerSpawnPoint; [Signal] public delegate void ZoneEnteredEventHandler(PlayZone sender); [Signal] public delegate void ZoneLeftEventHandler(PlayZone sender); public Rect2I Bounds = new Rect2I(0, 0, 0, 0); private Area2D _area2D; private CollisionShape2D _collisionShape2D; //private GameManager _gameManager; public override void _Ready() { //_gameManager = (GameManager)GetTree().Root.FindChild("GameManager"); _area2D = (Area2D)FindChild("Area2D"); _collisionShape2D = (CollisionShape2D)FindChild("CollisionShape2D"); var size = BottomRightCorner.Position - TopLeftCorner.Position; Bounds = new Rect2I((int)TopLeftCorner.Position.X, (int)TopLeftCorner.Position.Y, (int)size.X, (int)size.Y); var middle = (BottomRightCorner.Position + TopLeftCorner.Position) / 2; _area2D.Position = middle; _collisionShape2D.Shape = new RectangleShape2D { Size = size }; } private void BodyEntered(Node2D body) { if (body is not Player player) return; EmitSignal(SignalName.ZoneEntered, this); } private void BodyExited(Node2D body) { if (body is not Player player) return; EmitSignal(SignalName.ZoneLeft, this); } }