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