Newer
Older
DungeonShooting / src / Cursor.cs
@小李xl 小李xl on 28 May 2022 1 KB 抽出枪的基类
  1. using Godot;
  2.  
  3. /// <summary>
  4. /// 鼠标指针
  5. /// </summary>
  6. public class Cursor : Node2D
  7. {
  8.  
  9. public Gun TargetGun = null;
  10.  
  11. private Sprite lt;
  12. private Sprite lb;
  13. private Sprite rt;
  14. private Sprite rb;
  15.  
  16. public override void _Ready()
  17. {
  18. lt = GetNode<Sprite>("LT");
  19. lb = GetNode<Sprite>("LB");
  20. rt = GetNode<Sprite>("RT");
  21. rb = GetNode<Sprite>("RB");
  22. }
  23.  
  24. public override void _Process(float delta)
  25. {
  26. if (TargetGun != null)
  27. {
  28. SetScope(TargetGun.CurrScatteringRange);
  29. }
  30. else
  31. {
  32. SetScope(0);
  33. }
  34. SetCursorPos();
  35. }
  36.  
  37. /// <summary>
  38. /// 设置光标半径范围
  39. /// </summary>
  40. private void SetScope(float scope)
  41. {
  42. if (TargetGun != null)
  43. {
  44. var len = GlobalPosition.DistanceTo(TargetGun.GlobalPosition);
  45. if (TargetGun.Attribute != null)
  46. {
  47. len = Mathf.Max(0, len - TargetGun.Attribute.FirePosition.x);
  48. }
  49. scope = len / GameConfig.ScatteringDistance * scope;
  50. }
  51. lt.Position = new Vector2(-scope, -scope);
  52. lb.Position = new Vector2(-scope, scope);
  53. rt.Position = new Vector2(scope, -scope);
  54. rb.Position = new Vector2(scope, scope);
  55. }
  56.  
  57. private void SetCursorPos()
  58. {
  59. Position = GetGlobalMousePosition();
  60. }
  61. }