diff --git a/scenes/enemies/Enemy.cs b/scenes/enemies/Enemy.cs index 5a3c614..ba9be87 100644 --- a/scenes/enemies/Enemy.cs +++ b/scenes/enemies/Enemy.cs @@ -6,14 +6,29 @@ public class Enemy : KinematicBody2D [Export] private Vector2 _startPosition; public Vector2 StartPosition { get { return _startPosition; } } + private Event _event; public override void _Ready() { + _event = GetNode("/root/Event"); _startPosition = Position; } public virtual void Reset() { - Position = _startPosition; + // Shove him off screen somewhere until we can respawn him + Position = new Vector2(-100, - 100); + _event.Connect("CameraView", this, "OnCameraView"); + } + + public void OnCameraView(Rect2 rect) + { + rect.Size += new Vector2(32, 32); + if (!rect.HasPoint(StartPosition)) + { + // We can respawn him because the player is not in the spawn point + _event.Disconnect("CameraView", this, "OnCameraView"); + Position = StartPosition; + } } }