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

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