Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / role / player / state / PlayerRollState.cs
@小李xl 小李xl on 29 Nov 2023 2 KB 更新翻滚动作
  1.  
  2. using System.Collections;
  3. using Godot;
  4.  
  5. /// <summary>
  6. /// 翻滚状态
  7. /// </summary>
  8. public class PlayerRollState : StateBase<Player, PlayerStateEnum>
  9. {
  10. private long _coroutineId = -1;
  11. private Vector2 _moveDir;
  12. public PlayerRollState() : base(PlayerStateEnum.Roll)
  13. {
  14. }
  15.  
  16. public override void Enter(PlayerStateEnum prev, params object[] args)
  17. {
  18. if (_coroutineId >= 0)
  19. {
  20. Master.StopCoroutine(_coroutineId);
  21. }
  22.  
  23. _coroutineId = Master.StartCoroutine(RunRoll());
  24.  
  25. //隐藏武器
  26. Master.BackMountPoint.Visible = false;
  27. Master.MountPoint.Visible = false;
  28. //禁用伤害碰撞
  29. Master.HurtCollision.Disabled = true;
  30. //翻滚移动方向
  31. _moveDir = InputManager.MoveAxis;
  32. Master.BasisVelocity = _moveDir * Master.PlayerRoleState.RollSpeed;
  33. }
  34.  
  35. public override void Exit(PlayerStateEnum next)
  36. {
  37. //显示武器
  38. Master.BackMountPoint.Visible = true;
  39. Master.MountPoint.Visible = true;
  40. //启用伤害碰撞
  41. Master.HurtCollision.Disabled = false;
  42. Master.BasisVelocity = Master.BasisVelocity.LimitLength(Master.RoleState.MoveSpeed);
  43. }
  44.  
  45. public override void Process(float delta)
  46. {
  47. Master.BasisVelocity = _moveDir * Master.PlayerRoleState.RollSpeed;
  48. }
  49.  
  50. //翻滚逻辑处理
  51. private IEnumerator RunRoll()
  52. {
  53. Master.AnimatedSprite.Play(AnimatorNames.Roll);
  54.  
  55. Master.MountLookTarget = false;
  56. var face = Master.Face;
  57. var velocity = Master.BasisVelocity;
  58. if (velocity.X > 0 && face == FaceDirection.Left)
  59. {
  60. Master.Face = FaceDirection.Right;
  61. }
  62. else if (velocity.X < 0 && face == FaceDirection.Right)
  63. {
  64. Master.Face = FaceDirection.Left;
  65. }
  66. yield return Master.AnimatedSprite.ToSignal(Master.AnimatedSprite, AnimatedSprite2D.SignalName.AnimationFinished);
  67. _coroutineId = -1;
  68. Master.MountLookTarget = true;
  69. Master.Face = face;
  70. Master.OverRoll();
  71. if (InputManager.MoveAxis != Vector2.Zero) //切换到移动状态
  72. {
  73. ChangeState(PlayerStateEnum.Move);
  74. }
  75. else //切换空闲状态
  76. {
  77. ChangeState(PlayerStateEnum.Idle);
  78. }
  79. }
  80. }