/// <summary> /// Moves to cube diagonals. /// </summary> /// <param name="coordinates">The coordinates.</param> /// <param name="direction">The direction.</param> /// <returns></returns> public static CubeCoordinate MoveToCubeDiagonals(CubeCoordinate coordinates, int direction) { Dictionary <int, int[]> diagonals = new Dictionary <int, int[]> { { 0, new int[] { 2, -1, -1 } }, { 1, new int[] { 1, 1, -2 } }, { 2, new int[] { -1, 2, -1 } }, { 3, new int[] { -2, 1, 1 } }, { 4, new int[] { -1, -1, 2 } }, { 5, new int[] { 1, -2, 1 } } }; int[] d = diagonals[direction]; return(new CubeCoordinate(coordinates.X + d[0], coordinates.Y + d[1], coordinates.Z + d[2])); }
/// <summary> /// Moves the in cube coordinates. /// </summary> /// <returns>The in cube coordinates.</returns> /// <param name="corrdinates">Corrdinates.</param> /// <param name="direction">Start at the left Hex, moves counter clockwise 0-5.</param> public CubeCoordinate MoveInCubeCoordinate(CubeCoordinate corrdinates, int direction) { Dictionary <int, int[]> neighbors = new Dictionary <int, int[]> { { 0, new int[] { 1, -1, 0 } }, { 1, new int[] { 1, 0, -1 } }, { 2, new int[] { 0, 1, -1 } }, { 3, new int[] { -1, 1, 0 } }, { 4, new int[] { -1, 0, 1 } }, { 5, new int[] { 0, -1, 1 } } }; int[] d = neighbors[direction]; return(new CubeCoordinate(corrdinates.X + d[0], corrdinates.Y + d[1], corrdinates.Z + d[2])); }
/// <summary> /// Caclulates the cube hexagon distance. /// </summary> /// <param name="cube1">The cube1.</param> /// <param name="cube2">The cube2.</param> /// <returns></returns> public static float CaclulateCubeCoordDistance(CubeCoordinate cube1, CubeCoordinate cube2) { return((float)(Math.Abs(cube1.X - cube2.X) + Math.Abs(cube1.Y - cube1.Y) + Math.Abs(cube1.Z - cube2.Z) / 2)); }