diff --git a/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs b/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs index 6d30caa..720a970 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs @@ -70,9 +70,9 @@ //PathSign = new PathSign(this, PathSignLength, GameApplication.Instance.Room.Player); //注册Ai状态机 - StateController.Register(new AiNormalStateBase()); - StateController.Register(new AiProbeStateBase()); - StateController.Register(new AiTailAfterStateBase()); + StateController.Register(new AiNormalState()); + StateController.Register(new AiProbeState()); + StateController.Register(new AiTailAfterState()); } public override void _Ready() diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiNormalState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiNormalState.cs new file mode 100644 index 0000000..6939a45 --- /dev/null +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiNormalState.cs @@ -0,0 +1,26 @@ + +using Godot; + +/// <summary> +/// AI 正常状态 +/// </summary> +public class AiNormalState : StateBase<Enemy, AIStateEnum> +{ + public AiNormalState() : base(AIStateEnum.AINormal) + { + } + + public override void PhysicsProcess(float delta) + { + //检测玩家 + var player = GameApplication.Instance.Room.Player; + //玩家中心点坐标 + var playerPos = player.MountPoint.GlobalPosition; + + if (Master.IsInViewRange(playerPos) && Master.TestViewRayCast(playerPos) == null) + { + //发现玩家 + StateController.ChangeStateLate(AIStateEnum.AITailAfter); + } + } +} diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiNormalStateBase.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiNormalStateBase.cs deleted file mode 100644 index 65a3148..0000000 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiNormalStateBase.cs +++ /dev/null @@ -1,26 +0,0 @@ - -using Godot; - -/// <summary> -/// AI 正常状态 -/// </summary> -public class AiNormalStateBase : StateBase<Enemy, AIStateEnum> -{ - public AiNormalStateBase() : base(AIStateEnum.AINormal) - { - } - - public override void PhysicsProcess(float delta) - { - //检测玩家 - var player = GameApplication.Instance.Room.Player; - //玩家中心点坐标 - var playerPos = player.MountPoint.GlobalPosition; - - if (Master.IsInViewRange(playerPos) && Master.TestViewRayCast(playerPos) == null) - { - //发现玩家 - StateController.ChangeStateLate(AIStateEnum.AITailAfter); - } - } -} diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiProbeState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiProbeState.cs new file mode 100644 index 0000000..4b1d6ca --- /dev/null +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiProbeState.cs @@ -0,0 +1,10 @@ + +/// <summary> +/// Ai 不确定玩家位置 +/// </summary> +public class AiProbeState : StateBase<Enemy, AIStateEnum> +{ + public AiProbeState() : base(AIStateEnum.AIProbe) + { + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiProbeStateBase.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiProbeStateBase.cs deleted file mode 100644 index be9854d..0000000 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiProbeStateBase.cs +++ /dev/null @@ -1,10 +0,0 @@ - -/// <summary> -/// Ai 不确定玩家位置 -/// </summary> -public class AiProbeStateBase : StateBase<Enemy, AIStateEnum> -{ - public AiProbeStateBase() : base(AIStateEnum.AIProbe) - { - } -} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs new file mode 100644 index 0000000..5fe44e0 --- /dev/null +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs @@ -0,0 +1,43 @@ + +/// <summary> +/// AI 发现玩家 +/// </summary> +public class AiTailAfterState : StateBase<Enemy, AIStateEnum> +{ + + private float _navigationUpdateTimer = 0; + + public AiTailAfterState() : base(AIStateEnum.AITailAfter) + { + } + + public override void PhysicsProcess(float delta) + { + //跟随玩家 + var master = Master; + if (master.NavigationAgent2D.IsNavigationFinished()) + { + return; + } + var playerGlobalPosition = GameApplication.Instance.Room.Player.GlobalPosition; + //临时处理, 让敌人跟随玩家 + if (_navigationUpdateTimer <= 0) + { + _navigationUpdateTimer = 0.2f; + if (master.NavigationAgent2D.GetTargetLocation() != playerGlobalPosition) + { + master.NavigationAgent2D.SetTargetLocation(playerGlobalPosition); + } + } + else + { + _navigationUpdateTimer -= delta; + } + + var nextPos = master.NavigationAgent2D.GetNextLocation(); + master.LookTargetPosition(playerGlobalPosition); + master.AnimatedSprite.Animation = AnimatorNames.Run; + master.Velocity = (nextPos - master.GlobalPosition - master.NavigationPoint.Position).Normalized() * master.MoveSpeed; + master.CalcMove(delta); + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterStateBase.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterStateBase.cs deleted file mode 100644 index 725bf8e..0000000 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterStateBase.cs +++ /dev/null @@ -1,43 +0,0 @@ - -/// <summary> -/// AI 发现玩家 -/// </summary> -public class AiTailAfterStateBase : StateBase<Enemy, AIStateEnum> -{ - - private float _navigationUpdateTimer = 0; - - public AiTailAfterStateBase() : base(AIStateEnum.AITailAfter) - { - } - - public override void PhysicsProcess(float delta) - { - //跟随玩家 - var master = Master; - if (master.NavigationAgent2D.IsNavigationFinished()) - { - return; - } - var playerGlobalPosition = GameApplication.Instance.Room.Player.GlobalPosition; - //临时处理, 让敌人跟随玩家 - if (_navigationUpdateTimer <= 0) - { - _navigationUpdateTimer = 0.2f; - if (master.NavigationAgent2D.GetTargetLocation() != playerGlobalPosition) - { - master.NavigationAgent2D.SetTargetLocation(playerGlobalPosition); - } - } - else - { - _navigationUpdateTimer -= delta; - } - - var nextPos = master.NavigationAgent2D.GetNextLocation(); - master.LookTargetPosition(playerGlobalPosition); - master.AnimatedSprite.Animation = AnimatorNames.Run; - master.Velocity = (nextPos - master.GlobalPosition - master.NavigationPoint.Position).Normalized() * master.MoveSpeed; - master.CalcMove(delta); - } -} \ No newline at end of file