Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / bullet / normal / BoomBullet.cs
@小李xl 小李xl on 28 Nov 2023 2 KB 将液体画布加入到RoomInfo上
  1.  
  2. using Godot;
  3.  
  4. /// <summary>
  5. /// 爆炸子弹
  6. /// </summary>
  7. [Tool]
  8. public partial class BoomBullet : Bullet
  9. {
  10. /// <summary>
  11. /// 轨迹粒子
  12. /// </summary>
  13. [Export]
  14. public GpuParticles2D Particles;
  15.  
  16. public override void InitData(BulletData data, uint attackLayer)
  17. {
  18. base.InitData(data, attackLayer);
  19. if (Particles != null)
  20. {
  21. Particles.Restart();
  22. }
  23. }
  24.  
  25. public override void OnLimeOver()
  26. {
  27. PlayBoom();
  28. DoReclaim();
  29. }
  30.  
  31. public override void OnMaxDistance()
  32. {
  33. PlayBoom();
  34. DoReclaim();
  35. }
  36.  
  37. public override void OnCollisionTarget(ActivityObject o)
  38. {
  39. PlayBoom();
  40. DoReclaim();
  41. }
  42.  
  43. public override void OnMoveCollision(KinematicCollision2D lastSlideCollision)
  44. {
  45. CurrentBounce++;
  46. if (CurrentBounce > BulletData.BounceCount) //反弹次数超过限制
  47. {
  48. PlayBoom();
  49. }
  50. else
  51. {
  52. //播放撞击音效
  53. SoundManager.PlaySoundByConfig("collision0001", Position, BulletData.TriggerRole);
  54. }
  55. }
  56.  
  57. protected override void OnFallToGround()
  58. {
  59. //播放撞击音效
  60. SoundManager.PlaySoundByConfig("collision0001", Position, BulletData.TriggerRole);
  61. //这里不调用父类的 OnFallToGround() 函数, 因为这种子弹落地不需要销毁
  62. }
  63.  
  64. /// <summary>
  65. /// 播放爆炸
  66. /// </summary>
  67. public void PlayBoom()
  68. {
  69. var explode = ObjectManager.GetPoolItem<Explode>(ResourcePath.prefab_bullet_explode_Explode0001_tscn);
  70. var pos = Position;
  71. explode.Position = pos;
  72. explode.RotationDegrees = Utils.Random.RandomRangeInt(0, 360);
  73. explode.AddToActivityRootDeferred(RoomLayerEnum.YSortLayer);
  74. explode.Init(BulletData, AttackLayer, 25, BulletData.Harm, 50, BulletData.Repel);
  75. explode.RunPlay(BulletData.TriggerRole);
  76. if (AffiliationArea != null)
  77. {
  78. var texture = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_effects_explode_Explode_pit0001_png);
  79. var tempPos = AffiliationArea.RoomInfo.ToCanvasPosition(pos);
  80. AffiliationArea.RoomInfo.StaticImageCanvas.DrawImageInCanvas(
  81. texture, null, tempPos.X, tempPos.Y, Utils.Random.RandomRangeInt(0, 360),
  82. texture.GetWidth() / 2, texture.GetHeight() / 2, false
  83. );
  84. }
  85. }
  86. }