Exemple #1
0
        /*地图中随机一个位置*/
        public static Vector2Int FindRandomNodeLocation(int maxCol, int maxRow)
        {
            int row = CDarkRandom.Next(0, maxRow);
            int col = CDarkRandom.Next(0, maxCol);

            return(new Vector2Int(col, row));
        }
        /// <summary>
        /// 寻找一个可同行的地块.
        /// </summary>
        /// <returns>The walkable tile.</returns>
        public Vector3 FindWalkableTile()
        {
            int times = 10;

            while (times > 0)
            {
                int col = CDarkRandom.Next(m_mapWalkableData.NumCols);
                int row = CDarkRandom.Next(m_mapWalkableData.NumRows);
                if (IsWalkable(col, row))
                {
                    return(new Vector3(col, 0, row));
                }
                times--;
            }

            for (int c = 0; c < m_mapWalkableData.NumCols; c++)
            {
                for (int r = 0; r < m_mapWalkableData.NumRows; r++)
                {
                    if (IsWalkable(c, r))
                    {
                        return(new Vector3(c, 0, r));
                    }
                }
            }

            return(Vector3.zero);
        }
Exemple #3
0
        private void GeneratePond()
        {
            if (MaxPondNum <= 0)
            {
                return;
            }
            int num = CDarkRandom.Next(MaxPondNum + 1);

            if (num <= 0)
            {
                return;
            }

            //池塘的相关配置
            var type     = (int)CPCGLayer.Terrain;
            var subType  = CForestTerrainSubType.Pond;
            var walkable = CForestUtil.GetTerrainTypeWalkable(subType);

            CPondGenerator p        = new CPondGenerator();
            int            pondCols = CDarkRandom.Next(16, 32);
            int            pondRows = CDarkRandom.Next(16, 32);
            int            leftCols = m_numCols - pondCols;
            int            leftRows = m_numRows - pondRows;
            Vector2Int     size     = new Vector2Int(pondCols, pondRows);

            for (int i = 0; i < num; i++)
            {
                int startX = CDarkRandom.Next(0, leftCols);
                int startZ = CDarkRandom.Next(0, leftRows);
                var ponds  = p.Generate(size);

                //活着的是池塘
                for (int x = 0; x < pondCols; x++)
                {
                    for (int z = 0; z < pondRows; z++)
                    {
                        if (ponds[x, z] < 1)
                        {
                            continue;
                        }
                        m_grid.FillData(startX + x, startZ + z, type, (int)subType, walkable);
                    }
                }
            }
        }
        //路标, 大块石头, 路灯等
        public void CreateDecoration(int decoBlockNum, CAssetGrid walkGrid, CAssetGrid typeGrid, CAssetGrid assetGrid)
        {
            string name;

            //添加阻碍装饰物
            for (int i = 0; i < decoBlockNum; ++i)
            {
                int col = CDarkRandom.Next(_numCols);
                int row = CDarkRandom.Next(_numRows);
                if (!walkGrid.IsWalkable(col, row))
                {
                    continue;
                }

                walkGrid.SetWalkable(col, row, false);

                int nameIndex = CDarkRandom.Next(1, 6);
                name = string.Format("Preb_Deco_Block_00{0}", nameIndex);
                //assetGrid.SetName(row, col, name);
            }
        }
        public void CreateDecal(string decalNameRoot, int decalStartIndex, CAssetGrid walkGrid, CAssetGrid typeGrid, CAssetGrid assetGrid)
        {
            string name;

            //添加贴花
            for (int i = 0; i < 30; ++i)
            {
                int col = CDarkRandom.Next(_numCols);
                int row = CDarkRandom.Next(_numRows);
                //if(typeGrid.IsSpecial(row, col))continue;
                if (!walkGrid.IsWalkable(row, col))
                {
                    continue;
                }

                //typeGrid.SetType(row, col, (int)RayConst.TileType.DECAL);

                int nameIndex = CDarkRandom.Next(decalStartIndex, decalStartIndex + 5);
                name = string.Format("{0}{1}", decalNameRoot, nameIndex);
                //assetGrid.SetName(row, col, name);
            }
        }
        //创建可以销毁的障碍物. 比如说坦克大战和炸弹人的地块
        public void CreateDestroyBlock(int decoDestroyNum, CAssetGrid walkGrid, CAssetGrid typeGrid, CAssetGrid assetGrid)
        {
            string name;

            //添加阻碍装饰物
            for (int i = 0; i < decoDestroyNum; ++i)
            {
                int col = CDarkRandom.Next(_numCols);
                int row = CDarkRandom.Next(_numRows);
                //if(typeGrid.IsSpecial(row, col))continue;
                if (!walkGrid.IsWalkable(row, col))
                {
                    continue;
                }

                //typeGrid.SetType(row, col, (int)RayConst.TileType.DECO_DESTROY);
                walkGrid.SetWalkable(row, col, false);

                //5个里面随机一个
                int nameIndex = CDarkRandom.Next(1, 6);
                name = string.Format("Preb_Deco_Destroy_00{0}", nameIndex);
                //assetGrid.SetName(row, col, name);
            }
        }