예제 #1
0
//	IEnumerator Randomise()
//	{
//		rand = true;
//		while(randomise)
//		{
//			chunk[Random.Range(0, TerrainChunk.ChunkWidth), Random.Range(0, TerrainChunk.ChunkHeight)] = World.Cells[Random.Range(0, 2)];
//			rend.BuildChunk();
//			yield return new WaitForSeconds(waitTime);
//		}
//		rand = false;
//	}

    IEnumerator Randomise()
    {
        CellType type;
        float    noise, x, y;

        rand = true;
        while (randomise)
        {
            for (int i = 0; i < chunk.Length; i++)
            {
                x = (float)TerrainChunk.getX(i);
                y = (float)TerrainChunk.getY(i);
                //Debug.Log(x.ToString() + " " + y.ToString());
                noise = Simplex.noise(x, y, Time.time);

                if (noise > 0.5)
                {
                    type = World.Cells[0];
                }
                else if (noise > 0)
                {
                    type = World.Cells[4];
                }
                else if (noise < -0.5)
                {
                    type = World.Cells[3];
                }
                else
                {
                    type = World.Cells[2];
                }

                chunk[i] = type;
            }

            rend.BuildChunk();
            yield return(new WaitForSeconds(waitTime));
        }
        rand = false;
    }