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.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. lock (gameObjLock)
  49. {
  50. FacingDirection = moveVec;
  51. this.Position += moveVec;
  52. this.place = place;
  53. }
  54. return moveVec * moveVec;
  55. }
  56. public void ReSetPos(XY pos, PlaceType place)
  57. {
  58. lock (gameObjLock)
  59. {
  60. this.Position = pos;
  61. this.place = place;
  62. }
  63. }
  64. /// <summary>
  65. /// 设置移动速度
  66. /// </summary>
  67. /// <param name="newMoveSpeed">新速度</param>
  68. public void SetMoveSpeed(int newMoveSpeed)
  69. {
  70. MoveSpeed = newMoveSpeed;
  71. }
  72. /* /// <summary>
  73. /// 复活时数据重置
  74. /// </summary>
  75. public virtual void Reset(PlaceType place)
  76. {
  77. lock (gameObjLock)
  78. {
  79. this.FacingDirection = new XY(1, 0);
  80. isMoving = false;
  81. CanMove = false;
  82. IsResetting = true;
  83. this.Position = birthPos;
  84. this.Place= place;
  85. }
  86. }*/
  87. /// <summary>
  88. /// 为了使IgnoreCollide多态化并使GameObj能不报错地继承IMoveable
  89. /// 在xfgg点播下设计了这个抽象辅助方法,在具体类中实现
  90. /// </summary>
  91. /// <returns> 依具体类及该方法参数而定,默认为false </returns>
  92. public Moveable(XY initPos, int initRadius, GameObjType initType) : base(initPos, initRadius, initType)
  93. {
  94. }
  95. }
  96. }