示例#1
0
    private void DoNextGenerationStep(List <MazeCell> activeCells)
    {
        int      currentIndex = activeCells.Count - 1;
        MazeCell currentCell  = activeCells[currentIndex];

        if (currentCell.IsFullyInitialized)
        {
            activeCells.RemoveAt(currentIndex);
            return;
        }
        MazeDirection direction   = currentCell.RandomUninitializedDirection;
        intVector2    coordinates = currentCell.coordinates + direction.ToIntVector2();

        if (ContainsCoordinates(coordinates))
        {
            MazeCell neighbor = GetCell(coordinates);
            if (neighbor == null)
            {
                neighbor = CreateCell(coordinates);
                CreatePassage(currentCell, neighbor, direction);
                activeCells.Add(neighbor);
            }
            else
            {
                CreateWall(currentCell, neighbor, direction, false);               ////////////////////////////////////////////
                // No longer remove the cell here.
            }
        }
        else
        {
            CreateWall(currentCell, null, direction, true);
            // No longer remove the cell here.
        }
    }
	public void Grow()
	{
		intVector2 idealSpace = null;
		float mostFertile = 0;

		for(int i = 0 ; i < plantTiles.Count; i++)
		{
			foreach(intVector2 dir in directions)
			{
				if(plantTiles[i].x+dir.x >= 0 && plantTiles[i].x+dir.x < manager.getTile.GetLength(0) &&
				   plantTiles[i].y+dir.y >= 0 && plantTiles[i].y+dir.y < manager.getTile.GetLength(1))
				{
					Tile tempTile = manager.getTile[plantTiles[i].x+dir.x,plantTiles[i].y+dir.y];
					if(tempTile.plant == false)
					{
						if(tempTile.growthFactor > mostFertile)
						{
							idealSpace = new intVector2(plantTiles[i].x+dir.x,plantTiles[i].y+dir.y);
							mostFertile = tempTile.growthFactor;
						}
					}
				}
			}
		}
		if(idealSpace != null) 
		{
			Tile growTile = manager.getTile[idealSpace.x,idealSpace.y];
			growTile.growthFactor += mostFertile;
			if(growTile.growthFactor > 1)
			{
				AddPlant(idealSpace);
				growTile.growthFactor = 0;
			}
		}
	}
示例#3
0
    private Cs_MazeCell CreateCell(intVector2 a_Coordinates)
    {
        Cs_MazeCell newCell = Instantiate(mazeCellPrefab) as Cs_MazeCell;

        cells[a_Coordinates.x, a_Coordinates.z] = newCell;
        newCell.iCoordinates = a_Coordinates;
        newCell.name         = "MazeCell" + a_Coordinates.x + "," + a_Coordinates.z;

        newCell.transform.parent = transform;

        newCell.transform.localPosition = new Vector3(a_Coordinates.x - iSize.x * 0.5f + 0.5f, 0f, a_Coordinates.z - iSize.z * 0.5f + 0.5f);

        return(newCell);
    }
示例#4
0
    private MazeCell CreateCell(intVector2 coordinates)
    {
        MazeCell newCell = Instantiate(cellPrefab) as MazeCell;

        cells[coordinates.x, coordinates.z] = newCell;
        newCell.coordinates             = coordinates;
        newCell.name                    = "Maze Cell " + coordinates.x + ", " + coordinates.z;
        newCell.transform.parent        = transform;
        newCell.transform.localPosition =
            new Vector3(coordinates.x - size.x * 0.5f + 0.5f, 0f, coordinates.z - size.z * 0.5f + 0.5f);

        tempObjects.Enqueue(newCell.gameObject);
        RandomBonus(newCell.transform);
        //CreateSpotLights (newCell.transform);

        return(newCell);
    }
    private void floodFill(intVector2 startNode, Color newColor, Texture2D texture)
    {
        Queue <intVector2> myQueue = new Queue <intVector2> ();

        myQueue.Enqueue(startNode);

        intVector2 node;
        intVector2 nextNode;

        while (myQueue.Count > 0)
        {
            node      = myQueue.Dequeue();
            nodeColor = texture.GetPixel(node.x, node.y);

            //fill condition
            if (!colorEqual(nodeColor, Color.black) &&
                !colorEqual(nodeColor, newColor) &&
                node.x >= 0 && node.y >= 0 &&
                node.x < texture.width && node.y < texture.height)
            {
                //replace color
                texture.SetPixel(node.x, node.y, newColor);


                //north
                nextNode.x = node.x;
                nextNode.y = node.y + 1;
                myQueue.Enqueue(nextNode);

                //south
                nextNode.x = node.x;
                nextNode.y = node.y - 1;
                myQueue.Enqueue(nextNode);

                //west
                nextNode.x = node.x - 1;
                nextNode.y = node.y;
                myQueue.Enqueue(nextNode);

                //east
                nextNode.x = node.x + 1;
                nextNode.y = node.y;
                myQueue.Enqueue(nextNode);
            }
        }
    }
