Exemplo n.º 1
0
        protected override Map makeMap()
        {
            Map worldMap = new Map(sizeY, sizeX);

            //make dict of biomes
            biomeList = new Dictionary <string, MapTileType>();
            MapTileType water = new MapTileType("water", Brushes.Blue);

            water.makeUnpassable();
            biomeList.Add("water", water);
            biomeList.Add("grassland", new MapTileType("grassland", Brushes.Lime));
            biomeList.Add("forest", new MapTileType("forest", Brushes.Green));
            biomeList.Add("desert", new MapTileType("desert", Brushes.Yellow));
            biomeList.Add("snowy_plains", new MapTileType("snowy plains", Brushes.White));
            biomeList.Add("mountain", new MapTileType("mountain", Brushes.Brown));

            //some reasonable value examples are 0.1 for 50 with 9 types, 0.05 for 100,
            NoiseGenerator noiseGen = new NoiseGenerator(0.035f);


            //DEFINE ELEVATION
            Stopwatch stopwatch = Stopwatch.StartNew(); //creates and start the instance of Stopwatch

            //your sample code
            elevationGrid = new float[sizeY, sizeX];
            for (int row = 0; row < sizeY; row++)
            {
                for (int col = 0; col < sizeX; col++)
                {
                    float multiplier = 1.1f;
                    int   percent25  = sizeX / 5;

                    //making both sides the same halves the if statements
                    int distanceToVerticWall = row < sizeY / 2 ? row : sizeY - 1 - row;
                    int distanceToHorizWall  = col < sizeX / 2  ? col : sizeX - 1 - col;
                    //int distanceToVerticCenter = Math.Abs(sizeY / 2 - row);
                    //int distanceToHorizCenter  = Math.Abs(sizeX / 2 - col);

                    if (distanceToVerticWall == 0 || distanceToHorizWall == 0)
                    {
                        multiplier = 0;
                    }
                    else if (distanceToVerticWall < percent25)
                    {
                        if (distanceToHorizWall < percent25)
                        {
                            //corners
                            float distToPerc25Vert  = (float)(percent25 - distanceToVerticWall);
                            float distToPerc25Horiz = (float)(percent25 - distanceToHorizWall);
                            distToPerc25Vert  /= percent25;
                            distToPerc25Horiz /= percent25;
                            multiplier         = (float)Math.Max(1f - Math.Sqrt(distToPerc25Vert * distToPerc25Vert + distToPerc25Horiz * distToPerc25Horiz), 0f);
                        }
                        else
                        {
                            //top and bottom walls
                            multiplier = (float)(distanceToVerticWall) / percent25;
                        }
                    }
                    else if (distanceToHorizWall < percent25)
                    {
                        //left and right walls
                        multiplier = (float)(distanceToHorizWall) / percent25;
                    }

                    elevationGrid[row, col] = noiseGen.getOctaveRand(row + 1000, col + 1000, 1f, 4, 0.5f) * multiplier;
                }
            }

            //DEFINE PRECIPITATION
            percipitationGrid = new float[sizeY, sizeX];
            for (int row = 0; row < sizeY; row++)
            {
                for (int col = 0; col < sizeX; col++)
                {
                    float newRainValue = noiseGen.getOctaveRand(row + 2000, col + 2000);
                    percipitationGrid[row, col] = newRainValue;
                }
            }

            //DEFINE TEMPERATURE
            temperatureGrid = new float[sizeY, sizeX];
            for (int row = 0; row < sizeY; row++)
            {
                for (int col = 0; col < sizeX; col++)
                {
                    float newTempValue = noiseGen.getOctaveRand(row + 3000, col + 3000);
                    temperatureGrid[row, col] = newTempValue;
                }
            }

            //DEFINE FINAL BIOMES
            for (int row = 0; row < sizeY; row++)
            {
                for (int col = 0; col < sizeX; col++)
                {
                    //worldMap.map[row, col] = new MapTile(noiseGen.getOctaveRandInt(row, col, 9));
                    worldMap.map[row, col] = getMapTileForCell(row, col);
                }
            }

            stopwatch.Stop();
            Console.log("Time to make world: " + stopwatch.ElapsedMilliseconds + " ms");

            return(worldMap);
        }
 public MapTile(MapTileType _tileDef)
 {
     typeName     = _tileDef.typeName;
     tileColor    = _tileDef.primaryColor;
     isUnpassable = _tileDef.unpassable;
 }