mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 00:55:54 +00:00
Disabled navigation
This commit is contained in:
parent
7b8abba100
commit
3681614196
7 changed files with 126 additions and 4 deletions
|
|
@ -56,6 +56,8 @@ BulletScene = ExtResource("2_ogldd")
|
|||
BulletCapacity = 4
|
||||
BulletSpeed = 50.0
|
||||
|
||||
[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||
[connection signal="area_entered" from="PlayerDetection" to="." method="_on_player_detection_area_entered"]
|
||||
[connection signal="area_exited" from="PlayerDetection" to="." method="_on_player_detection_area_exited"]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=28 format=4 uid="uid://bv451a8wgty4u"]
|
||||
[gd_scene load_steps=38 format=4 uid="uid://bv451a8wgty4u"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
|
||||
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_8mh54"]
|
||||
|
|
@ -25,6 +25,66 @@
|
|||
[ext_resource type="PackedScene" uid="uid://dkwi1hu1bixoe" path="res://Scenes/HUD/HUD.tscn" id="22_krk0o"]
|
||||
[ext_resource type="Script" path="res://Scenes/CameraTarget.gd" id="24_0c2yt"]
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_lnwgu"]
|
||||
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
|
||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
|
||||
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
|
||||
agent_radius = 0.0
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_ml1qs"]
|
||||
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
|
||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
|
||||
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
|
||||
agent_radius = 0.0
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_h4p0b"]
|
||||
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
|
||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
|
||||
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
|
||||
agent_radius = 0.0
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_1miy6"]
|
||||
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
|
||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
|
||||
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
|
||||
agent_radius = 0.0
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_uanwu"]
|
||||
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
|
||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
|
||||
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
|
||||
agent_radius = 0.0
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_6t4b1"]
|
||||
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
|
||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
|
||||
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
|
||||
agent_radius = 0.0
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_ajuv4"]
|
||||
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
|
||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
|
||||
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
|
||||
agent_radius = 0.0
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_3ass8"]
|
||||
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
|
||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
|
||||
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
|
||||
agent_radius = 0.0
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_2t186"]
|
||||
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
|
||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
|
||||
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
|
||||
agent_radius = 0.0
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_63d1d"]
|
||||
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
|
||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
|
||||
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
|
||||
agent_radius = 0.0
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_jwf4b"]
|
||||
resource_name = "Factory"
|
||||
texture = ExtResource("8_0km4o")
|
||||
|
|
@ -50,6 +110,7 @@ texture = ExtResource("8_0km4o")
|
|||
5:1/0 = 0
|
||||
5:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
|
||||
6:1/0 = 0
|
||||
6:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_uanwu")
|
||||
7:1/0 = 0
|
||||
8:1/0 = 0
|
||||
9:1/0 = 0
|
||||
|
|
@ -60,13 +121,18 @@ texture = ExtResource("8_0km4o")
|
|||
4:2/0 = 0
|
||||
5:2/0 = 0
|
||||
6:2/0 = 0
|
||||
6:2/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_6t4b1")
|
||||
7:2/0 = 0
|
||||
8:2/0 = 0
|
||||
9:2/0 = 0
|
||||
0:3/0 = 0
|
||||
0:3/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_lnwgu")
|
||||
1:3/0 = 0
|
||||
1:3/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_ml1qs")
|
||||
2:3/0 = 0
|
||||
2:3/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_h4p0b")
|
||||
3:3/0 = 0
|
||||
3:3/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_1miy6")
|
||||
4:3/0 = 0
|
||||
5:3/0 = 0
|
||||
7:3/0 = 0
|
||||
|
|
@ -99,8 +165,11 @@ texture = ExtResource("8_0km4o")
|
|||
5:5/0 = 0
|
||||
5:5/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
|
||||
6:5/0 = 0
|
||||
6:5/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_ajuv4")
|
||||
7:5/0 = 0
|
||||
7:5/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_ajuv4")
|
||||
8:5/0 = 0
|
||||
8:5/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_ajuv4")
|
||||
9:5/0 = 0
|
||||
0:6/0 = 0
|
||||
0:6/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
|
||||
|
|
@ -113,8 +182,10 @@ texture = ExtResource("8_0km4o")
|
|||
5:6/0 = 0
|
||||
5:6/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
|
||||
6:6/0 = 0
|
||||
6:6/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_3ass8")
|
||||
7:6/0 = 0
|
||||
8:6/0 = 0
|
||||
8:6/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_63d1d")
|
||||
9:6/0 = 0
|
||||
0:7/0 = 0
|
||||
0:7/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
|
||||
|
|
@ -127,8 +198,11 @@ texture = ExtResource("8_0km4o")
|
|||
5:7/0 = 0
|
||||
5:7/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
|
||||
6:7/0 = 0
|
||||
6:7/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_2t186")
|
||||
7:7/0 = 0
|
||||
7:7/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_2t186")
|
||||
8:7/0 = 0
|
||||
8:7/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_63d1d")
|
||||
9:7/0 = 0
|
||||
0:8/0 = 0
|
||||
1:8/0 = 0
|
||||
|
|
@ -220,6 +294,7 @@ physics_layer_0/collision_layer = 1
|
|||
physics_layer_0/collision_mask = 30
|
||||
physics_layer_1/collision_layer = 32
|
||||
physics_layer_1/collision_mask = 18
|
||||
navigation_layer_0/layers = 1
|
||||
sources/0 = SubResource("TileSetAtlasSource_jwf4b")
|
||||
sources/1 = SubResource("TileSetScenesCollectionSource_qg3vu")
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -92,7 +92,9 @@ Use={
|
|||
[layer_names]
|
||||
|
||||
2d_physics/layer_1="world"
|
||||
2d_navigation/layer_1="Walkable"
|
||||
2d_physics/layer_2="player"
|
||||
2d_navigation/layer_2="Solid"
|
||||
2d_physics/layer_3="items"
|
||||
2d_physics/layer_4="bullets"
|
||||
2d_physics/layer_5="enemies"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue