Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / effects / enemy / EnemyDead0001.cs
@小李xl 小李xl on 11 Apr 2024 2 KB 敌人死亡效果更新
  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) //测试笔刷
  42. {
  43. var pos = AffiliationArea.RoomInfo.LiquidCanvas.ToLiquidCanvasPosition(Position);
  44. if (Altitude <= 0.25f)
  45. {
  46. AffiliationArea.RoomInfo.LiquidCanvas.DrawBrush(_brushData, PrevPosition, pos, 0);
  47. }
  48.  
  49. PrevPosition = pos;
  50. }
  51. }
  52.  
  53. public IEnumerator EmitParticles()
  54. {
  55. var gpuParticles2D = GetNode<GpuParticles2D>("GPUParticles2D");
  56. gpuParticles2D.Emitting = true;
  57. yield return new WaitForSeconds(Utils.Random.RandomRangeFloat(1f, 2.5f));
  58. gpuParticles2D.Emitting = false;
  59. yield return new WaitForSeconds(1);
  60. _playOver = true;
  61. }
  62. }