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.

IMoveable.cs 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Threading;
  3. using Preparation.Utility;
  4. namespace Preparation.Interface
  5. {
  6. public interface IMoveable : IGameObj
  7. {
  8. public XY FacingDirection { get; set; }
  9. object ActionLock { get; }
  10. public int MoveSpeed { get; }
  11. public bool IsMoving { get; set; }
  12. public bool IsRemoved { get; }
  13. public bool IsAvailableForMove { get; }
  14. public long StateNum { get; }
  15. public Semaphore ThreadNum { get; }
  16. public long MovingSetPos(XY moveVec, long stateNum);
  17. public void ReSetCanMove(bool value);
  18. public bool WillCollideWith(IGameObj? targetObj, XY nextPos) // 检查下一位置是否会和目标物碰撞
  19. {
  20. if (targetObj == null)
  21. return false;
  22. // 会移动的只有子弹和人物,都是Circle
  23. if (!targetObj.IsRigid || targetObj.ID == ID)
  24. return false;
  25. if (IgnoreCollideExecutor(targetObj) || targetObj.IgnoreCollideExecutor(this))
  26. return false;
  27. if (targetObj.Shape == ShapeType.Circle)
  28. {
  29. return XY.DistanceCeil3(nextPos, targetObj.Position) < targetObj.Radius + Radius;
  30. }
  31. else // Square
  32. {
  33. long deltaX = Math.Abs(nextPos.x - targetObj.Position.x), deltaY = Math.Abs(nextPos.y - targetObj.Position.y);
  34. if (deltaX >= targetObj.Radius + Radius || deltaY >= targetObj.Radius + Radius)
  35. return false;
  36. if (deltaX < targetObj.Radius || deltaY < targetObj.Radius)
  37. return true;
  38. else
  39. return ((long)(deltaX - targetObj.Radius) * (deltaX - targetObj.Radius)) + ((long)(deltaY - targetObj.Radius) * (deltaY - targetObj.Radius)) <= (long)Radius * (long)Radius;
  40. }
  41. }
  42. }
  43. }