Пример #1
0
    private void BuildBaseTerrain()
    {
        float noiseScale = 0.008f;

        for (int i = 0; i < PlanetSettings.worldSize.x; i++)
        {
            int genHeight = Mathf.FloorToInt(Utils.map(Noise.CalcPixel1D(i, noiseScale) * 1, 0, 256,
                                                       PlanetSettings.worldSize.y / 2 - 128, PlanetSettings.worldSize.y / 2 + (float)(128 * PlanetSettings.heightBoost)));
            GenHeight[i] = genHeight;
            for (int j = 0; j < PlanetSettings.worldSize.y; j++)
            {
                if (j > genHeight)
                {
                    blocks[i, j]   = Database.TileDatabase.TileDictionary["air"];
                    blocksBG[i, j] = Database.TileDatabase.TileDictionary["air"];
                }
                else if (j == genHeight)
                {
                    blocks[i, j]   = Database.TileDatabase.TileDictionary[PlanetSettings.surfaceTile];
                    blocksBG[i, j] = Database.TileDatabase.TileDictionary[PlanetSettings.surfaceTile];
                }
                else if (j < genHeight && j >= genHeight - 8)
                {
                    blocks[i, j]   = Database.TileDatabase.TileDictionary[PlanetSettings.middleTile];
                    blocksBG[i, j] = Database.TileDatabase.TileDictionary[PlanetSettings.middleTile];
                }
                else if (j < genHeight - 8)
                {
                    blocks[i, j]   = Database.TileDatabase.TileDictionary[PlanetSettings.undergroundTile];
                    blocksBG[i, j] = Database.TileDatabase.TileDictionary[PlanetSettings.undergroundTile];
                }
            }
        }
        for (int i = 0; i < PlanetSettings.worldSize.x; i++)
        {
            for (int j = 0; j < Utils.CHUNKHEIGHT * 2; j++)
            {
                blocks[i, j]   = Database.TileDatabase.TileDictionary["bedrock"];
                blocksBG[i, j] = Database.TileDatabase.TileDictionary["bedrock"];
            }
        }
    }
Пример #2
0
        public Map GenerateMap()
        {
            Config.PhysicalEnvironment.VoxelTypes.Add(Config.GroundVoxelType);

            Chunks = new Chunk[Config.MapWidth, Config.MapHeight];

            for (uint chunkI = 0; chunkI < Config.MapWidth; chunkI++)
            {
                for (uint chunkJ = 0; chunkJ < Config.MapHeight; chunkJ++)
                {
                    Chunk chunk = Chunks[chunkI, chunkJ] =
                        new Chunk(this, new Vector2f(chunkI * Config.ChunkSize, chunkJ * Config.ChunkSize));

                    for (uint voxelI = 0; voxelI < Config.ChunkSize; voxelI++)
                    {
                        float height = Noise.CalcPixel1D(
                            (int)((chunkI * Config.ChunkSize) + voxelI),
                            Config.HorizontalNoiseScale) * (Config.VerticalNoiseScale / 128f);

                        for (uint voxelJ = 0; voxelJ < Config.ChunkSize; voxelJ++)
                        {
                            bool isGround = (chunkJ * Config.ChunkSize) + voxelJ > height + Config.GroundLevel;

                            bool isFloating = Noise.CalcPixel2D(
                                (int)((chunkI * Config.ChunkSize) + voxelI),
                                (int)((chunkJ * Config.ChunkSize) + voxelJ),
                                Config.FloatingNoiseScale) / 128f
                                              < Config.FloatingNoiseThreshold;

                            chunk[voxelI, voxelJ] =
                                isGround || isFloating
                                    ? new Voxel(this, Config.GroundVoxelType)
                                    : new Voxel(this);
                        }
                    }
                }
            }

            return(this);
        }