Exemple #1
0
    private LevelSplit[] SplitLevel(LevelSplit levelSplit, int splitOffset, bool horizontal)
    {
        LevelSplit[] splitResult = new LevelSplit[2];

        if (horizontal) // Horizontal split (so in width/x)
        {
            int newWidth = Mathf.RoundToInt(levelSplit.delta.x / 2) + splitOffset;
            splitResult[0] = new LevelSplit
            {
                start = levelSplit.start, delta = new Vector2Int(newWidth, levelSplit.delta.y)
            };
            splitResult[1] = new LevelSplit
            {
                start = new Vector2Int(levelSplit.start.x + newWidth, levelSplit.start.y),
                delta = new Vector2Int(levelSplit.delta.x - newWidth, levelSplit.delta.y)
            };
        }
        else // Vertical split (so in height/y)
        {
            int newHeigth = Mathf.RoundToInt(levelSplit.delta.y / 2) + splitOffset;
            splitResult[0] = new LevelSplit
            {
                start = levelSplit.start, delta = new Vector2Int(levelSplit.delta.x, newHeigth)
            };
            splitResult[1] = new LevelSplit
            {
                start = new Vector2Int(levelSplit.start.x, levelSplit.start.y + newHeigth),
                delta = new Vector2Int(levelSplit.delta.x, levelSplit.delta.y - newHeigth)
            };
        }

        return(splitResult);
    }
Exemple #2
0
 private bool DoISplitHorizontally(LevelSplit split)
 {
     if (split.delta.x / split.delta.y < minRoomRatio)
     {
         return(false);
     }
     else if (split.delta.y / split.delta.x < minRoomRatio)
     {
         return(true);
     }
     else
     {
         return(UnityEngine.Random.Range(0, 2) == 1);
     }
 }
Exemple #3
0
    private LevelSplit[] SplitLevels()
    {
        LevelSplit[] splits = new LevelSplit[]
        { new LevelSplit {
              start = new Vector2Int(0, 0), delta = new Vector2Int(levelWidth, levelHeight)
          } };
        for (int splitLevel = 1; splitLevel <= splitDepth; splitLevel++)
        {
            int          newSplitNo = splits.Length * 2;
            LevelSplit[] newSplits  = new LevelSplit[newSplitNo];

            splitCubes = new List <GameObject>();

            int currentIndex = 0;
            foreach (LevelSplit split in splits)
            {
                bool splitHorizontal = DoISplitHorizontally(split);
                int  splitRange      = 0;
                if (splitHorizontal)
                {
                    splitRange = Mathf.RoundToInt(split.delta.x * maxSplitOffset);
                }
                else
                {
                    splitRange = Mathf.RoundToInt(split.delta.y * maxSplitOffset);
                }

                LevelSplit[] newSplit = SplitLevel(split, UnityEngine.Random.Range(-splitRange, splitRange),
                                                   splitHorizontal);
                newSplits[currentIndex] = newSplit[0];
                currentIndex++;
                newSplits[currentIndex] = newSplit[1];
                currentIndex++;
            }

            splits = newSplits;
        }

        return(splits);
    }