using System; using Godot; namespace ColdMint.scripts.utils; /// /// CoordinateUtils /// 坐标工具类 /// public static class CoordinateUtils { /// /// 方向描述 /// public enum OrientationDescribe { //上 Up, //下 Down, //左 Left, //右 Right, //原点 Origin } /// /// Vector to direction description(Relative to the origin) /// 向量到方向描述(相对原点而言) /// /// ///origin ///原点坐标 /// /// ///position ///位置 /// /// public static OrientationDescribe[] VectorToOrientationArray(Vector2 origin, Vector2 position) { var vector2 = position - origin; var orientationDescribes = new OrientationDescribe[2]; if (vector2.X < 0) { orientationDescribes[0] = OrientationDescribe.Left; } else if (vector2.X == 0) { orientationDescribes[0] = OrientationDescribe.Origin; } else { orientationDescribes[0] = OrientationDescribe.Right; } if (vector2.Y > 0) { orientationDescribes[1] = OrientationDescribe.Down; } else if (vector2.Y == 0) { orientationDescribes[0] = OrientationDescribe.Origin; } else { orientationDescribes[1] = OrientationDescribe.Up; } return orientationDescribes; } /// /// 传入矩形起点和终点,遍历瓦片地图上的每一个坐标 /// /// /// /// public static void ForEachCell(Vector2I startPoint,Vector2I endPosition,Action action) { for (var x = startPoint.X; x <= endPosition.X; x++) { for (var y = startPoint.Y; y <= endPosition.Y; y++) { action.Invoke(new Vector2I(x, y)); } } } }