Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / weapon / bow / Bow.cs
  1. using Godot;
  2.  
  3. /// <summary>
  4. /// 弓箭
  5. /// </summary>
  6. [Tool]
  7. public partial class Bow : Weapon
  8. {
  9. /// <summary>
  10. /// 弓箭挂载点
  11. /// </summary>
  12. [Export, ExportFillNode]
  13. public Marker2D ArrowPoint { get; set; }
  14.  
  15. //正在使用的弓箭
  16. private Arrow _activeArrow;
  17.  
  18. public override void OnInit()
  19. {
  20. base.OnInit();
  21. _activeArrow = (Arrow)FireManager.ShootBullet(this, 0, Attribute.Bullet);
  22. _activeArrow.Pickup();
  23. _activeArrow.MoveController.Enable = false;
  24. _activeArrow.CollisionArea.Monitoring = false;
  25. _activeArrow.Collision.Disabled = true;
  26. _activeArrow.Position = Vector2.Zero;
  27. ArrowPoint.AddChild(_activeArrow);
  28. }
  29.  
  30. protected override void Process(float delta)
  31. {
  32. base.Process(delta);
  33. _activeArrow.ShadowOffset = ShadowOffset + new Vector2(0, Altitude);
  34. _activeArrow.Visible = !IsTotalAmmoEmpty();
  35. }
  36.  
  37. protected override void OnPickUp(Role master)
  38. {
  39. _activeArrow.RefreshBulletColor(master.IsEnemyWithPlayer());
  40. }
  41.  
  42. protected override void OnRemove(Role master)
  43. {
  44. _activeArrow.RefreshBulletColor(false);
  45. }
  46.  
  47. protected override void OnBeginCharge()
  48. {
  49. //拉弓开始蓄力
  50. AnimationPlayer.Play(AnimatorNames.Pull);
  51. }
  52.  
  53. protected override void OnChargeFinish()
  54. {
  55. //蓄力完成
  56. SetShake(0.7f);
  57. }
  58.  
  59. protected override void OnEndCharge()
  60. {
  61. //结束蓄力
  62. SetShake(0);
  63. AnimationPlayer.Play(AnimatorNames.Reset);
  64. }
  65.  
  66. protected override void OnFire()
  67. {
  68. if (Master.IsPlayer())
  69. {
  70. //创建抖动
  71. GameCamera.Main.DirectionalShake(Vector2.Right.Rotated(GlobalRotation) * Attribute.CameraShake);
  72. }
  73. }
  74.  
  75. protected override void OnShoot(float fireRotation)
  76. {
  77. FireManager.ShootBullet(this, fireRotation, Attribute.Bullet);
  78. }
  79.  
  80. protected override void OnDestroy()
  81. {
  82. base.OnDestroy();
  83. if (_activeArrow != null)
  84. {
  85. _activeArrow.Destroy();
  86. _activeArrow = null;
  87. }
  88. }
  89. }