Files

38 lines
849 B
C#

using System;
using Godot;
public partial class Enemy : PathFollow2D
{
[Export] public EnemyType Type;
[Export] public Health Health;
[Export] private AudioStreamPlayer2D _audio;
public event Action<Enemy> Died;
public event Action<Enemy> ReachedShrine;
public override void _Ready()
{
Health.Death += _ => Died?.Invoke(this);
Health.Damaged += () =>
{
_audio?.SetPitchScale(RandomHelper.Float(0.8f, 1.2f));
_audio?.Play();
};
}
public void ResetEnemy()
{
GlobalPosition = Vector2.Zero;
Rotation = 0f;
Visible = true;
ProcessMode = ProcessModeEnum.Inherit;
Health.Reset();
// reset velocity, animation, AI, etc here
}
public void Despawn()
{
ReachedShrine?.Invoke(this);
}
}