Exemplo n.º 1
0
        public static bbLoc CubeToSquare(bbLoc cubeLoc)
        {
            float x = cubeLoc.z();
            float y = cubeLoc.x() + (cubeLoc.z() - (cubeLoc.z() % 2f)) / 2;

            return(new bbLoc(x, y));
        }
Exemplo n.º 2
0
 public bbPos(bbLoc _loc, BaseBuilderMVP _game)
 {
     gridLoc = _loc;
     game    = _game;
     setMapLoc(game.tileShape);
     neighbors = new List <bbPos>();
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        public void AddStructure(bbStructureType t, float x, float y, ClickType _clickType)
        {
            bbLoc       l = new bbLoc(x, y);
            bbStructure s = bbStructureFactory.GenerateStructure(t, pathMap[l.key()], _clickType);

            structures[s.getPos()] = s;
            //Debug.Log("Added Structure at " + s.getPos().getName());
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
0
        private Dictionary <string, bbPos> Generate2DGrid(int _dim)
        {
            Dictionary <string, bbPos> map = new Dictionary <string, bbPos>();

            for (int x = 0; x < _dim; x++)
            {
                for (int y = 0; y < _dim; y++)
                {
                    bbLoc l = new bbLoc(x, y);
                    bbPos p = new bbPos(l, game);
                    map[p.gridLoc.key()] = p;
                }
            }

            return(map);
        }