示例#1
0
    public static void CubeToOffset(ref HexCubeCoordinate c, HexCellOrientation orientation, out OffsetCoordinate o)
    {
        switch (orientation)
        {
        case HexCellOrientation.PointyOdd:
            CubeToPointyOdd(ref c, out o);
            break;

        case HexCellOrientation.PointyEven:
            CubeToPointyEven(ref c, out o);
            break;

        case HexCellOrientation.FlatOdd:
            CubeToFlatOdd(ref c, out o);
            break;

        case HexCellOrientation.FlatEven:
            CubeToFlatEven(ref c, out o);
            break;

        default:
            CubeToPointyOdd(ref c, out o);
            break;
        }
    }
示例#2
0
    public void CellsInRange(ref HexCell center, int range, List <HexCell> neighbours)
    {
        //Return tiles rnage steps from center, http://www.redblobgames.com/grids/hexagons/#range

        for (int dx = -range; dx <= range; dx++)
        {
            for (int dy = Mathf.Max(-range, -dx - range); dy <= Mathf.Min(range, -dx + range); dy++)
            {
                var o = new HexCubeCoordinate(dx, dy, -dx - dy) + center.coordinates;
                if (grid.TryGetValue(o.ToString(), out var cell))
                {
                    neighbours.Add(cell);
                }
            }
        }
    }
示例#3
0
 private static void FlatOddToCube(ref OffsetCoordinate o, out HexCubeCoordinate c)
 {
     c.x = o.col;
     c.z = o.row - (o.col - (o.col & 1)) / 2;
     c.y = -c.x - c.z;
 }
示例#4
0
 private static void PointyEvenToCube(ref OffsetCoordinate o, out HexCubeCoordinate c)
 {
     c.x = o.col - (o.row + (o.row & 1)) / 2;
     c.z = o.row;
     c.y = -c.x - c.z;
 }
示例#5
0
    public static void OffsetToCube(ref OffsetCoordinate o, HexCellOrientation orientation, out HexCubeCoordinate c)
    {
        switch (orientation)
        {
        case HexCellOrientation.PointyOdd:
            PointyOddToCube(ref o, out c);
            break;

        case HexCellOrientation.PointyEven:
            PointyEvenToCube(ref o, out c);
            break;

        case HexCellOrientation.FlatOdd:
            FlatOddToCube(ref o, out c);
            break;

        case HexCellOrientation.FlatEven:
            FlatEvenToCube(ref o, out c);
            break;

        default:
            PointyOddToCube(ref o, out c);
            break;
        }
    }
示例#6
0
 public void GetCubeCoordinates(HexCellOrientation orientation, out HexCubeCoordinate c)
 {
     OffsetToCube(ref this, orientation, out c);
 }
示例#7
0
 private static void CubeToFlatEven(ref HexCubeCoordinate c, out OffsetCoordinate o)
 {
     o.row = c.x;
     o.col = c.z + (c.x + (c.x & 1)) / 2;
 }
示例#8
0
 private static void CubeToPointyEven(ref HexCubeCoordinate c, out OffsetCoordinate o)
 {
     o.row = c.z;
     o.col = c.x + (c.z + (c.z & 1)) / 2;
 }
示例#9
0
 public void Neighbours(ref HexCubeCoordinate coordinate, List <HexCell> neighbours)
 {
     CellAt(ref coordinate, out var cell);
     Neighbours(ref cell, neighbours);
 }
示例#10
0
    public void CellAt(int x, int z, out HexCell cell)
    {
        var c = new HexCubeCoordinate(x, z);

        CellAt(ref c, out cell);
    }
示例#11
0
 public void CellAt(ref HexCubeCoordinate coordinate, out HexCell cell)
 {
     grid.TryGetValue(coordinate.ToString(), out cell);
 }
示例#12
0
 public int Distance(HexCubeCoordinate a, HexCubeCoordinate b)
 {
     return(Mathf.Abs(a.x - b.x) + Mathf.Abs(a.y - b.y) + Mathf.Abs(a.z - b.z));
 }
示例#13
0
 public void CellsInRange(ref HexCubeCoordinate coordinate, int range, List <HexCell> neighbours)
 {
     CellAt(ref coordinate, out var cell);
     CellsInRange(ref cell, range, neighbours);
 }