Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new new HexGrid.
        /// </summary>
        /// <param name="width">The number of columns</param>
        /// <param name="height">The number of rows</param>
        public HexGrid(int width, int height)
        {
            _width  = width + 1;
            _height = height;

            _gridOffset = HexCoordinate.FromCartesian(-new Vector2(_width * 0.5f, 0.66f * _height * 0.5f));
            _cells      = new T[_width, _height];
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new new HexGrid at a specfic position.
        /// </summary>
        /// <param name="width">The number of columns</param>
        /// <param name="height">The number of rows</param>
        /// <param name="position">The center of the grid in cartesian space</param>>
        /// <param name="hexDimensions">Hex cell dimensions, x = width in world units, y = squash factor eg. 0.66 means hex height is 66% what it would be for a cell of that width</param>
        public HexGrid(int width, int height, Vector2 position, Vector2 hexDimensions)
        {
            _width  = width + 1;
            _height = height;

            _gridOffset = HexCoordinate.FromCartesian(position - new Vector2(hexDimensions.x * _width * 0.5f, hexDimensions.y * _height * 0.5f));
            _cells      = new T[_width, _height];
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Finds the hex coordinate that is nearest to this position.
 /// </summary>
 /// <returns>The nearest hex coordinate to this cartesian position</returns>
 public static HexCoordinate ToHexCoordinate(this Vector2 vector)
 {
     return(HexCoordinate.FromCartesian(vector));
 }