示例#6
0
    public void Generate(intVector2 mazeSize)
    {
        size = mazeSize;

        Corners     = new int[] { 0, size.x - 1, size.z - 1 };
        tempObjects = new Queue <GameObject> ();
        wallsQueue  = new Queue <GameObject> ();
        cw          = gameObject.GetComponent <ColorWorker> ();
        cells       = new MazeCell[size.x, size.z];
        List <MazeCell> activeCells = new List <MazeCell> ();

        bonusHolder = GameObject.Find("bonusHolder");

        DoFirstGenerationStep(activeCells);
        while (activeCells.Count > 0)
        {
            DoNextGenerationStep(activeCells);
        }
        //после того как лабиринт сгенерировался он должен быть прозрачным;
        //PaintMaze (Color.gray,0.5f);
    }
示例#7
0
////////////////////////////////////////////////////////

    public MazeCell GetCell(intVector2 coordinates)
    {
        return(cells[coordinates.x, coordinates.z]);
    }
示例#8
0
 public bool ContainsCoordinates(intVector2 coordinate)
 {
     return
         (coordinate.x >= 0 && coordinate.x < size.x && coordinate.z >= 0 && coordinate.z < size.z);
 }
	public void AddPlant(intVector2 pos)
	{
		AddPlant (pos.x, pos.y);
	}
示例#10
0
    // Update is called once per frame
    void Update()
    {
        //PHASE 1
        if (phase == 0)
        {
            while (successfulSearch == false)
            {
                int choice = Random.Range(0, 4);
                //Debug.Log (choice);


                switch (choice)
                {
                case 0:
                    if (vox.grid [currentCoords.x + 1, currentCoords.y].tag != "cube")
                    {
                        target           = vox.grid [currentCoords.x + 1, currentCoords.y];
                        successfulSearch = true;
                        phase            = 1;
                    }
                    break;

                case 1:
                    if (vox.grid [currentCoords.x - 1, currentCoords.y].tag != "cube")
                    {
                        target           = vox.grid [currentCoords.x - 1, currentCoords.y];
                        successfulSearch = true;
                        phase            = 1;
                    }
                    break;

                case 2:
                    if (vox.grid [currentCoords.x, currentCoords.y + 1].tag != "cube")
                    {
                        target           = vox.grid [currentCoords.x, currentCoords.y + 1];
                        successfulSearch = true;
                        phase            = 1;
                    }
                    break;

                case 3:
                    if (vox.grid [currentCoords.x, currentCoords.y - 1].tag != "cube")
                    {
                        target           = vox.grid [currentCoords.x, currentCoords.y - 1];
                        successfulSearch = true;
                        phase            = 1;
                    }
                    break;
                }
            }
        }

        //PHASE 2
        if (phase == 1)
        {
            direction = (target.transform.position - current.transform.position).normalized;
            phase     = 2;
        }
        //PHASE 3
        if (phase == 2)
        {
            tf.Translate(direction * 2.2f * Time.deltaTime);
            if (Vector3.Distance(tf.position, target.transform.position) < 0.04f)
            {
                tf.position      = target.transform.position;
                phase            = 0;
                successfulSearch = false;
                current          = target;
                currentCoords    = new intVector2((int)tf.position.x, (int)tf.position.z);
                target           = null;
            }
        }
    }