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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. private readonly ReaderWriterLockSlim gameObjReaderWriterLock = new();
  12. public ReaderWriterLockSlim GameObjReaderWriterLock => gameObjReaderWriterLock;
  13. protected readonly object gameObjLock = new();
  14. public object GameLock => gameObjLock;
  15. protected readonly XY birthPos;
  16. private readonly GameObjType type;
  17. public GameObjType Type => type;
  18. private static long currentMaxID = 0; // 目前游戏对象的最大ID
  19. public const long invalidID = long.MaxValue; // 无效的ID
  20. public long ID { get; }
  21. protected XY position;
  22. public abstract XY Position { get; }
  23. protected XY facingDirection = new(1, 0);
  24. public abstract XY FacingDirection { get; }
  25. protected bool canMove;
  26. public abstract bool CanMove { get; }
  27. public abstract bool IsRigid { get; }
  28. public abstract ShapeType Shape { get; }
  29. public int Radius { get; }
  30. public virtual bool IgnoreCollideExecutor(IGameObj targetObj) => false;
  31. public GameObj(XY initPos, int initRadius, GameObjType initType)
  32. {
  33. this.position = this.birthPos = initPos;
  34. this.Radius = initRadius;
  35. this.type = initType;
  36. ID = Interlocked.Increment(ref currentMaxID);
  37. }
  38. }
  39. }