Exemple #1
0
        public void generateHeightMap(Continent continent, double frequency, double persistence, double octaves, double amplitude)
        {
            continent.heightMap = new float[continent.size, continent.size];

            //generate heightmap from a modified perlin noise
            r1 = random.Next(1000, 10000);
            r2 = random.Next(100000, 1000000);
            r3 = random.Next(1000000000, 2000000000);

            for (int i = 0; i < continent.size; i++)
            {
                for (int j = 0; j < continent.size; j++)
                {
                    continent.heightMap[i, j] = (float)(Common.MAX_TERRAIN_HEIGHT * (PerlinNoise(i, j, frequency, persistence, octaves, amplitude)));
                }
            }
        }
Exemple #2
0
        public Continent generateContinent(int size)
        {
            Continent continent = new Continent();

            continent.size = size;

            //hard-coded; gotta change this as soon as
            //a good range of values is found:
            generateHeightMap(continent, 0.015, 0.65, 8, 1);
            generateTreeMap(continent, 0.015, 0.25, 3, 1);
            generateTemperatureMap(continent);
            generateTerrainMap(continent);
            //generateRivers(continent);

            //TODO: create other stuff here...

            return continent;
        }
Exemple #3
0
        public void generateRivers(Continent continent)
        {
            //get maximum height
            float maxHeight = 0;
            for (int i = 0; i < continent.size; i++)
            {
                for (int j = 0; j < continent.size; j++)
                {
                    if (continent.heightMap[i, j] > maxHeight)
                        maxHeight = continent.heightMap[i, j];
                }
            }

            //find number of fountains
            int fountains = Common.MAX_FOUNTAINS_PER_100 * (continent.size / 100);

            //find actual fountains
            continent.fountainsX = new int[fountains];
            continent.fountainsY = new int[fountains];
            int countFountains = 0;
            int newX, newY;
            while (countFountains < fountains)
            {
                newX = random.Next(20, continent.size - 20);
                newY = random.Next(20, continent.size - 20);
                if (continent.heightMap[newX, newY] >= maxHeight - 4 || continent.heightMap[newX, newY] < maxHeight - 2)
                {
                    continent.fountainsX[countFountains] = newX;
                    continent.fountainsY[countFountains] = newY;
                    countFountains++;
                }
            }

            //rivers
            int rivers = random.Next(1, fountains / 2);
            continent.riversList = new River[rivers];
            List<WaterMass> waterMassList = new List<WaterMass>();
            for (int i = 0; i < rivers; i++)
            {
                int maxWidth = random.Next(3, 9);
                int width = 1;
                int halfWidth = 1;
                int length = random.Next(50, 200);
                int x = continent.fountainsX[i];
                int y = continent.fountainsY[i];
                int dir = 5;
                bool lowerOrEqual = false;
                int[] point = new int[2];
                int[] center = new int[2];
                for (int j = 0; j < length; j++)
                {
                    lowerOrEqual = false;
                    bool []tested = new bool[8];
                    int increment = 1;
                    while (!lowerOrEqual)
                    {
                        if (x - increment <= 0 || x + increment >= continent.size || y - increment <= 0 || y + increment >= 0)
                        {
                            break;
                        }
                        dir++;
                        if (dir > 7) dir = 0;
                        else if (dir < 0) dir = 7;
                        switch (dir)
                        {
                            case 0:
                                tested[0] = true;
                                if (!tested[0] && x - increment > 0 && y - increment > 0)
                                {
                                    lowerOrEqual = continent.heightMap[x - increment, y - increment] <= continent.heightMap[x, y];
                                }
                                break;
                            case 1:
                                tested[1] = true;
                                if (!tested[1] && y - increment > 0)
                                {
                                    lowerOrEqual = continent.heightMap[x, y - increment] <= continent.heightMap[x, y];
                                }
                                break;
                            case 2:
                                tested[2] = true;
                                if (!tested[2] && x + increment < continent.size && y - increment > 0)
                                {
                                    lowerOrEqual = continent.heightMap[x + increment, y - increment] <= continent.heightMap[x, y];
                                }
                                break;
                            case 3:
                                tested[3] = true;
                                if (!tested[3] && x + increment < continent.size)
                                {
                                    lowerOrEqual = continent.heightMap[x + increment, y] <= continent.heightMap[x, y];
                                }
                                break;
                            case 4:
                                tested[4] = true;
                                if (!tested[4] && x + increment < continent.size && y + increment < continent.size)
                                {
                                    lowerOrEqual = continent.heightMap[x + increment, y + increment] <= continent.heightMap[x, y];
                                }
                                break;
                            case 5:
                                tested[5] = true;
                                if (!tested[5] && y + increment < continent.size)
                                {
                                    lowerOrEqual = continent.heightMap[x, y + increment] <= continent.heightMap[x, y];
                                }
                                break;
                            case 6:
                                tested[6] = true;
                                if (!tested[6] && x - increment > 0 && y + increment < continent.size)
                                {
                                    lowerOrEqual = continent.heightMap[x - increment, y + increment] <= continent.heightMap[x, y];
                                }
                                break;
                            case 7:
                                tested[7] = true;
                                if (!tested[7] && x - increment > 0)
                                {
                                    lowerOrEqual = continent.heightMap[x - increment, y] <= continent.heightMap[x, y];
                                }
                                break;
                            default: lowerOrEqual = false; break;
                        }

                        if (!lowerOrEqual && tested[0] && tested[1] && tested[2] && tested[3] && tested[4] && tested[5] && tested[6] && tested[7])
                        {
                            tested = new bool[8];
                            increment++;
                        }
                    }
                    switch (dir)
                    {
                        //up+left
                        case 0:
                            x--;
                            y--;
                            if (x > 0 && y > 0)
                            {
                                x += (x > 0 ? random.Next(-1, 2) : 0);
                                y += (y > 0 ? random.Next(-1, 2) : 0);
                            }
                            break;

                        //up
                        case 1:
                            y--;
                            if (y > 0)
                            {
                                x += (x > 0 ? random.Next(-1, 2) : 0);
                            }
                            break;

                        //up+right
                        case 2:
                            x++;
                            y--;
                            if (x < continent.size && y > 0)
                            {
                                x += (x > 0 ? random.Next(-1, 2) : 0);
                                y += (y > 0 ? random.Next(-1, 2) : 0);
                            }
                            break;

                        //right
                        case 3:
                            x++;
                            if (x < continent.size)
                            {
                                y += (y > 0 ? random.Next(-1, 2) : 0);
                            }
                            break;

                        //down+right
                        case 4:
                            x++;
                            y++;
                            if (x < continent.size && y < continent.size)
                            {
                                x += (x > 0 ? random.Next(-1, 2) : 0);
                                y += (y > 0 ? random.Next(-1, 2) : 0);
                            }
                            break;

                        //down
                        case 5:
                            y++;
                            if (y < continent.size)
                            {
                                x += (x > 0 ? random.Next(-1, 2) : 0);
                            }
                            break;

                        //down+left
                        case 6:
                            x--;
                            y++;
                            if (x > 0 && y < continent.size)
                            {
                                x += (x > 0 ? random.Next(-1, 2) : 0);
                                y += (y > 0 ? random.Next(-1, 2) : 0);
                            }
                            break;

                        //left
                        case 7:
                            x--;
                            if (x > 0)
                            {
                                y += (y > 0 ? random.Next(-1, 2) : 0);
                            }
                            break;

                        default: break;
                    }

                    //fill width-wise
                    center[0] = x;
                    center[1] = y;
                    int radius = 1;
                    while (radius < halfWidth)
                    {
                        for (int angle = 0; angle < 360; angle++)
                        {
                            point = getCircleCoordinate(center, halfWidth, angle);
                            if (point[0] > 0 && point[0] < continent.size && point[1] > 0 && point[1] < continent.size)
                            {
                                continent.heightMap[point[0], point[1]]--;
                            }
                        }
                        radius++;
                    }

                    WaterMass watermass = new WaterMass();
                    watermass.x = center[0];
                    watermass.y = center[1];
                    watermass.radius = halfWidth;
                    watermass.dir = dir;
                    watermass.depth = 1; //TODO: add dynamic depth

                    waterMassList.Add(watermass);

                    if (width < maxWidth)
                        width = Math.Max(1, j / 10);
                    halfWidth = width / 2;
                }

                //put a lake at the end:
                int maxLakeRadius = random.Next(Common.MIN_LAKE_WIDTH, Common.MAX_LAKE_WIDTH);
                int lakeRadius = 1;
                center = new int[2];
                center[0] = x;
                center[1] = y;
                while (lakeRadius < maxLakeRadius)
                {
                    for (int angle = 0; angle < 360; angle++)
                    {
                        point = new int[2];
                        point = getCircleCoordinate(center, lakeRadius, angle);
                        if (point[0] > 0 && point[0] < continent.size && point[1] > 0 && point[1] < continent.size)
                        {
                            continent.heightMap[point[0], point[1]]--;
                        }
                    }
                    lakeRadius++;
                }

                WaterMass lake = new WaterMass();
                lake.x = center[0];
                lake.y = center[1];
                lake.radius = lakeRadius;
                lake.dir = dir;
                lake.depth = 1; //TODO: add dynamic depth

                waterMassList.Add(lake);

                continent.riversList[i] = new River();
                continent.riversList[i].points = waterMassList.Count;
                continent.riversList[i].waterPoints = new WaterMass[continent.riversList[i].points];
                int pos = 0;
                foreach (WaterMass w in waterMassList)
                {
                    continent.riversList[i].waterPoints[pos] = new WaterMass();
                    continent.riversList[i].waterPoints[pos].depth = w.depth;
                    continent.riversList[i].waterPoints[pos].dir = w.dir;
                    continent.riversList[i].waterPoints[pos].radius = w.radius;
                    continent.riversList[i].waterPoints[pos].x = w.x;
                    continent.riversList[i].waterPoints[pos].y = w.y;
                    pos++;
                }
            }

            //coastline
            //top:
            int seaLine = random.Next(5, 10);
            for (int i = 0; i < continent.size; i++)
            {
                seaLine = Math.Max(5, seaLine + random.Next(-1, 2));
                int it = seaLine;
                while (it >= 0)
                {
                    continent.heightMap[i, it]--;
                    it--;
                }
            }

            //bottom:
            seaLine = random.Next(5, 10);
            for (int i = 0; i < continent.size; i++)
            {
                seaLine = Math.Max(5, seaLine + random.Next(-1, 2));
                int it = continent.size - seaLine;
                while (it < continent.size)
                {
                    continent.heightMap[i, it]--;
                    it++;
                }
            }

            //left:
            seaLine = random.Next(5, 10);
            for (int i = 0; i < continent.size; i++)
            {
                seaLine = Math.Max(5, seaLine + random.Next(-1, 2));
                int it = seaLine;
                while (it >= 0)
                {
                    continent.heightMap[it, i]--;
                    it--;
                }
            }

            //right:
            seaLine = random.Next(5, 10);
            for (int i = 0; i < continent.size; i++)
            {
                seaLine = Math.Max(5, seaLine + random.Next(-1, 2));
                int it = continent.size - seaLine;
                while (it < continent.size)
                {
                    continent.heightMap[it, i]--;
                    it++;
                }
            }
        }
