示例#1
0
    private void DoNextGenerationStep(LevelCell [,] cells, List <LevelCell> activeCells, Canvas twoDMap, IntVector2 offset, IntVector2 size)
    {
        int       currentIndex = activeCells.Count - 1;
        LevelCell currentCell  = activeCells[currentIndex];

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

        if (ContainsCoordinates(coordinates, size, offset))
        {
            LevelCell neighbor = cells[coordinates.x - offset.x, coordinates.z - offset.z];
            if (neighbor == null)
            {
                neighbor = CreateCell(cells, coordinates, twoDMap, offset);
                CreatePassage(currentCell, neighbor, direction, twoDMap, false);
                activeCells.Add(neighbor);
            }
            else if (currentCell.room == neighbor.room)
            {
                CreatePassageInSameRoom(currentCell, neighbor, direction, twoDMap);
            }
            else
            {
                if (currentCell.room.matIndex == neighbor.room.matIndex)
                {
                    CreatePassageInSameRoom(currentCell, neighbor, direction, twoDMap);
                }
                else
                {
                    if (Random.value < breakableWallProability)
                    {
                        CreateBreakableWall(currentCell, neighbor, direction, twoDMap);
                    }
                    else
                    {
                        CreateWall(currentCell, neighbor, direction, twoDMap);
                    }
                }
            }
        }
        else
        {
            CreateWall(currentCell, null, direction, twoDMap);
        }
    }
示例#2
0
    public IEnumerator CleanLevelCinematically()
    {
        LevelCell[,] areaCells = cells;
        IntVector2       offset    = new IntVector2(0, 0);
        List <LevelRoom> deadRooms = new List <LevelRoom>();

        foreach (LevelRoom room in rooms)
        {
            if (room.cells.Count <= 4)
            {
                deadRooms.Add(room);
                bool           roomCleaned = false;
                int            cellIndex   = 0;
                LevelCell      cell        = room.cells[0];
                LevelDirection direction   = 0;
                while (!roomCleaned && cellIndex < room.cells.Count)
                {
                    cell = room.cells[cellIndex];
                    while ((int)direction < 4 && !roomCleaned)
                    {
                        if (cell.GetEdge(direction) is LevelPassage)
                        {
                            IntVector2 coordinates = cell.coordinates + direction.ToIntVector2();
                            LevelCell  otherCell   = areaCells[coordinates.x - offset.x, coordinates.z - offset.z];
                            if (otherCell.room != cell.room)
                            {
                                StartCoroutine(AssimilateCinematically(otherCell.room, cell.room));
                                roomCleaned = true;
                            }
                        }
                        direction++;
                    }
                    cellIndex++;
                }
            }
            yield return(new WaitForSeconds(0.0f));
        }
        foreach (LevelRoom room in deadRooms)
        {
            rooms.Remove(room);
            Destroy(room);
        }
    }
示例#3
0
    private void CreateTwoDWall(LevelCell cell, Canvas twoDMap, LevelDirection direction)
    {
        IntVector2 positionMultiplier = direction.ToIntVector2();
        Vector3    cellPosition       = new Vector3((cell.coordinates.x - midX) * 1.0f, (cell.coordinates.z - midY) * 1.0f, 0);
        Vector2    offset             = new Vector2(positionMultiplier.x * 0.5f, positionMultiplier.z * 0.5f);
        Image      newImage           = null;

        if (positionMultiplier.x != 0)
        {
            newImage = Instantiate(twoDVertPrefab) as Image;
        }
        else
        {
            newImage = Instantiate(twoDHorzPrefab) as Image;
        }
        newImage.transform.SetParent(twoDMap.transform, false);
        newImage.transform.localPosition = new Vector3(cellPosition.x + offset.x, cellPosition.y + offset.y, 0);
        newImage.color = Color.black;
        newImage.transform.SetAsLastSibling();
        cell.GetEdge(direction).image = newImage;
    }
示例#4
0
    private void CleanLevel(LevelCell[,] areaCells, IntVector2 offset)
    {
        List <LevelRoom> deadRooms = new List <LevelRoom>();

        foreach (LevelRoom room in rooms)
        {
            if (room.cells.Count <= 4)
            {
                deadRooms.Add(room);
                bool           roomCleaned = false;
                int            cellIndex   = 0;
                LevelCell      cell        = room.cells[0];
                LevelDirection direction   = 0;
                while (!roomCleaned && cellIndex < room.cells.Count)
                {
                    cell = room.cells[cellIndex];
                    while ((int)direction < 4 && !roomCleaned)
                    {
                        if (cell.GetEdge(direction) is LevelPassage)
                        {
                            IntVector2 coordinates = cell.coordinates + direction.ToIntVector2();
                            LevelCell  otherCell   = areaCells[coordinates.x - offset.x, coordinates.z - offset.z];
                            if (otherCell.room != cell.room)
                            {
                                Assimilate(otherCell.room, cell.room);
                                roomCleaned = true;
                            }
                        }
                        direction++;
                    }
                    cellIndex++;
                }
            }
        }
        foreach (LevelRoom room in deadRooms)
        {
            rooms.Remove(room);
            Destroy(room);
        }
    }