Пример #1
0
        private void plotTerrain(Terrain terrain,
            int minPercent, int maxPercent,
            int polygonLow, int polygonHigh)
        {
            int mininum = (WalkableTiles * minPercent) / 100;
            int maximum = (WalkableTiles * maxPercent) / 100;
            while (terrain.Count < mininum)
            {
                int centerX = getRandomXInsideIsland();
                int centerY = getRandomYInsideIsland();

                Polygon polygon = new RadialCirclePolygon(centerX, centerY,
                                                          polygonLow, polygonHigh);

                terraformIfInside(grass, terrain, maximum, polygon);
            }
        }
Пример #2
0
        /// <summary>
        /// This function turns the square map entirely made out of grass into an island,
        /// which is roughly square, but not completely.
        /// </summary>
        private void createMainIsland()
        {
            int size = (int)mapSize;
            int minGrassTerrains = (int)(mapSize);
            minGrassTerrains = minGrassTerrains * minGrassTerrains;

            while (grass.Count < minGrassTerrains)
            {
                // Creates a jagged polygon (see RadialCirclePolygon), rougly centered around (0,0).
                // Everything inside this polygon is turned into grass.
                int range = size / 2;
                double xc = RandomAid.NextFloatInRange(-range, range);
                double yc = RandomAid.NextFloatInRange(-range, range);
                double minimumRadius = size * 0.1;
                double maximumRadius = size * 0.3;
                Polygon polygon = new RadialCirclePolygon(xc, yc,
                                                          minimumRadius, maximumRadius);

                // Check each tile to see if it's outside the polygon.
                // First we check all the tiles in the outer layer.
                // Then the ones in the layer inside that, and so on.
                // So if we we reach maxGrassTerrains too fast, then
                // the water will be evenly distributed around the map.
                for (int y = (int)polygon.TopBound(); y <= polygon.BottomBound(); y++)
                {
                    for (int x = (int)polygon.LeftBound(); x <= polygon.RightBound(); x++)
                    {
                        createGrass(polygon, x, y);   // north
                    }
                }
            }
        }