Пример #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);
            }
        }
        else
        {
            CreateWall(currentCell, null, direction);
        }
    }
Пример #2
0
    void CreatePassageInSameRoom(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction)
    {
        MazePassage mazePassage = Instantiate(mazePassPrefab);

        mazePassage.Initialise(_cell, _otherCell, _direction);

        mazePassage = Instantiate(mazePassPrefab);
        mazePassage.Initialise(_otherCell, _cell, _direction.GetOpposite());
    }
Пример #3
0
    private void Move(mazeDirection direction)
    {
        mazeCellEdge edge = currentCell.GetEdge(direction);

        if (edge is mazePassage)
        {
            SetLocation(edge.otherCell);
        }
    }
Пример #4
0
 public virtual void Initialize(mazeCell cell, 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();
 }
Пример #5
0
    private void CreateWall(mazeCell cell, mazeCell otherCell, mazeDirection direction)
    {
        mazeWall wall = Instantiate(wallPrefabs[Random.Range(0, wallPrefabs.Length)]) as mazeWall;

        wall.Initialize(cell, otherCell, direction);
        if (otherCell != null)
        {
            wall = Instantiate(wallPrefabs[Random.Range(0, wallPrefabs.Length)]) as mazeWall;
            wall.Initialize(otherCell, cell, direction.GetOpposite());
        }
    }
    public virtual void Initialise(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction)
    {
        this.cell               = _cell;
        this.otherCell          = _otherCell;
        this.direction          = _direction;
        transform.parent        = _cell.transform;
        transform.localPosition = Vector3.zero;
        transform.localRotation = _direction.ToRotation();

        //Cell should know about the edge too, Smart edge yayy
        _cell.SetEdge(this, _direction);
    }
Пример #7
0
    void CreateWall(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction)
    {
        MazeWall mazeWall = Instantiate(mazeWallPrefabs[Random.Range(0, mazeWallPrefabs.Length)]) as MazeWall;

        mazeWall.Initialise(_cell, _otherCell, _direction);

        if (_otherCell != null)
        {
            mazeWall = Instantiate(mazeWallPrefabs[Random.Range(0, mazeWallPrefabs.Length)]) as MazeWall;
            mazeWall.Initialise(_otherCell, _cell, _direction.GetOpposite());
        }
    }
Пример #8
0
    private void CreatePassageInSameRoom(mazeCell cell, mazeCell otherCell, mazeDirection direction)
    {
        mazePassage passage = Instantiate(passagePrefab) as mazePassage;

        passage.Initialize(cell, otherCell, direction);
        passage = Instantiate(passagePrefab) as mazePassage;
        passage.Initialize(otherCell, cell, direction.GetOpposite());

        if (cell.room != otherCell.room)
        {
            mazeRoom roomToAssimilate = otherCell.room;
            cell.room.Assimilate(roomToAssimilate);
            rooms.Remove(roomToAssimilate);
            Destroy(roomToAssimilate);
        }
    }
Пример #9
0
    private void CreatePassage(mazeCell cell, mazeCell otherCell, mazeDirection direction)
    {
        mazePassage prefab  = Random.value < doorProbability ? doorPrefab : passagePrefab;
        mazePassage passage = Instantiate(prefab) as mazePassage;

        passage.Initialize(cell, otherCell, direction);
        passage = Instantiate(prefab) as mazePassage;
        if (passage is mazeDoor)
        {
            otherCell.Initialize(CreateRoom(cell.room.settingsIndex));
        }
        else
        {
            otherCell.Initialize(cell.room);
        }

        passage.Initialize(otherCell, cell, direction.GetOpposite());
    }
Пример #10
0
    void DoNextGenerationStep(List <MazeCell> _activeCells)
    {
        // newest cell index
        int      currentIndex = ChooseIndex(_activeCells.Count);
        MazeCell currentCell  = _activeCells [currentIndex];

        if (currentCell.isFullyInitialized())
        {
            _activeCells.RemoveAt(currentIndex);
            return;
        }
        IntVector2    currentCoords  = currentCell.coordinates;
        mazeDirection nextDirection  = currentCell.RandomUninitializedDirection;
        IntVector2    nextCellCoords = currentCoords + nextDirection.ToIntVector2();


        if (isCoordInRange(nextCellCoords))
        {
            MazeCell neighbourCell = GetCell(nextCellCoords);

            // Check if cell already or not
            if (neighbourCell == null)
            {
                // i.e. cell doesn't exists
                neighbourCell = CreateCell(nextCellCoords);
                CreatePassage(currentCell, neighbourCell, nextDirection);
                _activeCells.Add(neighbourCell);
            }
            else if (currentCell.room == neighbourCell.room && expandRooms)
            {
                CreatePassageInSameRoom(currentCell, neighbourCell, nextDirection);
            }
            else
            {
                CreateWall(currentCell, neighbourCell, nextDirection);
            }
        }
        else
        {
            //Create wall
            CreateWall(currentCell, null, nextDirection);
        }
    }
