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. Destroy();
  14. }
  15.  
  16. public override void OnMaxDistance()
  17. {
  18. PlayBoom();
  19. Destroy();
  20. }
  21.  
  22. public override void OnCollisionTarget(ActivityObject o)
  23. {
  24. PlayBoom();
  25. Destroy();
  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. }
  47.  
  48. /// <summary>
  49. /// 播放爆炸
  50. /// </summary>
  51. public void PlayBoom()
  52. {
  53. var explode = ObjectManager.GetExplode(ResourcePath.prefab_bullet_explode_Explode0001_tscn);
  54. var pos = Position;
  55. explode.Position = pos;
  56. explode.RotationDegrees = Utils.Random.RandomRangeInt(0, 360);
  57. explode.AddToActivityRootDeferred(RoomLayerEnum.YSortLayer);
  58. explode.Init(BulletData.TriggerRole?.AffiliationArea, AttackLayer, 25, BulletData.MinHarm, BulletData.MaxHarm, 50, 150);
  59. explode.RunPlay(BulletData.TriggerRole);
  60. if (AffiliationArea != null)
  61. {
  62. var texture = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_effects_explode_Explode_pit0001_png);
  63. var tempPos = AffiliationArea.RoomInfo.ToImageCanvasPosition(pos);
  64. AffiliationArea.RoomInfo.StaticImageCanvas.DrawImageInCanvas(
  65. texture, null, tempPos.X, tempPos.Y, Utils.Random.RandomRangeInt(0, 360),
  66. texture.GetWidth() / 2, texture.GetHeight() / 2, false
  67. );
  68. }
  69. }
  70. }