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.

GameObj.cs 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 GameObj : IGameObj
  10. {
  11. protected readonly object gameObjLock = new();
  12. public object GameLock => gameObjLock;
  13. protected readonly XY birthPos;
  14. private readonly GameObjType type;
  15. public GameObjType Type => type;
  16. private static long currentMaxID = 0; // 目前游戏对象的最大ID
  17. public const long invalidID = long.MaxValue; // 无效的ID
  18. public long ID { get; }
  19. protected XY position;
  20. public virtual XY Position { get; set; }
  21. private XY facingDirection = new(1, 0);
  22. public XY FacingDirection
  23. {
  24. get
  25. {
  26. lock (gameObjLock)
  27. return facingDirection;
  28. }
  29. set
  30. {
  31. lock (gameObjLock)
  32. facingDirection = value;
  33. }
  34. }
  35. public abstract bool IsRigid { get; }
  36. public abstract ShapeType Shape { get; }
  37. private bool canMove;
  38. public bool CanMove
  39. {
  40. get => canMove;
  41. set
  42. {
  43. lock (gameObjLock)
  44. {
  45. canMove = value;
  46. }
  47. }
  48. }
  49. private bool isResetting;
  50. public bool IsResetting
  51. {
  52. get => isResetting;
  53. set
  54. {
  55. lock (gameObjLock)
  56. {
  57. isResetting = value;
  58. }
  59. }
  60. }
  61. public int Radius { get; }
  62. public virtual bool IgnoreCollideExecutor(IGameObj targetObj) => false;
  63. public GameObj(XY initPos, int initRadius, GameObjType initType)
  64. {
  65. this.position = this.birthPos = initPos;
  66. this.Radius = initRadius;
  67. this.type = initType;
  68. ID = Interlocked.Increment(ref currentMaxID);
  69. }
  70. }
  71. }