Exemple #4
0
        public void generateTerrainMap(Continent continent)
        {
            continent.terrainMap = new int[continent.size, continent.size];

            //generate terrain map from the other 2 + river areas
            r1 = random.Next(1000, 10000);
            r2 = random.Next(100000, 1000000);
            r3 = random.Next(1000000000, 2000000000);

            for (int i = 0; i < continent.size; i++)
            {
                for (int j = 0; j < continent.size; j++)
                {
                    //still hard-coded, gotta get around to change this:
                    continent.terrainMap[i, j] = Math.Max(0, (int)(7 * PerlinNoise(i, j, 0.015, 0.35, 8, 1)));
                }
            }
        }
Exemple #5
0
        public void generateTemperatureMap(Continent continent)
        {
            continent.temperatureMap = new float[continent.size, continent.size];

            //generate temperature map
            r1 = random.Next(1000, 10000);
            r2 = random.Next(100000, 1000000);
            r3 = random.Next(1000000000, 2000000000);

            for (int i = 0; i < continent.size; i++)
            {
                for (int j = 0; j < continent.size; j++)
                {
                    //hard-coded for now:
                    continent.temperatureMap[i, j] = (float)(Common.MAX_TEMPERATURE * (PerlinNoise(i, j, 0.015, 0.35, 8, 1) + 0.5));
                }
            }
        }
