Beispiel #1
0
        private void CreatePassage(BaseCell cell, BaseCell otherCell, CompassDirection direction)
        {
            CellPassage prefab  = Random.value < ip.doorProbability ? ip.doorPrefab : ip.passagePrefab;
            CellPassage passage = Instantiate(prefab) as CellPassage;

            passage.Initialize(cell, otherCell, direction);
            passage = Instantiate(prefab) as CellPassage;
            if (passage is Door)
            {
                otherCell.Initialize(CreateRoom(-1 /*cell.room.settingsIndex*/));
            }
            else
            {
                otherCell.Initialize(cell.room);
            }
            passage.Initialize(otherCell, cell, direction.GetOpposite());
        }
Beispiel #2
0
        private void PerformNextGenerationStep(List <BaseCell> activeCells)
        {
            int index = activeCells.Count - 1;

            index = ip.useFirstIndex ? 0 : index;
            BaseCell currentCell = activeCells[index];

            if (currentCell.IsFullyInitialized)
            {
                activeCells.RemoveAt(index);
                return;
            }
            CompassDirection direction   = currentCell.RandomUninitializedDirection;
            IntVector2       coordinates = currentCell.coordinates + direction.ToIntVector2();

            if (ContainsCoordinates(coordinates))
            {
                BaseCell neighbor = GetCell(coordinates);
                if (neighbor == null)
                {
                    neighbor = CreateCell(coordinates);
                    CreatePassage(currentCell, neighbor, direction);
                    activeCells.Add(neighbor);
                }
                // if we match on room.settingsIndex instead we can merge same rooms
                else if (currentCell.room == neighbor.room)
                {
                    CreatePassageInSameRoom(currentCell, neighbor, direction);
                }
                else
                {
                    CreateWall(currentCell, neighbor, direction);
                }
            }
            else
            {
                CreateWall(currentCell, null, direction);
            }
        }
Beispiel #3
0
        private BaseCell CreateCell(IntVector2 coordinates)
        {
            var child = new GameObject("Dummy");

            child.transform.parent           = stamp.transform;
            child.transform.localPosition    = new Vector3(coordinates.x * 4 - size.x * 4 * 0.5f + 0.5f, 0f, coordinates.z * 4 - size.z * 4 * 0.5f + 0.5f);
            child.transform.localEulerAngles = Vector3.zero;
            BaseCell cell = PrefabUtility.InstantiatePrefab(ip.baseCell) as BaseCell;

            foreach (var c in cell.GetComponentsInChildren <Collider>())
            {
                c.enabled = false;
            }
            cells[coordinates.x, coordinates.z] = cell;
            cell.coordinates             = coordinates;
            cell.transform.parent        = child.transform;
            cell.transform.localPosition = Vector3.zero;
            cell.transform.localRotation = Quaternion.identity;
            // originally set the parent to the maze's transform
            // then set localposition to the new vector3
            // instead of any of the child stuff
            return(cell);
        }
Beispiel #4
0
 public void Add(BaseCell cell)
 {
     cell.room = this;
     cells.Add(cell);
 }