Пример #11
0
 public override void Initialize(mazeCell primary, mazeCell other, mazeDirection direction)
 {
     base.Initialize(primary, other, direction);
     if (OtherSideOfDoor != null)
     {
         isMirrored       = true;
         hinge.localScale = new Vector3(-1f, 1f, 1f);
         Vector3 p = hinge.localPosition;
         p.x = -p.x;
         hinge.localPosition = p;
     }
     for (int i = 0; i < transform.childCount; i++)
     {
         Transform child = transform.GetChild(i);
         if (child != hinge)
         {
             child.GetComponent <Renderer>().material = cell.room.settings.wallMaterial;
         }
     }
 }
Пример #12
0
    public override void Initialise(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction)
    {
        base.Initialise(_cell, _otherCell, _direction);
        this.isOpen = false;

        if (OtherSideDoor != null)
        {
            hinge.localScale = new Vector3(-1f, 1f, 1f);
            Vector3 hingePos = hinge.localPosition;
            hingePos.x          = -hingePos.x;
            hinge.localPosition = hingePos;
        }

        for (int i = 0; i < transform.childCount; i++)
        {
            Transform doorTransform = transform.GetChild(i);
            if (doorTransform != hinge)
            {
                doorTransform.GetComponent <Renderer> ().material = _cell.room.setting.wallMaterial;
            }
        }
    }
Пример #13
0
    void CreatePassage(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction)
    {
        MazePassage prefabPass = Random.value < doorProbability ? mazeDoorPrefab : mazePassPrefab;

        MazePassage mazePassage = Instantiate(prefabPass) as MazePassage;

        mazePassage.Initialise(_cell, _otherCell, _direction);

        if (mazePassage is MazeDoor)
        {
            //Create a new room, excluding the last index
            _otherCell.SetRoom((CreateRoom(_cell.room.settingIndex)));
        }
        else
        {
            //initialize with the ongoing room
            _otherCell.SetRoom(_cell.room);
        }

        mazePassage = Instantiate(prefabPass) as MazePassage;
        mazePassage.Initialise(_otherCell, _cell, _direction.GetOpposite());
    }
Пример #14
0
 public MazeCellEdge GetEdge(mazeDirection _direction)
 {
     return(edges [(int)_direction]);
 }
Пример #15
0
 public static mazeDirection GetNextCounterclockwise(this mazeDirection direction)
 {
     return((mazeDirection)(((int)direction + Count - 1) % Count));
 }
Пример #16
0
 //pass in the direction we want and get the vector2 representation of it
 public static Vector2Int ToIntVector2(this mazeDirection direction)
 {
     return(vectors[(int)direction]);
 }
Пример #17
0
 public void SetEdge(mazeDirection direction, mazeCellEdge edge)
 {
     edges[(int)direction] = edge;
     initializedEdgeCount += 1;
 }
Пример #18
0
 public void SetEdge(MazeCellEdge _edge, mazeDirection _direction)
 {
     edges[(int)_direction] = _edge;
     initializedEdges++;
 }
 public static mazeDirection GetOpposite(this mazeDirection dir)
 {
     return(opposites [(int)dir]);
 }
Пример #20
0
 public override void Initialize(mazeCell cell, mazeCell otherCell, mazeDirection direction)
 {
     base.Initialize(cell, otherCell, direction);
     //wall.GetComponent<Renderer>().material = cell.room.settings.wallMaterial;
 }
Пример #21
0
 public override void Initialise(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction)
 {
     base.Initialise(_cell, _otherCell, _direction);
     transform.GetChild(0).GetComponent <Renderer> ().material = _cell.room.setting.wallMaterial;
 }
 public static IntVector2 ToIntVector2(this mazeDirection dir)
 {
     return(vectors [(int)dir]);
 }
Пример #23
0
 private void Look(mazeDirection direction)
 {
     transform.localRotation = direction.ToRotation();
     currentDirection        = direction;
 }
 public static Quaternion ToRotation(this mazeDirection dir)
 {
     return(rotations [(int)dir]);
 }
Пример #25
0
 public mazeCellEdge GetEdge(mazeDirection direction)
 {
     return(edges[(int)direction]);
 }