Ejemplo n.º 1
0
    /// <summary>
    /// Recursive division algorithm
    /// </summary>
    /// <param name="x">Starting X position of the array</param>
    /// <param name="y">Starting Y position of the array</param>
    /// <param name="currentLevel">Current division deepness</param>
    public void DrawMapRandomRecursive(int x = 0, int y = 0, int currentLevel = 1)
    {
        int  level       = currentLevel;
        int  terrainSize = MapSize / (int)(Math.Pow(2, currentLevel));
        int  xPos        = x;
        int  yPos        = y;
        bool subdivided;
        var  rand = new System.Random();

        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                subdivided = rand.NextDouble() > DivisionChance ? true : false;
                if (level >= DivisionCells)
                {
                    subdivided = false;
                }

                if (subdivided)
                {
                    DrawMapRandomRecursive(xPos, yPos, level + 1);
                    yPos += terrainSize;
                    continue;
                }
                currentBiome = RandomBiome();
                MapBiomeList.Add(currentBiome);
                currentBiome.BuildTerrain(terrainSize, xPos, yPos, TerrainHeightScale, (level == 1 ? 1 : level - 1));
                yPos += terrainSize;
            }
            yPos  = y;
            xPos += terrainSize;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Old division algorithm, not being used atm
    /// </summary>
    public void DrawMapRandom()
    {
        int  terrainSize    = MapSize / 2;
        int  subTerrainSize = MapSize / 4;
        int  xPos           = 0;
        int  yPos           = 0;
        int  subYPos        = 0;
        int  subXPos        = 0;
        bool subdivided     = false;
        int  divisionCount  = 0;

        var rand = new System.Random();

        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                subdivided = rand.NextDouble() > 0.7 ? true : false;
                if (subdivided)
                {
                    subXPos = xPos;
                    subYPos = yPos;

                    divisionCount++;
                    for (int y = 0; y < 2; y++)
                    {
                        for (int x = 0; x < 2; x++)
                        {
                            currentBiome = RandomBiome();
                            MapBiomeList.Add(currentBiome);
                            currentBiome.BuildTerrain(subTerrainSize, subXPos, subYPos, TerrainHeightScale);
                            subYPos += subTerrainSize;
                        }
                        subYPos  = yPos;
                        subXPos += subTerrainSize;
                    }
                    yPos += terrainSize;
                    continue;
                }
                currentBiome = RandomBiome();
                MapBiomeList.Add(currentBiome);
                currentBiome.BuildTerrain(terrainSize, xPos, yPos, TerrainHeightScale);
                yPos += terrainSize;
            }
            yPos  = 0;
            xPos += terrainSize;
        }
        SetWater();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Divides the map with even slices
    /// </summary>
    public void DrawMapEven()
    {
        int terrainSize = MapSize / DivisionCells;
        int xPos        = 0;
        int yPos        = 0;

        for (int i = 0; i < DivisionCells; i++)
        {
            for (int j = 0; j < DivisionCells; j++)
            {
                currentBiome = RandomBiome();
                MapBiomeList.Add(currentBiome);
                currentBiome.BuildTerrain(terrainSize, xPos, yPos, TerrainHeightScale);
                yPos += terrainSize;
            }
            yPos  = 0;
            xPos += terrainSize;
        }

        float waterScale = MapSize * 1.37f / 1024f;

        WaterObject.transform.localScale = new Vector3(waterScale, 1, waterScale);
        WaterObject.transform.position   = new Vector3(MapSize / 2, 2, MapSize / 2);
    }