/// <summary> /// Translate a tile map coordinate to a standard "real" position. this is not scaled based /// on the size of the hexes. only use it for calculations that need to know about /// relative positioning of hex members as opposed to real positioning /// </summary> /// <param name="offsetCoordinates"></param> /// <returns></returns> public Vector2 TileMapToRelative(AxialCoordinate axial) { var x = qBasis.x * axial.q; var y = qBasis.y * axial.q + rBasis.y * axial.r; return(new Vector2(x, y)); }
private IEnumerable <IEnumerable <AxialCoordinate> > InternalSpiraling(AxialCoordinate origin) { var distance = 0; while (true) { yield return(GetRing(origin, distance)); distance++; } }
public static IEnumerable <AxialCoordinate> GetPositionsWithinJumpDistance(AxialCoordinate origin, int jumpDistance) { for (var q = -jumpDistance; q <= jumpDistance; q++) { var sliceStart = Mathf.Max(-jumpDistance, -q - jumpDistance); var sliceEnd = Mathf.Min(jumpDistance, -q + jumpDistance); for (var r = sliceStart; r <= sliceEnd; r++) { yield return(new AxialCoordinate(q, r) + origin); } } }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj is AxialCoordinate) { AxialCoordinate other = (AxialCoordinate)obj; return(other.q == q && other.r == r); } return(false); }
public static IEnumerable <AxialCoordinate> GetRing(AxialCoordinate origin, int distance) { if (distance == 0) { yield return(origin); } var currentPointInRing = origin + (AxialCoordinate.GetDirection(4) * distance); for (var directionIndex = 0; directionIndex < 6; directionIndex++) { for (var i = 0; i < distance; i++) { yield return(currentPointInRing); currentPointInRing = currentPointInRing.GetNeighbor(directionIndex); } } }
public IEnumerable <AxialCoordinate> GetRouteGenerator(AxialCoordinate origin, AxialCoordinate destination) { var currentTileMapPos = new AxialCoordinate(origin.q, origin.r); var myDest = new AxialCoordinate(destination.q, destination.r); var iterations = 0; while (!currentTileMapPos.Equals(myDest)) { var realWorldVectorToDest = TileMapToRelative(myDest) - TileMapToRelative(currentTileMapPos); var nextMoveVector = GetClosestMatchingValidMove(realWorldVectorToDest); currentTileMapPos = currentTileMapPos + nextMoveVector; yield return(currentTileMapPos); iterations++; if (iterations > 1000) { throw new Exception("too many loop brooother"); } } }
public int DistanceTo(AxialCoordinate other) { return(this.DistanceTo(other.ToCube())); }
public IEnumerable <AxialCoordinate> GetPositionsSpiralingAround(AxialCoordinate origin) { return(this.InternalSpiraling(origin).SelectMany(x => x)); }
public Vector2 TileMapToReal(AxialCoordinate coordinate) { return(TileMapToRelative(coordinate) * hexRadius); }