Пример #1
0
    // algorithm obtained from Red Blobs Games' Hexagons blog: http://www.redblobgames.com/grids/hexagons/
    public List <HexTile> GetHexRing(HexTile Center, int Radius)
    {
        // reduce the radius to match our numerical system.
        Radius -= 1;

        List <HexTile> RetList = new List <HexTile>();

        if (Radius == 0)
        {
            RetList.Add(Center);
            return(RetList);
        }

        HexTransform CurrentLoc = new HexTransform(Center.hexTransform.Position);

        CurrentLoc.Position += Radius * HexCubeDirections[4];

        for (int i = 0; i < 6; ++i)
        {
            for (int j = 0; j < Radius; ++j)
            {
                if (CurrentLoc.validateOddQ())
                {
                    RetList.Add(MapGenerator.Map[(int)CurrentLoc.RowColumn.x, (int)CurrentLoc.RowColumn.y]);
                }
                CurrentLoc.Position += HexCubeDirections[i];
            }
        }

        return(RetList);
    }
Пример #2
0
    public int GetConnections()
    {
        ASI.Connections.Clear();
        HexTransform testCon = new HexTransform(0, 0);

        testCon = testCon.CubetoOddQ(hexTransform.Position.x + 1, hexTransform.Position.y, hexTransform.Position.z - 1);
        if (testCon.validateOddQ())
        {
            ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI);
        }

        testCon = testCon.CubetoOddQ(hexTransform.Position.x + 1, hexTransform.Position.y, hexTransform.Position.z);
        if (testCon.validateOddQ())
        {
            ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI);
        }

        testCon = testCon.CubetoOddQ(hexTransform.Position.x, hexTransform.Position.y, hexTransform.Position.z + 1);
        if (testCon.validateOddQ())
        {
            ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI);
        }

        testCon = testCon.CubetoOddQ(hexTransform.Position.x - 1, hexTransform.Position.y, hexTransform.Position.z + 1);
        if (testCon.validateOddQ())
        {
            ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI);
        }

        testCon = testCon.CubetoOddQ(hexTransform.Position.x - 1, hexTransform.Position.y, hexTransform.Position.z);
        if (testCon.validateOddQ())
        {
            ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI);
        }

        testCon = testCon.CubetoOddQ(hexTransform.Position.x, hexTransform.Position.y, hexTransform.Position.z - 1);
        if (testCon.validateOddQ())
        {
            ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI);
        }

        return(ASI.Connections.Count);
    }