Esempio n. 1
0
 public Hex(CubicCoordinate coordinate, Orientation orientation, float width = 1f)
 {
     Orientation = orientation;
     Coordinate  = coordinate;
     Height      = 0;
     Depth       = 0;
     Width       = width;
 }
Esempio n. 2
0
 /// <summary>
 /// Gets the Hex at the given coordinate. If one does not exist creates it
 /// </summary>
 /// <param name="coord">The coord of the hex to retrieve</param>
 /// <returns>Either the existing hex or a new hex at the given coordinates</returns>
 public Hex GetHexAt(CubicCoordinate coord)
 {
     if (Hexes.ContainsKey(coord))
     {
         return(Hexes[coord]);
     }
     else
     {
         AddHex(coord);
         return(GetHexAt(coord));
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Converts Cubic coordinates to Cartesian coordinates
 /// </summary>
 ///
 /// <param name="coord">The coordinate to convert</param>
 /// <param name="orientation">The orientation of the Hexes</param>
 /// <param name="width">The width of the hexes in the same units as the return value</param>
 ///
 /// <returns>The point at the center of the cubic coordinates given</returns>
 /// <see href="https://www.redblobgames.com/grids/hexagons/#hex-to-pixel"/>
 public static Point CubicToCartesian(CubicCoordinate coord, Orientation orientation, float width)
 {
     if (orientation == Orientation.FlatTop)
     {
         var x = width * (1.5f * coord.Q);
         var y = width * (Math.Sqrt(3) / 2f * coord.Q + Math.Sqrt(3) * coord.R);
         return(new Point((int)x, (int)y));
     }
     else   // Pointy Top
     {
         var x = width * (Math.Sqrt(3) * coord.Q + Math.Sqrt(3) / 2f * coord.R);
         var y = width * (1.5 * coord.R);
         return(new Point((int)x, (int)y));
     }
 }
Esempio n. 4
0
 public void AddHex(CubicCoordinate coord)
 {
     Hexes.Add(coord, new Hex(coord, Orientation, Width));
 }
Esempio n. 5
0
 public static Point ToCartesian(this CubicCoordinate coord, Orientation orientation, float width)
 {
     return(CubicToCartesian(coord, orientation, width));
 }