mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:55:35 +00:00
Navigation and shooting modules
This commit is contained in:
parent
ef6c240e8e
commit
5a6d31e2f0
8 changed files with 229 additions and 11 deletions
|
|
@ -17,12 +17,16 @@ public partial class Alert : EnemyStateBase
|
|||
[Export]
|
||||
public GenericDamageReceiver DamageReceiver { get; private set; }
|
||||
|
||||
[Export]
|
||||
public NavigationMovementModule NavigationModule { get; private set; }
|
||||
|
||||
private bool _isPlayerInRange = false;
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
base.EnterState();
|
||||
GD.Print("Entered Idle");
|
||||
GD.Print($"Entered {Name}");
|
||||
NavigationModule.Init(MainObject);
|
||||
PlayerDetection.SetRange(StorageModule.Root.EnemyResource.PlayerDetectionRange);
|
||||
|
||||
_isPlayerInRange = PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.PlayerDetectionRange);
|
||||
|
|
@ -52,14 +56,14 @@ public partial class Alert : EnemyStateBase
|
|||
public override void ExitState()
|
||||
{
|
||||
base.ExitState();
|
||||
GD.Print("Exited Idle");
|
||||
GD.Print($"Exited {Name}");
|
||||
PlayerDetection.PlayerInRange -= PlayerDetectionOnPlayerInRange;
|
||||
|
||||
PlayerDetection.PlayerOutOfRange -= PlayerDetectionOnPlayerOutOfRange;
|
||||
|
||||
DamageReceiver.HealthProvider.ResourceDepleted -= HealthProviderOnResourceDepleted;
|
||||
DamageReceiver.ChangeState(false);
|
||||
|
||||
NavigationModule.SetTarget(null);
|
||||
}
|
||||
|
||||
private void PlayerDetectionOnPlayerInRange()
|
||||
|
|
@ -73,6 +77,7 @@ public partial class Alert : EnemyStateBase
|
|||
base.PhysicsProcessState(delta);
|
||||
if (_isPlayerInRange && PlayerDetection.IsPlayerInSight())
|
||||
{
|
||||
GD.Print("Player is in sight, shooting");
|
||||
StateMachine.SetState(EnemyState.Shooting);
|
||||
return;
|
||||
}
|
||||
|
|
@ -81,7 +86,9 @@ public partial class Alert : EnemyStateBase
|
|||
if (this.GlobalPosition.DistanceTo(GameManager.Instance.PlayerPosition.Value) >=
|
||||
StorageModule.Root.EnemyResource.PlayerDisengageRange)
|
||||
{
|
||||
GD.Print("Player is out of sight, idling");
|
||||
StateMachine.SetState(EnemyState.Idle);
|
||||
return;
|
||||
}
|
||||
|
||||
// Move towards last known position
|
||||
|
|
@ -90,12 +97,12 @@ public partial class Alert : EnemyStateBase
|
|||
MoveTowardsPosition(PlayerDetection.LastKnownPlayerPosition.Value);
|
||||
}
|
||||
|
||||
|
||||
NavigationModule.Move();
|
||||
}
|
||||
|
||||
private void MoveTowardsPosition(Vector2 position)
|
||||
{
|
||||
|
||||
NavigationModule.SetTarget(position);
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue