Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / bullet / normal / BoomBullet.cs
@小李xl 小李xl on 20 Feb 2024 2 KB 弓箭功能开发中
  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. LogicalFinish();
  14. }
  15.  
  16. public override void OnMaxDistance()
  17. {
  18. PlayBoom();
  19. LogicalFinish();
  20. }
  21.  
  22. public override void OnCollisionTarget(IHurt o)
  23. {
  24. State = BulletStateEnum.CollisionTarget;
  25. PlayBoom();
  26. LogicalFinish();
  27. }
  28.  
  29. public override void OnMoveCollision(KinematicCollision2D lastSlideCollision)
  30. {
  31. CurrentBounce++;
  32. if (CurrentBounce > BulletData.BounceCount) //反弹次数超过限制
  33. {
  34. State = BulletStateEnum.MoveCollision;
  35. PlayBoom();
  36. LogicalFinish();
  37. }
  38. else
  39. {
  40. //播放撞击音效
  41. SoundManager.PlaySoundByConfig("collision0001", Position, BulletData.TriggerRole);
  42. }
  43. }
  44.  
  45. protected override void OnFallToGround()
  46. {
  47. //播放撞击音效
  48. SoundManager.PlaySoundByConfig("collision0001", Position, BulletData.TriggerRole);
  49. //这里不调用父类的 OnFallToGround() 函数, 因为这种子弹落地不需要销毁
  50. }
  51.  
  52. /// <summary>
  53. /// 播放爆炸
  54. /// </summary>
  55. public void PlayBoom()
  56. {
  57. var explode = ObjectManager.GetPoolItem<Explode>(ResourcePath.prefab_bullet_explode_Explode0001_tscn);
  58. var pos = CollisionArea.GlobalPosition;
  59. explode.Position = pos;
  60. explode.RotationDegrees = Utils.Random.RandomRangeInt(0, 360);
  61. explode.AddToActivityRootDeferred(RoomLayerEnum.YSortLayer);
  62. explode.Init(BulletData, AttackLayer, 25, BulletData.Harm, 50, BulletData.Repel);
  63. explode.RunPlay(BulletData.TriggerRole);
  64. if (AffiliationArea != null)
  65. {
  66. var texture = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_explode_Explode_pit0001_png);
  67. var tempPos = AffiliationArea.RoomInfo.ToCanvasPosition(pos);
  68. AffiliationArea.RoomInfo.StaticImageCanvas.DrawImageInCanvas(
  69. texture, null, tempPos.X, tempPos.Y, Utils.Random.RandomRangeInt(0, 360),
  70. texture.GetWidth() / 2, texture.GetHeight() / 2, false
  71. );
  72. }
  73. }
  74. }