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. Throw(
  24. Utils.Random.RandomRangeInt(0, 16),
  25. Utils.Random.RandomRangeInt(10, 60),
  26. new Vector2(Utils.Random.RandomRangeInt(-25, 25), Utils.Random.RandomRangeInt(-25, 25)),
  27. Utils.Random.RandomRangeInt(-360, 360)
  28. );
  29. StartCoroutine(EmitParticles());
  30. _brushData = LiquidBrushManager.GetBrush("0003");
  31. }
  32.  
  33. protected override void Process(float delta)
  34. {
  35. if (_playOver && !IsThrowing && Altitude <= 0 && MoveController.IsMotionless())
  36. {
  37. MoveController.SetAllVelocity(Vector2.Zero);
  38. Freeze();
  39. _runBrush = false;
  40. }
  41. else if (_runBrush && AffiliationArea != null && Altitude <= 1f) //测试笔刷
  42. {
  43. var pos = AffiliationArea.RoomInfo.LiquidCanvas.ToLiquidCanvasPosition(Position);
  44. AffiliationArea.RoomInfo.LiquidCanvas.DrawBrush(_brushData, PrevPosition, pos, 0);
  45. PrevPosition = pos;
  46. }
  47. }
  48.  
  49. public IEnumerator EmitParticles()
  50. {
  51. var gpuParticles2D = GetNode<GpuParticles2D>("GPUParticles2D");
  52. gpuParticles2D.Emitting = true;
  53. yield return new WaitForSeconds(Utils.Random.RandomRangeFloat(1f, 2.5f));
  54. gpuParticles2D.Emitting = false;
  55. yield return new WaitForSeconds(1);
  56. _playOver = true;
  57. }
  58. }