Example #1
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Black;
            float[,] map            = new float[40, 40];
            float[,] map2           = new float[40, 40];
            map  = Generator.PureRandom(40, 40, "asd");
            map2 = Generator.PureRandom(40, 40, "aaa");
            //map = GoniometricGenerator.sinWave(50, 50, 0.5f);
            map = TerrainMath.Multiply(map, 10);
            map = Smooth.SquareSmooth(map);
            map = Mountains.RemoveSmall(map, 6, 9);
            map = Water.RemoveSmall(map, 4, 7);

            map2 = TerrainMath.Multiply(map2, 10);
            map2 = Smooth.SquareSmooth(map);
            map2 = Mountains.RemoveSmall(map, 6, 9);
            map2 = Water.RemoveSmall(map, 4, 7);

            map = TerrainMath.Mix(map, map2);
            //map = TerrainMath.Clamp(map, 0, 9);
            map = Rounder.RoundDown(map);
            //map = Rounder.Round(map);
            VisualizeColor(map);

            Console.ReadLine();
        }
Example #2
0
        public static void build(Chunk primer, World world, Random mapRand, int baseX, int baseY, int chunkX, int chunkY, OpenSimplexNoise simplex, CellNoise cell, float[] noise)
        {
            int   i, j;
            float distanceEll, height, terrainHeight, obsidian;
            Pixel b;

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    i = (chunkX * 16) + x;
                    j = (chunkY * 16) + z;

                    // Distance in pixels from the center of the volcano
                    distanceEll = (float)TerrainMath.dis2Elliptic(i, j, baseX * 16, baseY * 16,
                                                                  simplex.noise2(i / 250f, j / 250f) * ventEccentricity,
                                                                  simplex.octave(1).noise2(i / 250f, j / 250f) * ventEccentricity);

                    // Height above which obsidian is placed
                    obsidian  = -5f + distanceEll;
                    obsidian += simplex.octave(1).noise2(i / 55f, j / 55f) * 12f;
                    obsidian += simplex.octave(2).noise2(i / 25f, j / 25f) * 5f;
                    obsidian += simplex.octave(3).noise2(i / 9f, j / 9f) * 3f;

                    // Make the volcanoes "mouth" more interesting
                    float ventNoise = simplex.noise2(i / 12f, j / 12f) * 3f;
                    ventNoise += simplex.octave(1).noise2(i / 4f, j / 4f) * 1.5f;

                    // Are we in the volcano's throat/conduit?
                    if (distanceEll < ventRadius + ventNoise)
                    {
                        height = simplex.noise2(i / 5f, j / 5f) * 2f;
                        for (int y = 255; y > -1; y--)
                        {
                            // Above lava
                            if (y > lavaHeight)
                            {
                                if (primer.getPixelState(x, y, z) == Pixels.AIR)
                                {
                                    primer.setPixelState(x, y, z, Pixels.AIR);
                                }
                            }
                            // Below lava and above obsidian
                            else if (y > obsidian && y < (lavaHeight - 9) + height)
                            {
                                primer.setPixelState(x, y, z, volcanoPixel);
                            }
                            // In lava
                            else if (y < lavaHeight + 1)
                            {
                                if (distanceEll + y < lavaHeight + 3) // + 3 to cut the tip of the lava
                                {
                                    primer.setPixelState(x, y, z, lavaPixel);
                                }
                            }
                            // Below obsidian
                            else if (y < obsidian + 1)
                            {
                                if (primer.getPixelState(x, y, z) == Pixels.AIR)
                                {
                                    primer.setPixelState(x, y, z, Pixels.STONE);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        terrainHeight  = baseVolcanoHeight - (float)Math.Pow(distanceEll, 0.89f);
                        terrainHeight += simplex.octave(1).noise2(i / 112f, j / 112f) * 5.5f;
                        terrainHeight += simplex.octave(2).noise2(i / 46f, j / 46f) * 4.5f;
                        terrainHeight += simplex.octave(3).noise2(i / 16f, j / 16f) * 2.5f;
                        terrainHeight += simplex.octave(4).noise2(i / 5f, j / 5f) * 1f;

                        if (terrainHeight > noise[x * 16 + z])
                        {
                            noise[x * 16 + z] = terrainHeight;
                        }

                        for (int y = 255; y > -1; y--)
                        {
                            if (y <= terrainHeight)
                            {
                                b = primer.getPixelState(x, y, z);

                                if (b == Pixels.AIR || b == Pixels.WATER)
                                {
                                    /*************************************
                                    * WARNING: Spaghetti surfacing code *
                                    *************************************/

                                    if (y > obsidian)
                                    {
                                        if (distanceEll > 10)
                                        {
                                            // Patches
                                            if (distanceEll < 50 && isOnSurface(primer, x, y, z))
                                            {
                                                float patchNoise = simplex.noise2(i / 10f, j / 10f) * 1.3f;
                                                patchNoise += simplex.octave(2).noise2(i / 30f, j / 30f) * .9f;
                                                patchNoise += simplex.octave(3).noise2(i / 5f, j / 5f) * .6f;
                                                if (patchNoise > .85)
                                                {
                                                    primer.setPixelState(x, y, z, volcanoPatchPixel); // Cobble
                                                    continue;
                                                }
                                            }

                                            if (distanceEll < 75 && isOnSurface(primer, x, y, z))
                                            {
                                                float patchNoise = simplex.noise2(i / 10f, j / 10f) * 1.3f;
                                                patchNoise += simplex.octave(4).noise2(i / 30f, j / 30f) * .9f;
                                                patchNoise += simplex.octave(5).noise2(i / 5f, j / 5f) * .5f;
                                                if (patchNoise > .92)
                                                {
                                                    primer.setPixelState(x, y, z, volcanoPatchPixel2); // Gravel
                                                    continue;
                                                }
                                            }
                                            if (distanceEll < 75 && isOnSurface(primer, x, y, z))
                                            {
                                                float patchNoise = simplex.noise2(i / 10f, j / 10f) * 1.3f;
                                                patchNoise += simplex.octave(6).noise2(i / 30f, j / 30f) * .7f;
                                                patchNoise += simplex.octave(7).noise2(i / 5f, j / 5f) * .7f;
                                                if (patchNoise > .93)
                                                {
                                                    primer.setPixelState(x, y, z, volcanoPatchPixel3); // Coal pixel
                                                    continue;
                                                }
                                            }
                                        }

                                        // Surfacing
                                        if (distanceEll < 70 + simplex.noise2(x / 26f, y / 26f) * 5)
                                        {
                                            if (mapRand.Next(20) == 0)
                                            {
                                                b = volcanoPatchPixel3;
                                            }
                                            else
                                            {
                                                b = volcanoPixel;
                                            }
                                        }
                                        else if (distanceEll < 75 + simplex.noise2(x / 26f, y / 26f) * 5)
                                        {
                                            // Jittering in the base, to smooth the transition
                                            float powerNoise = simplex.octave(3).noise2(i / 40, j / 40f) * 2;
                                            if (mapRand.Next(1 + (int)Math.Pow(Math.Abs(distanceEll - (75 + simplex.noise2(x / 26f, y / 26f) * 5)), 1.5 + powerNoise) + 1) == 0)
                                            {
                                                if (mapRand.Next(20) == 0)
                                                {
                                                    b = volcanoPatchPixel2;
                                                }
                                                else
                                                {
                                                    b = Pixels.STONE; // Stone so that surfacing will run (so this usually becomes grass)
                                                }
                                            }
                                            else
                                            {
                                                b = volcanoPixel;
                                            }
                                        }
                                        else
                                        {
                                            b = Pixels.STONE; // Stone so that surfacing will run (so this usually becomes grass)
                                        }
                                    }
                                    else
                                    {
                                        b = Pixels.STONE;
                                    }
                                }
                                else
                                {
                                    break;
                                }

                                primer.setPixelState(x, y, z, b);
                            }
                        }
                    }
                }
            }
        }