mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 18:15:53 +00:00
Disabled navigation
This commit is contained in:
parent
7b8abba100
commit
3681614196
7 changed files with 126 additions and 4 deletions
|
|
@ -10,19 +10,33 @@ public partial class Enemy : Area2D, IDestructible
|
|||
|
||||
[Export] public float Health = 4f;
|
||||
|
||||
[Export] public float WalkSpeed = 2500f;
|
||||
|
||||
[Export] public Weapon EquippedWeapon;
|
||||
|
||||
private float _currentHealth = 0f;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
private NavigationAgent2D _navigationAgent;
|
||||
|
||||
[Export] public bool NavigationEnabled { get; set; } = false;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_currentHealth = Health;
|
||||
|
||||
_navigationAgent = GetNode<NavigationAgent2D>("NavigationAgent2D");
|
||||
|
||||
CallDeferred("Setup");
|
||||
}
|
||||
|
||||
private void Setup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
|
@ -48,6 +62,18 @@ public partial class Enemy : Area2D, IDestructible
|
|||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
HandlePlayerDetection();
|
||||
if (NavigationEnabled)
|
||||
{
|
||||
var moveLocation = _navigationAgent.GetNextPathPosition();
|
||||
|
||||
if (_currentState is EnemyState.Primed)
|
||||
{
|
||||
this.Position = moveLocation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void HandlePlayerDetection()
|
||||
|
|
@ -59,7 +85,14 @@ public partial class Enemy : Area2D, IDestructible
|
|||
|
||||
if (IsPlayerInSight())
|
||||
{
|
||||
// Update player position only if player is in sight
|
||||
if (NavigationEnabled)
|
||||
{
|
||||
_navigationAgent.SetTargetPosition(_cachedPlayer.GlobalPosition);
|
||||
}
|
||||
Shoot();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -161,6 +194,7 @@ public partial class Enemy : Area2D, IDestructible
|
|||
private enum EnemyState
|
||||
{
|
||||
Idle,
|
||||
Primed
|
||||
Primed,
|
||||
Patrolling
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,19 @@ public partial class GameManager : Node2D
|
|||
[Export]
|
||||
public Marker2D PlayerSpawnMarker { get; set; }
|
||||
|
||||
|
||||
private InventoryManager _inventoryManager { get; set; }
|
||||
|
||||
public InventoryManager Inventory => _inventoryManager;
|
||||
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_hud = GetNode<Hud>("HUD");
|
||||
_cameraTarget = GetNode<Node2D>("CameraTarget");
|
||||
|
||||
_inventoryManager = GetNode<InventoryManager>("InventoryManager");
|
||||
|
||||
if (PlayerSpawnMarker != null)
|
||||
{
|
||||
SpawnPlayer();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ using System;
|
|||
|
||||
public partial class InventoryManager : Node2D
|
||||
{
|
||||
|
||||
public bool RedKeycard { get; set; }
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
//private InventoryManager _inventoryManager;
|
||||
|
||||
public override void _Ready()
|
||||
|
|
@ -52,6 +54,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
_movementDirection = Vector2.Zero;
|
||||
_facingDirection = Vector2.Zero;
|
||||
|
||||
_gameManager = GetNode<GameManager>("/root/GameScene");
|
||||
|
||||
if (SelectorScene != null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue