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

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