Exemple #6
0
        protected override void LoadContent()
        {
            device = GraphicsDevice;

            clients = new List<dummy>();

            serverPort = 8888;

            p = gp(0);

            if (serverName.Length > 0 && nick.Length > 0)
            {
                try
                {
                    connect();
                }
                catch (Exception ex)
                {
                }

                if (connected)
                {
                    while (serverSeed == 0) ;
                    sendTimer = new System.Windows.Forms.Timer();
                    sendTimer.Tick += new EventHandler(sendTimer_Tick);
                    sendTimer.Interval = 20;
                    sendTimer.Start();
                }
            }
            else
            {
                serverSeed = Math.Abs((int)DateTime.Now.Ticks);
            }

            this.Window.Title = "MIGETGame test (seed: " + serverSeed + ")";

            wg = new WorldGenerator(serverSeed);

            continent = wg.generateContinent(continentSize);
            //overriden, for test purposes:
            wg.generateHeightMap(continent, 0.010, 0.55, 4, 1);
            wg.filterMap(continent.heightMap, 1);

            effect = Content.Load<Effect>("effects");
            bbEffect = Content.Load<Effect>("bbEffect");
            UpdateViewMatrix();
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.3f, 1000.0f);

            Mouse.SetPosition(device.Viewport.Width / 2, device.Viewport.Height / 2);
            originalMouseState = Mouse.GetState();

            skyDome = Content.Load<Model>("skyDome"); skyDome.Meshes[0].MeshParts[0].Effect = effect.Clone(device);
            PresentationParameters pp = device.PresentationParameters;
            refractionRenderTarget = new RenderTarget2D(device, pp.BackBufferWidth, pp.BackBufferHeight, 1, device.DisplayMode.Format);
            reflectionRenderTarget = new RenderTarget2D(device, pp.BackBufferWidth, pp.BackBufferHeight, 1, device.DisplayMode.Format);
            cloudsRenderTarget = new RenderTarget2D(device, pp.BackBufferWidth, pp.BackBufferHeight, 1, device.DisplayMode.Format);

            LoadVertices();
            LoadTextures();

            m_SpriteBatch = new SpriteBatch(this.GraphicsDevice);
            m_SpriteFont = Content.Load<SpriteFont>("Arial");

            if (drawTrees)
            {
                treeThread = new System.Windows.Forms.Timer();
                treeThread.Tick += new EventHandler(CreateTreeBillboardVerticesFromList);
                treeThread.Interval = 250;
                treeThread.Start();
            }

            if (drawGrass)
            {
                grassThread = new System.Windows.Forms.Timer();
                grassThread.Tick += new EventHandler(CreateGrassBillboardVerticesFromList);
                grassThread.Interval = 250;
                grassThread.Start();
            }

            cameraPosition = new Vector3(0, continent.heightMap[(int)cameraPosition.X, (int)cameraPosition.Z] + 1.2f, 0);
        }