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. DoReclaim();
  35. }
  36. else
  37. {
  38. //播放撞击音效
  39. SoundManager.PlaySoundByConfig("collision0001", Position, BulletData.TriggerRole);
  40. }
  41. }
  42.  
  43. protected override void OnFallToGround()
  44. {
  45. //播放撞击音效
  46. SoundManager.PlaySoundByConfig("collision0001", Position, BulletData.TriggerRole);
  47. //这里不调用父类的 OnFallToGround() 函数, 因为这种子弹落地不需要销毁
  48. }
  49.  
  50. /// <summary>
  51. /// 播放爆炸
  52. /// </summary>
  53. public void PlayBoom()
  54. {
  55. var explode = ObjectManager.GetPoolItem<Explode>(ResourcePath.prefab_bullet_explode_Explode0001_tscn);
  56. var pos = Position;
  57. explode.Position = pos;
  58. explode.RotationDegrees = Utils.Random.RandomRangeInt(0, 360);
  59. explode.AddToActivityRootDeferred(RoomLayerEnum.YSortLayer);
  60. explode.Init(BulletData, AttackLayer, 25, BulletData.Harm, 50, BulletData.Repel);
  61. explode.RunPlay(BulletData.TriggerRole);
  62. if (AffiliationArea != null)
  63. {
  64. var texture = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_explode_Explode_pit0001_png);
  65. var tempPos = AffiliationArea.RoomInfo.ToCanvasPosition(pos);
  66. AffiliationArea.RoomInfo.StaticImageCanvas.DrawImageInCanvas(
  67. texture, null, tempPos.X, tempPos.Y, Utils.Random.RandomRangeInt(0, 360),
  68. texture.GetWidth() / 2, texture.GetHeight() / 2, false
  69. );
  70. }
  71. }
  72. }