Esempio n. 1
0
        public void setMapLoc(TileShape _tileShape)
        {
            switch (_tileShape)
            {
            case TileShape.SQUARE:
                mapLoc = new bbLoc(gridLoc.coordinates);
                break;

            case TileShape.HEX:
                float x = Mathf.Sqrt(3) * (gridLoc.x() - 0.5f * (gridLoc.y() % 2f)) / 1.9f;
                float y = (3 / 2) * gridLoc.y() / 1.3f;
                mapLoc = new bbLoc(x, y);
                break;
            }
        }
Esempio n. 2
0
        List <bbPos> SetNeighborsSquare(bbPos p, Dictionary <string, bbPos> map, int _dim, bool _wrapEastWest = false, bool _wrapNorthSouth = false)
        {
            float        x         = p.gridLoc.x();
            float        y         = p.gridLoc.y();
            List <bbPos> neighbors = new List <bbPos>();

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if (i != 0 || j != 0)
                    {
                        float X = _wrapEastWest ? (_dim + x + i) % _dim : x + i;
                        float Y = _wrapNorthSouth ? (_dim + y + j) % _dim : y + j;

                        bbLoc l2 = new bbLoc(X, Y);
                        if (map.ContainsKey(l2.key()))
                        {
                            neighbors.Add(map[l2.key()]);
                        }
                        else
                        {
                            Debug.Log("Map doesn't contain " + l2.x() + "," + l2.y());
                        }
                    }
                }
            }
            return(neighbors);
        }
Esempio n. 3
0
        public static bbLoc SquareToCube(bbLoc squareLoc)
        {
            float x = squareLoc.y() - (squareLoc.x() - (squareLoc.x() % 2f)) / 2f;
            float z = squareLoc.x();
            float y = -x - z;

            return(new bbLoc(x, y, z));
        }
Esempio n. 4
0
        List <bbPos> SetNeighborsHex(bbPos p, Dictionary <string, bbPos> map, int _dim, bool _wrapEastWest = false, bool _wrapNorthSouth = false)
        {
            List <bbPos> neighbors = new List <bbPos>();

            List <int[]> hexNeighbors = new List <int[]>();

            if (p.gridLoc.y() % 2 == 0)
            {
                hexNeighbors.Add(new int[] { 1, 0 });
                hexNeighbors.Add(new int[] { 1, -1 });
                hexNeighbors.Add(new int[] { 0, -1 });
                hexNeighbors.Add(new int[] { -1, 0 });
                hexNeighbors.Add(new int[] { 0, 1 });
                hexNeighbors.Add(new int[] { 1, 1 });
            }
            else
            {
                hexNeighbors.Add(new int[] { 1, 0 });
                hexNeighbors.Add(new int[] { -1, -1 });
                hexNeighbors.Add(new int[] { 0, -1 });
                hexNeighbors.Add(new int[] { -1, 0 });
                hexNeighbors.Add(new int[] { 0, 1 });
                hexNeighbors.Add(new int[] { -1, 1 });
            }


            float x = p.gridLoc.x();
            float y = p.gridLoc.y();

            for (int k = 0; k < hexNeighbors.Count; k++)
            {
                int   i = hexNeighbors[k][0];
                int   j = hexNeighbors[k][1];
                float X = _wrapEastWest ? (_dim + x + i) % _dim : x + i;
                float Y = _wrapNorthSouth ? (_dim + y + j) % _dim : y + j;

                bbLoc l2 = new bbLoc(X, Y);
                if (map.ContainsKey(l2.key()))
                {
                    neighbors.Add(map[l2.key()]);
                }
                else
                {
                    Debug.Log("Map doesn't contain " + l2.x() + "," + l2.y());
                }
            }

            return(neighbors);
        }