Пример #1
0
 private NeighborIndices GetNeihborsFor(HexCenter hex, Dictionary <string, HexCenter> table)
 {
     return(new NeighborIndices()
     {
         NeighborA = GetOffsetHex(hex, 0, -1, table),
         NeighborB = GetOffsetHex(hex, -1, 0, table),
         NeighborC = GetOffsetHex(hex, -1, 1, table),
         NeighborD = GetOffsetHex(hex, 0, 1, table),
         NeighborE = GetOffsetHex(hex, 1, 0, table),
         NeighborF = GetOffsetHex(hex, 1, -1, table),
     });
 }
Пример #2
0
    private NeighborIndices[] GetNeighborsData()
    {
        NeighborIndices[] ret = new NeighborIndices[MaxIndex];
        Dictionary <string, HexCenter> indexTable = BaseHexs.ToDictionary(GetKey, item => item);

        for (int i = 0; i < MaxIndex; i++)
        {
            HexCenter       hex       = BaseHexs[i];
            NeighborIndices neighbors = GetNeihborsFor(hex, indexTable);
            ret[hex.Index] = neighbors;
        }
        return(ret);
    }
Пример #3
0
    private static uint GetOffsetHex(HexCenter hex, int rowOffset, int columnOffset, Dictionary <string, HexCenter> lookupTable)
    {
        int    newRow    = hex.Row + rowOffset;
        int    newColumn = hex.Column + columnOffset;
        string key       = GetKey(newRow, newColumn);

        if (lookupTable.ContainsKey(key))
        {
            HexCenter neighbor = lookupTable[key];
            return((uint)neighbor.Index);
        }
        return(0);
    }
Пример #4
0
    private Color GetMapValue(HexCenter hexCenter)
    {
        if (hexCenter == null || hexCenter.Index == 0)
        {
            return(Color.black);
        }

        int   red    = hexCenter.Index % 255;
        float redVal = (float)red / 255;

        int   green    = hexCenter.Index / 255;
        float greenVal = (float)green / 255;

        return(new Color(redVal, greenVal, 0));
    }
Пример #5
0
    private void MakeMap(IEnumerable <HexCenter> hexCenters)
    {
        HexTable table = new HexTable(hexCenters, _extents);

        for (int xIndex = 0; xIndex < _main.BaseTexture.width; xIndex++)
        {
            for (int yIndex = 0; yIndex < _main.BaseTexture.height; yIndex++)
            {
                HexCenter hexCenter  = table.GetHexCenter(xIndex, yIndex, _main.BaseTexture.width, _main.BaseTexture.height);
                Color     pixelColor = GetMapValue(hexCenter);
                _main.BaseTexture.SetPixel(xIndex, yIndex, pixelColor);
            }
        }
        _main.BaseTexture.Apply();
    }
Пример #6
0
        private HexCenter GetCenterFromCell(IEnumerable <HexCenter> cell, Vector2 pixelPos)
        {
            HexCenter ret     = null;
            float     minDist = float.PositiveInfinity;

            foreach (HexCenter center in cell)
            {
                float dist = (pixelPos - center.Position).magnitude;
                if (dist < minDist)
                {
                    ret     = center;
                    minDist = dist;
                }
            }
            return(ret);
        }
Пример #7
0
 private static string GetKey(HexCenter hex)
 {
     return(GetKey(hex.Row, hex.Column));
 }