Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / role / player / state / PlayerRollState.cs
  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. Master.AnimatedSprite.Play(AnimatorNames.Roll);
  25.  
  26. //隐藏武器
  27. Master.BackMountPoint.Visible = false;
  28. Master.MountPoint.Visible = false;
  29. //禁用伤害碰撞
  30. Master.HurtCollision.Disabled = true;
  31. //翻滚移动方向
  32. _moveDir = InputManager.MoveAxis;
  33. Master.BasisVelocity = _moveDir * Master.RoleState.RollSpeed;
  34. }
  35.  
  36. public override void Exit(PlayerStateEnum next)
  37. {
  38. //显示武器
  39. Master.BackMountPoint.Visible = true;
  40. Master.MountPoint.Visible = true;
  41. //启用伤害碰撞
  42. Master.HurtCollision.Disabled = false;
  43. }
  44.  
  45. public override void Process(float delta)
  46. {
  47. Master.BasisVelocity = _moveDir * Master.RoleState.RollSpeed;
  48. }
  49.  
  50. //翻滚逻辑处理
  51. private IEnumerator RunRoll()
  52. {
  53. yield return Master.AnimatedSprite.ToSignal(Master.AnimatedSprite, AnimatedSprite2D.SignalName.AnimationFinished);
  54. _coroutineId = -1;
  55. Master.OverRoll();
  56. if (InputManager.MoveAxis != Vector2.Zero) //切换到移动状态
  57. {
  58. ChangeState(PlayerStateEnum.Move);
  59. }
  60. else //切换空闲状态
  61. {
  62. ChangeState(PlayerStateEnum.Idle);
  63. }
  64. }
  65. }