Пример #1
0
        /// <summary>
        /// Gets the number of steps between this coordinate
        /// and the given one
        /// </summary>
        public int Distance(AxialCoordinate other)
        {
            int dX = Math.Abs(other.x - x);
            int dY = Math.Abs(other.Y - Y);
            int dZ = Math.Abs(other.z - z);

            return(Maths.Max(dX, dY, dZ));
        }
Пример #2
0
            public HexCell Create(AxialCoordinate coordinate, Vector3 position, HexMap parent)
            {
                HexCell cell = base.Create();

                cell.Coordinate = coordinate;
                cell.transform.SetParent(parent.transform);
                cell.transform.position = position;
                cell.name = coordinate.ToString();
                cell._map = parent;
                return(cell);
            }
Пример #3
0
        /// <summary>
        /// Gets the hex cell at the given axial coordiante
        /// </summary>
        public HexCell this[AxialCoordinate coordinate]
        {
            get
            {
                // Check if map contains cell at given coordinate
                if (!Contains(coordinate))
                {
                    return(null);
                }

                return(cells[coordinate.Z, coordinate.GridColumn]);
            }
        }
Пример #4
0
            private void CreateCells()
            {
                hexMap.cells = new HexCell[cellsDeep, cellsWide];
                for (int column = 0; column < cellsWide; column++)
                {
                    for (int row = 0; row < cellsDeep; row++)
                    {
                        // Calculate coordinate and position
                        AxialCoordinate coordinate = AxialCoordinate.FromGridIndices(column, row);
                        Vector3         position   = GetCellCentre(coordinate);

                        // Create cell and save to map
                        HexCell cell = hexCellFactory.Create(coordinate, position, hexMap);
                        hexMap.cells[row, column] = cell;
                    }
                }
            }
Пример #5
0
            private Vector3 GetCellCentre(AxialCoordinate cell)
            {
                // Is the row odd (odd rows are offset by InnerRadius distance)
                int odd = cell.Z % 2;

                // Get cell centre's distance from bottom left of map
                float   xFromBottomLeft = innerRadius + (cell.GridColumn * innerDiameter) + (odd * innerRadius);
                float   zFromBottomLeft = outerRadius + (cell.Z * 1.5f * outerRadius);
                Vector3 fromBottomLeft  = new Vector3(xFromBottomLeft, 0, zFromBottomLeft);

                // Convert to distance from centre of map
                Vector3 fromCentre = fromBottomLeft - extents;

                // Convert to world position
                Vector3 worldPosition = hexMap.transform.TransformPoint(fromCentre);

                return(worldPosition);
            }
Пример #6
0
 /// <summary>
 /// Checks if this coordinate is adjacent to the given coordinate
 /// </summary>
 public bool IsAdjacent(AxialCoordinate other)
 {
     return(Directions.Select(d => other + d)
            .Contains(this));
 }
Пример #7
0
 /// <summary>
 /// Checks if this hex map contains a cell with
 /// the given coordinate
 /// </summary>
 public bool Contains(AxialCoordinate coordinate)
 {
     return(Contains(coordinate.GridColumn, coordinate.Z));
 }