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