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. }
  35.  
  36. protected override void OnBeginCharge()
  37. {
  38. //拉弓开始蓄力
  39. AnimationPlayer.Play(AnimatorNames.Pull);
  40. }
  41.  
  42. protected override void OnChargeFinish()
  43. {
  44. //蓄力完成
  45. SetShake(0.7f);
  46. }
  47.  
  48. protected override void OnEndCharge()
  49. {
  50. //结束蓄力
  51. SetShake(0);
  52. AnimationPlayer.Play(AnimatorNames.Reset);
  53. }
  54.  
  55. protected override void OnFire()
  56. {
  57. if (Master.IsPlayer())
  58. {
  59. //创建抖动
  60. GameCamera.Main.DirectionalShake(Vector2.Right.Rotated(GlobalRotation) * Attribute.CameraShake);
  61. }
  62. }
  63.  
  64. protected override void OnShoot(float fireRotation)
  65. {
  66. FireManager.ShootBullet(this, fireRotation, Attribute.Bullet);
  67. }
  68.  
  69. protected override void OnDestroy()
  70. {
  71. base.OnDestroy();
  72. if (_activeArrow != null)
  73. {
  74. _activeArrow.Destroy();
  75. _activeArrow = null;
  76. }
  77. }
  78. }