Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        private IEnumerable <IEnumerable <AxialCoordinate> > InternalSpiraling(AxialCoordinate origin)
        {
            var distance = 0;

            while (true)
            {
                yield return(GetRing(origin, distance));

                distance++;
            }
        }
Ejemplo n.º 3
0
 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);
         }
     }
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
        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);
                }
            }
        }
Ejemplo n.º 6
0
        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");
                }
            }
        }
Ejemplo n.º 7
0
 public int DistanceTo(AxialCoordinate other)
 {
     return(this.DistanceTo(other.ToCube()));
 }
Ejemplo n.º 8
0
 public IEnumerable <AxialCoordinate> GetPositionsSpiralingAround(AxialCoordinate origin)
 {
     return(this.InternalSpiraling(origin).SelectMany(x => x));
 }
Ejemplo n.º 9
0
 public Vector2 TileMapToReal(AxialCoordinate coordinate)
 {
     return(TileMapToRelative(coordinate) * hexRadius);
 }