2022-11-21 00:42:55 -03:00
|
|
|
using Godot;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
public class Enemy : KinematicBody2D
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
private Vector2 _startPosition;
|
|
|
|
public Vector2 StartPosition { get { return _startPosition; } }
|
2022-11-21 01:43:45 -03:00
|
|
|
private Event _event;
|
2022-11-21 00:42:55 -03:00
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
2022-11-21 01:43:45 -03:00
|
|
|
_event = GetNode<Event>("/root/Event");
|
2022-11-21 00:42:55 -03:00
|
|
|
_startPosition = Position;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void Reset()
|
|
|
|
{
|
2022-11-21 01:43:45 -03:00
|
|
|
// 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;
|
|
|
|
}
|
2022-11-21 00:42:55 -03:00
|
|
|
}
|
|
|
|
}
|