Пример #1
0
        public void Init()
        {
            Data = new Node[2][,];
            Data[0] = new Node[X, Y];
            Data[1] = new Node[X, Y];

            ForeGround = Data[0];

            int i3 = 50;
            for (int i1 = 0; i1 < X; i1++)
            {
                double x = i1 / Size.X;

                double noise = Noise.NextOctave1D(1, x, 2.5f) / 5 + 0.5f;
                double noise3 = Math.Abs(Noise.NextOctave1D(2, x, 2.5f));
                double noise2 = Math.Abs(Noise.NextOctave1D(3, x, noise3)) / 10;

                noise = MathHelper.Clamp((float)(noise + noise2* noise3), 0, 1);

                i3 = (int)(noise * (Y - 1));

                if (i3 < 3) i3 = 3;

                var node = new Node
                {
                    Value = noise,

                };

                node.SetPosition(new Vector3(i1, i3, 0));
                node.SetType( NodeFactory.Get(NodeTypes.Soil));

                ForeGround[i1, i3] = node;

                for (int i2 = 0; i2< i3 - 3; i2++)
                {
                    double y = i2 * 1.0 / i3;
                    noise = 1 - Noise.NextOctave2DAbs(4, x, y) / 4;
                    node = new Node
                    {
                        Value = noise,
                    };

                    node.SetPosition(new Vector3(i1, i2, 0));

                    if (noise > 0.6f && noise < 0.7f && i2 < 20)
                    {
                        node.SetType(NodeFactory.Get(NodeTypes.EarthBack));
                        node.SetType(NodeFactory.Get(NodeTypes.Lava));
                    }
                    else
                        node.SetType(NodeFactory.Get(noise < 0.7f ? NodeTypes.Earth : NodeTypes.EarthBack));

                    ForeGround[i1, i2] = node;
                }

                for (int i2 = i3 - 3; i2 < i3; i2++)
                {
                    node = new Node
                    {
                        Value = noise,
                    };
                    node.SetPosition(new Vector3(i1, i2, 0));
                    node.SetType(NodeFactory.Get(NodeTypes.EarthBack));
                    node.SetType(NodeFactory.Get(NodeTypes.Soil));

                    ForeGround[i1, i2] = node;
                }

                for (int i2 = i3 + 1; i2 < Y; i2++)
                {
                    double y = i2 / Size.Y;
                    noise = Noise.NextOctave2DAbs(2, -x, -y);
                    node = new Node
                    {
                        Value = noise,
                    };
                    node.SetPosition(new Vector3(i1, i2, 0));
                    node.SetType(NodeFactory.Get(NodeTypes.Air, false));

                    ForeGround[i1, i2] = node;
                }
            }
            components = new List<IMapComponent> {lighting, /*new Clouds(),*/ new WaterSimulator(), new TextureModifier() };
            foreach (var component in components)
                component.Init(ForeGround, X, Y);
            new StructureGen().Init(ForeGround, X, Y);
        }