mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-07-02 10:41:15 +00:00
Enemies react to alarm
This commit is contained in:
parent
88fd702cea
commit
1d24be6156
1 changed files with 18 additions and 1 deletions
|
|
@ -16,6 +16,8 @@ public partial class Enemy : CharacterBody2D
|
||||||
|
|
||||||
[Export] public float PlayerDisengageRange = 500f;
|
[Export] public float PlayerDisengageRange = 500f;
|
||||||
|
|
||||||
|
[Export] public float AlarmReactRange = 200f;
|
||||||
|
|
||||||
[Export] public Weapon EquippedWeapon;
|
[Export] public Weapon EquippedWeapon;
|
||||||
|
|
||||||
private float _currentHealth = 0f;
|
private float _currentHealth = 0f;
|
||||||
|
|
@ -36,6 +38,7 @@ public partial class Enemy : CharacterBody2D
|
||||||
[Export]
|
[Export]
|
||||||
private bool _navigationEnabled = false;
|
private bool _navigationEnabled = false;
|
||||||
|
|
||||||
|
private AlarmManager _alarmManager;
|
||||||
public bool NavigationEnabled
|
public bool NavigationEnabled
|
||||||
{
|
{
|
||||||
get => _navigationEnabled && _navigationAgent != null;
|
get => _navigationEnabled && _navigationAgent != null;
|
||||||
|
|
@ -48,6 +51,20 @@ public partial class Enemy : CharacterBody2D
|
||||||
_currentHealth = Health;
|
_currentHealth = Health;
|
||||||
|
|
||||||
_navigationAgent = GetNodeOrNull<NavigationAgent2D>("NavigationAgent2D");
|
_navigationAgent = GetNodeOrNull<NavigationAgent2D>("NavigationAgent2D");
|
||||||
|
|
||||||
|
_alarmManager = GetNode<AlarmManager>("/root/GameScene/AlarmManager");
|
||||||
|
|
||||||
|
_alarmManager.AlarmEnabled += AlarmManagerOnAlarmEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AlarmManagerOnAlarmEnabled(Vector2 location)
|
||||||
|
{
|
||||||
|
if (NavigationEnabled && location.DistanceTo(this.GlobalPosition) <= AlarmReactRange)
|
||||||
|
{
|
||||||
|
GD.Print($"Enemy {Name} alerted");
|
||||||
|
this._currentState = EnemyState.Alert;
|
||||||
|
_lastPlayerPosition = location;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue