/// <summary> /// 柏林噪声产生地形数据, /// </summary> private void GenerateTerrain() { var perlin = new CPerlinMap(m_numCols, m_numRows); perlin.Generate(); //处理高地 //存储高地的数据 //1代表是高地, 0代表高地被平了 int[,] hillGrid = new int[m_numCols, m_numRows]; var type = (int)CPCGLayer.Terrain; for (int x = 0; x < m_numCols; x++) { for (int z = 0; z < m_numRows; z++) { CForestTerrainSubType subType = GetSubTypeAtHeight(perlin[x, z]); m_grid.FillData(x, z, type, (int)subType, CForestUtil.GetTerrainTypeWalkable(subType)); hillGrid[x, z] = 0; if (subType == CForestTerrainSubType.Hill) { hillGrid[x, z] = 1; } } } m_cell.SmoothOnce(hillGrid); var hillType = (int)CForestTerrainSubType.Hill; var landType = (int)CForestTerrainSubType.Land1; m_floodFill.Process(hillGrid, 11, 1, 0); //将处理过后的数据返还给assets for (int x = 0; x < m_numCols; x++) { for (int z = 0; z < m_numRows; z++) { var subType = m_grid.GetNodeSubType(x, z); if (subType == hillType && hillGrid[x, z] == 0) { m_grid.FillData(x, z, type, landType, true); } } } }
public static bool CanPlacePropsOnTerrainType(CForestTerrainSubType subType) { bool v = false; switch (subType) { case CForestTerrainSubType.Grass1: case CForestTerrainSubType.Grass2: case CForestTerrainSubType.Land1: case CForestTerrainSubType.Land2: v = true; break; case CForestTerrainSubType.Road: case CForestTerrainSubType.Hill: case CForestTerrainSubType.Pond: v = false; break; } return(v); }
public static bool GetTerrainTypeWalkable(CForestTerrainSubType subType) { bool v = false; switch (subType) { case CForestTerrainSubType.Grass1: case CForestTerrainSubType.Grass2: case CForestTerrainSubType.Land1: case CForestTerrainSubType.Land2: case CForestTerrainSubType.Road: v = true; break; case CForestTerrainSubType.Hill: case CForestTerrainSubType.Pond: v = false; break; } return(v); }