| @@ -6,8 +6,8 @@ namespace Preparation.Interface | |||||
| { | { | ||||
| public GameObjType Type { get; } | public GameObjType Type { get; } | ||||
| public long ID { 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 bool IsRigid { get; } | ||||
| public ShapeType Shape { get; } | public ShapeType Shape { get; } | ||||
| public bool CanMove { get; set; } | public bool CanMove { get; set; } | ||||
| @@ -13,6 +13,6 @@ namespace Preparation.Interface | |||||
| Dictionary<GameObjIdx, ReaderWriterLockSlim> GameObjLockDict { get; } | Dictionary<GameObjIdx, ReaderWriterLockSlim> GameObjLockDict { get; } | ||||
| public bool IsOutOfBound(IGameObj obj); | public bool IsOutOfBound(IGameObj obj); | ||||
| public IOutOfBound GetOutOfBound(XYPosition pos); // 返回新建的一个OutOfBound对象 | |||||
| public IOutOfBound GetOutOfBound(XY pos); // 返回新建的一个OutOfBound对象 | |||||
| } | } | ||||
| } | } | ||||
| @@ -7,9 +7,9 @@ namespace Preparation.Interface | |||||
| { | { | ||||
| object MoveLock { get; } | object MoveLock { get; } | ||||
| public int MoveSpeed { get; } | public int MoveSpeed { get; } | ||||
| public long Move(Vector moveVec); | |||||
| public long Move(XY moveVec); | |||||
| protected bool IgnoreCollide(IGameObj targetObj); // 忽略碰撞,在具体类中实现 | protected bool IgnoreCollide(IGameObj targetObj); // 忽略碰撞,在具体类中实现 | ||||
| public bool WillCollideWith(IGameObj? targetObj, XYPosition nextPos) // 检查下一位置是否会和目标物碰撞 | |||||
| public bool WillCollideWith(IGameObj? targetObj, XY nextPos) // 检查下一位置是否会和目标物碰撞 | |||||
| { | { | ||||
| if (targetObj == null) | if (targetObj == null) | ||||
| return false; | return false; | ||||
| @@ -20,7 +20,7 @@ namespace Preparation.Interface | |||||
| return false; | return false; | ||||
| if (targetObj.Shape == ShapeType.Circle) | 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 | else // Square | ||||
| { | { | ||||
| @@ -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))); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -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))); | |||||
| } | |||||
| } | |||||
| } | |||||