예제 #1
0
 public LevelLayout(Size levelSize, LevelCoordinate startingPostion)
 {
     LevelSize       = levelSize;
     TypeLayout      = new ARoomType[levelSize.Height, levelSize.Width];
     MainPath        = new List <LevelCoordinate>();
     StartingPostion = startingPostion;
 }
예제 #2
0
 public FourByFourLayout(IList <ARoomType> roomTypes, LevelCoordinate startingPoint)
 {
     this.roomTypes = roomTypes;
     LevelSize      = new Size {
         Height = 4, Width = 4
     };
     directionsMap = GetDirectionsMap();
     StartingPoint = startingPoint;
 }
예제 #3
0
        public LevelLayout GenerateRoomLayout()
        {
            LevelLayout levelLayout = new LevelLayout(LevelSize, StartingPoint);

            int enterDirection = 0;
            var selectedPos    = new LevelCoordinate
            {
                Height = StartingPoint.Height,
                Width  = StartingPoint.Width
            };

            while (selectedPos.Height < LevelSize.Height)
            {
                var roomTypeSelection = SelectABaseRoomType(enterDirection, selectedPos.Width);
                levelLayout.TypeLayout[selectedPos.Height, selectedPos.Width] = roomTypeSelection.SelectedBaseType;
                levelLayout.MainPath.Add(selectedPos.Clone());
                enterDirection = roomTypeSelection.ExitDirection;

                switch (roomTypeSelection.ExitDirection)
                {
                case 1: selectedPos.Width--; break;

                case 2: selectedPos.Width++; break;

                case 3: selectedPos.Height++; break;
                }
            }

            for (int i = 0; i < LevelSize.Height; i++)
            {
                for (int j = 0; j < LevelSize.Width; j++)
                {
                    if (levelLayout.TypeLayout[i, j] != null)
                    {
                        continue;
                    }

                    levelLayout.TypeLayout[i, j] = roomTypes[UnityEngine.Random.Range(0, roomTypes.Count)];
                    continue;
                }
            }

            return(levelLayout);
        }
예제 #4
0
    private void Start()
    {
        if (levelSize == null)
        {
            return;
        }

        var startingPoint = new LevelCoordinate
        {
            Height = 0,
            Width  = Random.Range(0, levelSize.Width)
        };

        levelRenderer  = GetComponent <LevelRenderer>();
        roomCollection = GetComponent <RoomCollection>();

        layoutCreator = new FourByFourLayout(roomCollection.GetRoomTypes(), startingPoint);

        bounds = levelRenderer.RenderBaseLevel(layoutCreator);
    }