Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / effects / enemy / EnemyDead0001.cs
  1.  
  2. using System.Collections;
  3. using Godot;
  4.  
  5. /// <summary>
  6. /// 敌人死亡碎片
  7. /// </summary>
  8. [Tool]
  9. public partial class EnemyDead0001 : ActivityObject
  10. {
  11.  
  12. private GpuParticles2D _gpuParticles2D;
  13. private bool _playOver = false;
  14. public override void OnInit()
  15. {
  16. var frameCount = AnimatedSprite.SpriteFrames.GetFrameCount(AnimatorNames.Default);
  17. AnimatedSprite.Frame = Utils.Random.RandomRangeInt(0, frameCount - 1);
  18.  
  19. Throw(
  20. Utils.Random.RandomRangeInt(0, 16),
  21. Utils.Random.RandomRangeInt(10, 60),
  22. new Vector2(Utils.Random.RandomRangeInt(-25, 25), Utils.Random.RandomRangeInt(-25, 25)),
  23. Utils.Random.RandomRangeInt(-360, 360)
  24. );
  25.  
  26. StartCoroutine(EmitParticles());
  27. }
  28.  
  29. protected override void Process(float delta)
  30. {
  31. if (_playOver && !IsThrowing && Altitude <= 0 && MoveController.IsMotionless())
  32. {
  33. MoveController.SetAllVelocity(Vector2.Zero);
  34. Freeze();
  35. }
  36. }
  37.  
  38. public IEnumerator EmitParticles()
  39. {
  40. var gpuParticles2D = GetNode<GpuParticles2D>("GPUParticles2D");
  41. gpuParticles2D.Emitting = true;
  42. yield return new WaitForSeconds(Utils.Random.RandomRangeFloat(1f, 2.5f));
  43. gpuParticles2D.Emitting = false;
  44. yield return new WaitForSeconds(1);
  45. _playOver = true;
  46. }
  47. }