You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Moveable.cs 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Preparation.Interface;
  2. using Preparation.Utility;
  3. using System.Threading;
  4. namespace GameClass.GameObj
  5. {
  6. /// <summary>
  7. /// 一切游戏元素的总基类,与THUAI4不同,继承IMoveable接口(出于一切物体其实都是可运动的指导思想)——LHR
  8. /// </summary>
  9. public abstract class Moveable : GameObj, IMoveable
  10. {
  11. protected readonly object moveObjLock = new();
  12. public object MoveLock => moveObjLock;
  13. private bool isMoving;
  14. public bool IsMoving
  15. {
  16. get => isMoving;
  17. set
  18. {
  19. lock (gameObjLock)
  20. {
  21. isMoving = value;
  22. }
  23. }
  24. }
  25. public bool IsAvailable => !IsMoving && CanMove && !IsResetting; // 是否能接收指令
  26. protected int moveSpeed;
  27. /// <summary>
  28. /// 移动速度
  29. /// </summary>
  30. public int MoveSpeed
  31. {
  32. get => moveSpeed;
  33. set
  34. {
  35. lock (gameObjLock)
  36. {
  37. moveSpeed = value;
  38. }
  39. }
  40. }
  41. /// <summary>
  42. /// 原初移动速度
  43. /// </summary>
  44. public int OrgMoveSpeed { get; protected set; }
  45. // 移动,改变坐标
  46. public long MovingSetPos(XY moveVec, PlaceType place)
  47. {
  48. if (moveVec.x != 0 || moveVec.y != 0)
  49. lock (gameObjLock)
  50. {
  51. FacingDirection = moveVec;
  52. this.Position += moveVec;
  53. this.place = place;
  54. }
  55. return moveVec * moveVec;
  56. }
  57. public void ReSetPos(XY pos, PlaceType place)
  58. {
  59. lock (gameObjLock)
  60. {
  61. this.Position = pos;
  62. this.place = place;
  63. }
  64. }
  65. /// <summary>
  66. /// 设置移动速度
  67. /// </summary>
  68. /// <param name="newMoveSpeed">新速度</param>
  69. public void SetMoveSpeed(int newMoveSpeed)
  70. {
  71. MoveSpeed = newMoveSpeed;
  72. }
  73. /* /// <summary>
  74. /// 复活时数据重置
  75. /// </summary>
  76. public virtual void Reset(PlaceType place)
  77. {
  78. lock (gameObjLock)
  79. {
  80. this.FacingDirection = new XY(1, 0);
  81. isMoving = false;
  82. CanMove = false;
  83. IsResetting = true;
  84. this.Position = birthPos;
  85. this.Place= place;
  86. }
  87. }*/
  88. /// <summary>
  89. /// 为了使IgnoreCollide多态化并使GameObj能不报错地继承IMoveable
  90. /// 在xfgg点播下设计了这个抽象辅助方法,在具体类中实现
  91. /// </summary>
  92. /// <returns> 依具体类及该方法参数而定,默认为false </returns>
  93. public Moveable(XY initPos, int initRadius, GameObjType initType) : base(initPos, initRadius, initType)
  94. {
  95. }
  96. }
  97. }