Ejemplo n.º 1
0
    private void DoNextGenerationStep(List <Cs_MazeCell> activeCells)
    {
        int         currentIndex = activeCells.Count - 1;
        Cs_MazeCell currentCell  = activeCells[currentIndex];

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

        if (ContainsCoordinates(coordinates))
        {
            Cs_MazeCell neighbor = GetCell(coordinates);
            if (neighbor == null)
            {
                neighbor = CreateCell(coordinates);
                CreatePassage(currentCell, neighbor, direction);
                activeCells.Add(neighbor);
            }
            else
            {
                CreateWall(currentCell, neighbor, direction);
            }
        }
        else
        {
            CreateWall(currentCell, null, direction);
        }
    }
Ejemplo n.º 2
0
    private void CreatePassage(Cs_MazeCell cell, Cs_MazeCell otherCell, MazeDirection direction)
    {
        Cs_MazePassage passage = Instantiate(passagePrefab) as Cs_MazePassage;

        passage.Initialize(cell, otherCell, direction);
        passage = Instantiate(passagePrefab) as Cs_MazePassage;
        passage.Initialize(otherCell, cell, direction.GetOpposite());
    }
 public void Initialize(Cs_MazeCell cell, Cs_MazeCell otherCell, MazeDirection direction)
 {
     this.cell      = cell;
     this.otherCell = otherCell;
     this.direction = direction;
     cell.SetEdge(direction, this);
     transform.parent        = cell.transform;
     transform.localPosition = Vector3.zero;
     transform.localRotation = direction.ToRotation();
 }
Ejemplo n.º 4
0
    private void CreateWall(Cs_MazeCell cell, Cs_MazeCell otherCell, MazeDirection direction)
    {
        Cs_MazeWall wall = Instantiate(wallPrefabs[Random.Range(0, wallPrefabs.Length)]) as Cs_MazeWall;

        wall.Initialize(cell, otherCell, direction);
        if (otherCell != null)
        {
            wall = Instantiate(wallPrefabs[Random.Range(0, wallPrefabs.Length)]) as Cs_MazeWall;
            wall.Initialize(otherCell, cell, direction.GetOpposite());
        }
    }
Ejemplo n.º 5
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);
    }