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.8 kB

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