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 2.9 kB

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