Fix for phase switch animation

This commit is contained in:
Marco 2025-02-14 09:33:10 +01:00
commit 95979bd3b8
7 changed files with 21 additions and 14 deletions

View file

@ -31,7 +31,9 @@ public partial class Enemy : CharacterBody2D
private bool _isDestroyed = false;
private NavigationAgent2D _navigationAgent;
protected bool _invulnerable = false;
private bool IsPlayerInRange => _playerDetection is { IsPlayerInRange: true };
private bool IsPlayerInSight => _playerDetection is not null && _playerDetection.IsPlayerInSight(CollisionMask);
@ -203,7 +205,9 @@ public partial class Enemy : CharacterBody2D
private void _on_damage_hitbox_area_entered(Area2D area)
{
if (area is not Bullet bullet) return;
GD.Print("Enemy Received damage");
if (_invulnerable) return;
if (bullet.BulletInfo.Owner == BulletOwner.Enemy) return;
this.Hit(bullet.Damage);
bullet.QueueFree();
}
@ -225,9 +229,10 @@ public partial class Enemy : CharacterBody2D
public void Hit(float damage)
{
if (_isDestroyed) return;
if (_invulnerable) return;
_currentHealth -= damage;
EmitSignal(nameof(HealthChanged), _currentHealth);
EmitSignal(SignalName.HealthChanged, _currentHealth);
if (!(_currentHealth <= 0)) return;
_isDestroyed = true;
Explode();