diff --git a/logic/Preparation/Interface/IGameObj.cs b/logic/Preparation/Interface/IGameObj.cs index 6c5205b..9be3aab 100644 --- a/logic/Preparation/Interface/IGameObj.cs +++ b/logic/Preparation/Interface/IGameObj.cs @@ -6,8 +6,8 @@ namespace Preparation.Interface { public GameObjType Type { get; } public long ID { get; } - public XYPosition Position { get; } // if Square, Pos equals the center - public double FacingDirection { get; } + public XY Position { get; } // if Square, Pos equals the center + public XY FacingDirection { get; } public bool IsRigid { get; } public ShapeType Shape { get; } public bool CanMove { get; set; } diff --git a/logic/Preparation/Interface/IMap.cs b/logic/Preparation/Interface/IMap.cs index 0d781b3..4ad6e18 100644 --- a/logic/Preparation/Interface/IMap.cs +++ b/logic/Preparation/Interface/IMap.cs @@ -13,6 +13,6 @@ namespace Preparation.Interface Dictionary GameObjLockDict { get; } public bool IsOutOfBound(IGameObj obj); - public IOutOfBound GetOutOfBound(XYPosition pos); // 返回新建的一个OutOfBound对象 + public IOutOfBound GetOutOfBound(XY pos); // 返回新建的一个OutOfBound对象 } } diff --git a/logic/Preparation/Interface/IMoveable.cs b/logic/Preparation/Interface/IMoveable.cs index bc16f5b..e72e14e 100644 --- a/logic/Preparation/Interface/IMoveable.cs +++ b/logic/Preparation/Interface/IMoveable.cs @@ -7,9 +7,9 @@ namespace Preparation.Interface { object MoveLock { get; } public int MoveSpeed { get; } - public long Move(Vector moveVec); + public long Move(XY moveVec); protected bool IgnoreCollide(IGameObj targetObj); // 忽略碰撞,在具体类中实现 - public bool WillCollideWith(IGameObj? targetObj, XYPosition nextPos) // 检查下一位置是否会和目标物碰撞 + public bool WillCollideWith(IGameObj? targetObj, XY nextPos) // 检查下一位置是否会和目标物碰撞 { if (targetObj == null) return false; @@ -20,7 +20,7 @@ namespace Preparation.Interface return false; if (targetObj.Shape == ShapeType.Circle) { - return XYPosition.Distance(nextPos, targetObj.Position) < targetObj.Radius + Radius; + return XY.Distance(nextPos, targetObj.Position) < targetObj.Radius + Radius; } else // Square { diff --git a/logic/Preparation/Utility/Vector.cs b/logic/Preparation/Utility/Vector.cs deleted file mode 100644 index 77e2f5c..0000000 --- a/logic/Preparation/Utility/Vector.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; - -namespace Preparation.Utility -{ - - public class Vector - { - public int x; - public int y; - public Vector(int x, int y) - { - this.x = x; - this.y = y; - } - public override string ToString() - { - return "(" + x.ToString() + "," + y.ToString() + ")"; - } - public static int operator*(Vector v1, Vector v2) - { - return (v1.x * v2.x) + (v1.y * v2.y); - } - public static Vector operator +(Vector v1, Vector v2) - { - return new Vector(v1.x + v2.x, v1.y + v2.y); - } - public static Vector operator -(Vector v1, Vector v2) - { - return new Vector(v1.x - v2.x, v1.y - v2.y); - } - } - public class XYPosition: Vector - { - public XYPosition(int x, int y):base(x,y){} - - public static double Distance(XYPosition p1, XYPosition p2) - { - return Math.Sqrt(((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y))); - } - } -} diff --git a/logic/Preparation/Utility/XY.cs b/logic/Preparation/Utility/XY.cs new file mode 100644 index 0000000..f7536a0 --- /dev/null +++ b/logic/Preparation/Utility/XY.cs @@ -0,0 +1,36 @@ +using System; + +namespace Preparation.Utility +{ + + public struct XY + { + public int x; + public int y; + public XY(int x, int y) + { + this.x = x; + this.y = y; + } + public override string ToString() + { + return "(" + x.ToString() + "," + y.ToString() + ")"; + } + public static int operator *(XY v1, XY v2) + { + return (v1.x * v2.x) + (v1.y * v2.y); + } + public static XY operator +(XY v1, XY v2) + { + return new XY(v1.x + v2.x, v1.y + v2.y); + } + public static XY operator -(XY v1, XY v2) + { + return new XY(v1.x - v2.x, v1.y - v2.y); + } + public static double Distance(XY p1, XY p2) + { + return Math.Sqrt(((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y))); + } + } +}