diff --git a/DungeonShooting_Godot/prefab/role/Enemy.tscn b/DungeonShooting_Godot/prefab/role/Enemy.tscn index 39588f5..e074e72 100644 --- a/DungeonShooting_Godot/prefab/role/Enemy.tscn +++ b/DungeonShooting_Godot/prefab/role/Enemy.tscn @@ -24,7 +24,7 @@ [node name="AnimatedSprite" parent="." index="2"] material = SubResource( 2 ) -frame = 1 +frame = 0 [node name="Collision" parent="." index="3"] position = Vector2( 0, -8 ) @@ -36,5 +36,4 @@ position = Vector2( 0, -5 ) [node name="NavigationAgent2D" type="NavigationAgent2D" parent="NavigationPoint" index="0"] -avoidance_enabled = true radius = 20.0 diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn index 5786938..7154560 100644 --- a/DungeonShooting_Godot/prefab/role/Player.tscn +++ b/DungeonShooting_Godot/prefab/role/Player.tscn @@ -24,4 +24,4 @@ [node name="AnimatedSprite" parent="." index="2"] material = SubResource( 2 ) -frame = 2 +frame = 1 diff --git a/DungeonShooting_Godot/prefab/role/Role.tscn b/DungeonShooting_Godot/prefab/role/Role.tscn index ab7fba1..37fe18d 100644 --- a/DungeonShooting_Godot/prefab/role/Role.tscn +++ b/DungeonShooting_Godot/prefab/role/Role.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=2] +[gd_scene load_steps=24 format=2] [ext_resource path="res://resource/materlal/Blend.tres" type="Material" id=1] [ext_resource path="res://addons/dungeonShooting_plugin/ActivityObjectTemplate.cs" type="Script" id=2] @@ -80,6 +80,9 @@ "speed": 10.0 } ] +[sub_resource type="CircleShape2D" id=34] +radius = 7.00446 + [sub_resource type="RectangleShape2D" id=16] extents = Vector2( 5, 8.25 ) @@ -99,11 +102,12 @@ position = Vector2( 0, -12 ) frames = SubResource( 6 ) animation = "idle" +frame = 3 playing = true [node name="Collision" type="CollisionShape2D" parent="."] position = Vector2( 0, -7.75 ) -shape = SubResource( 16 ) +shape = SubResource( 34 ) [node name="InteractiveArea" type="Area2D" parent="."] visible = false diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiLeaveForState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiLeaveForState.cs index 23cce4e..8d11412 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiLeaveForState.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiLeaveForState.cs @@ -42,14 +42,17 @@ { _navigationUpdateTimer -= delta; } - - //计算移动 - var nextPos = Master.NavigationAgent2D.GetNextLocation(); - Master.LookTargetPosition(Enemy.FindTargetPosition); - Master.AnimatedSprite.Animation = AnimatorNames.Run; - Master.Velocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * - Master.MoveSpeed; - Master.CalcMove(delta); + + if (!Master.NavigationAgent2D.IsNavigationFinished()) + { + //计算移动 + var nextPos = Master.NavigationAgent2D.GetNextLocation(); + Master.LookTargetPosition(Enemy.FindTargetPosition); + Master.AnimatedSprite.Animation = AnimatorNames.Run; + Master.Velocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * + Master.MoveSpeed; + Master.CalcMove(delta); + } var playerPos = GameApplication.Instance.Room.Player.GetCenterPosition(); //检测玩家是否在视野内, 如果在, 则切换到 AiTargetInView 状态 diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs index 5e140d3..fa04edb 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs @@ -48,13 +48,16 @@ _navigationUpdateTimer -= delta; } - //计算移动 - var nextPos = Master.NavigationAgent2D.GetNextLocation(); - Master.LookTargetPosition(playerPos); - Master.AnimatedSprite.Animation = AnimatorNames.Run; - Master.Velocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * Master.MoveSpeed; - Master.CalcMove(delta); - + if (!Master.NavigationAgent2D.IsNavigationFinished()) + { + //计算移动 + var nextPos = Master.NavigationAgent2D.GetNextLocation(); + Master.LookTargetPosition(playerPos); + Master.AnimatedSprite.Animation = AnimatorNames.Run; + Master.Velocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * + Master.MoveSpeed; + Master.CalcMove(delta); + } //检测玩家是否在视野内, 如果在, 则切换到 AiTargetInView 状态 if (Master.IsInTailAfterViewRange(playerPos)) { diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiTargetInViewState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiTargetInViewState.cs index 1856869..d468ca3 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiTargetInViewState.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiTargetInViewState.cs @@ -44,14 +44,17 @@ { _navigationUpdateTimer -= delta; } - - //计算移动 - var nextPos = Master.NavigationAgent2D.GetNextLocation(); - Master.LookTargetPosition(playerPos); - Master.AnimatedSprite.Animation = AnimatorNames.Run; - Master.Velocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * Master.MoveSpeed; - Master.CalcMove(delta); - + + if (!Master.NavigationAgent2D.IsNavigationFinished()) + { + //计算移动 + var nextPos = Master.NavigationAgent2D.GetNextLocation(); + Master.LookTargetPosition(playerPos); + Master.AnimatedSprite.Animation = AnimatorNames.Run; + Master.Velocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * Master.MoveSpeed; + Master.CalcMove(delta); + } + //检测玩家是否在视野内 if (Master.IsInTailAfterViewRange(playerPos)) { diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index 8fca170..b663e06 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -84,6 +84,15 @@ enemy1.PutDown(new Vector2(150, 300)); enemy1.PickUpWeapon(WeaponManager.GetGun("1003")); enemy1.PickUpWeapon(WeaponManager.GetGun("1001")); + + // for (int i = 0; i < 10; i++) + // { + // var enemyTemp = new Enemy(); + // enemyTemp.Name = "EnemyTemp" + i; + // enemyTemp.PutDown(new Vector2(150 + (i + 1) * 20, 300)); + // enemyTemp.PickUpWeapon(WeaponManager.GetGun("1003")); + // enemyTemp.PickUpWeapon(WeaponManager.GetGun("1001")); + // } var enemy2 = new Enemy(); enemy2.Name = "Enemy2";