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

1234567891011121314151617181920212223242526272829303132333435363738394041
  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, PlaceType place);
  12. public void ReSetPos(XY pos, PlaceType place);
  13. public bool WillCollideWith(IGameObj? targetObj, XY nextPos) // 检查下一位置是否会和目标物碰撞
  14. {
  15. if (targetObj == null)
  16. return false;
  17. // 会移动的只有子弹和人物,都是Circle
  18. if (!targetObj.IsRigid || targetObj.ID == ID)
  19. return false;
  20. if (IgnoreCollideExecutor(targetObj) || targetObj.IgnoreCollideExecutor(this))
  21. return false;
  22. if (targetObj.Shape == ShapeType.Circle)
  23. {
  24. return XY.DistanceCeil3(nextPos, targetObj.Position) < targetObj.Radius + Radius;
  25. }
  26. else // Square
  27. {
  28. long deltaX = Math.Abs(nextPos.x - targetObj.Position.x), deltaY = Math.Abs(nextPos.y - targetObj.Position.y);
  29. if (deltaX >= targetObj.Radius + Radius || deltaY >= targetObj.Radius + Radius)
  30. return false;
  31. if (deltaX < targetObj.Radius || deltaY < targetObj.Radius)
  32. return true;
  33. else
  34. return ((long)(deltaX - targetObj.Radius) * (deltaX - targetObj.Radius)) + ((long)(deltaY - targetObj.Radius) * (deltaY - targetObj.Radius)) <= (long)Radius * (long)Radius;
  35. }
  36. }
  37. }
  38. }