Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / effects / EnemyDebris.cs
@小李xl 小李xl on 3 Nov 2023 1 KB 爆炸影响弹壳
  1.  
  2. using System.Collections;
  3. using Godot;
  4.  
  5. /// <summary>
  6. /// 敌人死亡碎片
  7. /// </summary>
  8. [Tool]
  9. public partial class EnemyDebris : ActivityObject
  10. {
  11.  
  12. private GpuParticles2D _gpuParticles2D;
  13. public override void OnInit()
  14. {
  15. var frameCount = AnimatedSprite.SpriteFrames.GetFrameCount(AnimatorNames.Default);
  16. AnimatedSprite.Frame = Utils.Random.RandomRangeInt(0, frameCount - 1);
  17.  
  18. Throw(
  19. Utils.Random.RandomRangeInt(0, 16),
  20. Utils.Random.RandomRangeInt(10, 60),
  21. new Vector2(Utils.Random.RandomRangeInt(-25, 25), Utils.Random.RandomRangeInt(-25, 25)),
  22. Utils.Random.RandomRangeInt(-360, 360)
  23. );
  24.  
  25. StartCoroutine(EmitParticles());
  26. }
  27.  
  28. public IEnumerator EmitParticles()
  29. {
  30. var gpuParticles2D = GetNode<GpuParticles2D>("GPUParticles2D");
  31. gpuParticles2D.Emitting = true;
  32. yield return new WaitForSeconds(Utils.Random.RandomRangeFloat(1f, 2.5f));
  33. gpuParticles2D.Emitting = false;
  34. yield return new WaitForSeconds(1);
  35. //BecomesStaticImage();
  36. MoveController.SetAllVelocity(Vector2.Zero);
  37. Freeze();
  38. }
  39. }