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