Beispiel #1
0
        public static World CalculateWaterDistance(World world)
        {
            for (int x = 0; x < world.width; x++)
            {
                for (int y = 0; y < world.height; y++)
                {
                    int seek = 10;
                    int dist = seek;
                    BiomeType type = world.GetBiomeAt(x, y).type;

                    int fromX = Math.Max(0, x - seek);
                    int toX = Math.Min(world.width - 1, x + seek);
                    int fromY = Math.Max(0, y - seek);
                    int toY = Math.Min(world.height - 1, y + seek);

                    for (int dx = fromX; dx <= toX; dx++)
                    {
                        for (int dy = fromY; dy <= toY; dy++)
                        {
                            if (world.GetBiomeAt(dx, dy).type != type)
                            {
                                dist = Math.Min(dist, Math.Abs(x - dx) + Math.Abs(y - dy));
                            }
                        }
                    }

                    world.SetCustomMap(x, y, Map.WATER_DISTANCE, (float)dist);
                }
            }

            return world;
        }
Beispiel #2
0
        public static World CreateHeightMap(World world)
        {
            float seaLevel = 0;

            for (int x = 0; x < world.width; x++)
            {
                for (int y = 0; y < world.height; y++)
                {
                    if (world.GetBiomeAt(x, y).type == BiomeType.LAND)
                    {
                        world.SetHeightMapAt(x, y, seaLevel + 0.1f * world.GetWaterDistanceAt(x, y));
                    }
                    else
                    {
                        world.SetHeightMapAt(x, y, seaLevel - 0.1f * world.GetWaterDistanceAt(x, y));
                    }
                }
            }

            return world;
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap bmp = new Bitmap(512, 512);
            richTextBox1.Text = "Starting Worldgen\n";

            World world = new World(512, 512) { width = 512, height = 512, topology = Topology.EUCLIDEAN };
            world.Generate(LogProgress);

            LogProgress("Generation done\nNow creating image\n");
            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, world.GetColorAt(x, y));
                }
            }

            LogProgress("Image created\nNow printing output\n");
            pictureBox1.Image = bmp;
            pictureBox1.Refresh();
        }
Beispiel #4
0
        public static World DetermineLandWater(World world)
        {
            var noise = new OpenSimplexNoise();
            float scale = 50;

            for (int x = 0; x < world.width; x++)
            {
                for (int y = 0; y < world.height; y++)
                {
                    if (noise.Evaluate(x / scale, y / scale) >= 0.15f)
                    {
                        world.SetBiomeAt(x, y, BiomeType.LAND);
                    }
                    else
                    {
                        world.SetBiomeAt(x, y, BiomeType.WATER);
                    }
                }
            }

            return world;
        }