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. /// <summary>
  12. /// 上一帧笔刷坐标
  13. /// </summary>
  14. public Vector2I? PrevPosition = null;
  15. private BrushImageData _brushData;
  16. private GpuParticles2D _gpuParticles2D;
  17. private bool _playOver = false;
  18. private bool _runBrush = true;
  19. public override void OnInit()
  20. {
  21. var frameCount = AnimatedSprite.SpriteFrames.GetFrameCount(AnimatorNames.Default);
  22. AnimatedSprite.Frame = Utils.Random.RandomRangeInt(0, frameCount - 1);
  23.  
  24. Throw(
  25. Utils.Random.RandomRangeInt(0, 16),
  26. Utils.Random.RandomRangeInt(10, 60),
  27. new Vector2(Utils.Random.RandomRangeInt(-25, 25), Utils.Random.RandomRangeInt(-25, 25)),
  28. Utils.Random.RandomRangeInt(-360, 360)
  29. );
  30.  
  31. StartCoroutine(EmitParticles());
  32. _brushData = LiquidBrushManager.GetBrush("0003");
  33. }
  34.  
  35. protected override void Process(float delta)
  36. {
  37. if (_playOver && !IsThrowing && Altitude <= 0 && MoveController.IsMotionless())
  38. {
  39. MoveController.SetAllVelocity(Vector2.Zero);
  40. Freeze();
  41. _runBrush = false;
  42. }
  43. else if (_runBrush && AffiliationArea != null && Altitude <= 1f) //测试笔刷
  44. {
  45. var pos = AffiliationArea.RoomInfo.LiquidCanvas.ToLiquidCanvasPosition(Position);
  46. AffiliationArea.RoomInfo.LiquidCanvas.DrawBrush(_brushData, PrevPosition, pos, 0);
  47. PrevPosition = pos;
  48. }
  49. }
  50.  
  51. public IEnumerator EmitParticles()
  52. {
  53. var gpuParticles2D = GetNode<GpuParticles2D>("GPUParticles2D");
  54. gpuParticles2D.Emitting = true;
  55. yield return new WaitForSeconds(Utils.Random.RandomRangeFloat(1f, 2.5f));
  56. gpuParticles2D.Emitting = false;
  57. yield return new WaitForSeconds(1);
  58. _playOver = true;
  59. }
  60. }