Пример #1
0
    private void ProceedMain(LevelTemplate levelTemplate)
    {
        int[]        lastHeadCoords  = levelTemplate.GetMainHead();
        List <int[]> availableCoords = GetNextMainCoords(levelTemplate, lastHeadCoords);

        if (availableCoords.Count == 0)
        {
            return;
        }

        int[]        nextMainCoords = availableCoords[rand.Next(availableCoords.Count)];
        RoomTemplate lastHead       = levelTemplate.GetMap(lastHeadCoords);

        levelTemplate.SetMain(nextMainCoords);
        // connect the door from the previous
        ConnectRooms(lastHead, levelTemplate.GetMap(nextMainCoords));
    }
Пример #2
0
    private List <int[]> GetSurroundingTypeCoords(LevelTemplate levelTemplate, int[] coords, RoomTemplate.RoomType roomType)
    {
        List <int[]> surroundingAvailableCoords = new List <int[]>();

        int[][] surroundingCoords = GetSurroundingCoords(coords);
        foreach (int[] surroundingCoord in surroundingCoords)
        {
            if (levelTemplate.IsInside(surroundingCoord) && levelTemplate.GetMap(surroundingCoord).GetRoomType() == roomType)
            {
                surroundingAvailableCoords.Add(surroundingCoord);
            }
        }
        return(surroundingAvailableCoords);
    }
Пример #3
0
    private List <RoomTemplate> GetPotentialConnectRooms(LevelTemplate levelTemplate, int[] coords, int[] previousCoords)
    {
        List <RoomTemplate> potentialRooms = new List <RoomTemplate>();

        int[][] surroundingCoords = GetSurroundingCoords(coords);
        foreach (int[] surroundingCoord in surroundingCoords)
        {
            if (surroundingCoord != previousCoords && levelTemplate.IsInside(surroundingCoord))
            {
                RoomTemplate surroundingRoom = levelTemplate.GetMap(surroundingCoord);
                if (surroundingRoom.GetRoomType() == RoomTemplate.RoomType.MAIN || surroundingRoom.GetRoomType() == RoomTemplate.RoomType.OFFSHOOT)
                {
                    potentialRooms.Add(surroundingRoom);
                }
            }
        }
        return(potentialRooms);
    }
Пример #4
0
 private void CreateLevelFromTemplate(LevelTemplate levelTemplate, Transform mapTransform)
 {
     for (int col = 0; col < levelTemplate.GetCols(); ++col)
     {
         for (int row = 0; row < levelTemplate.GetRows(); ++row)
         {
             RoomTemplate roomTemplate = levelTemplate.GetMap(new int[] { col, row });
             if (roomTemplate.GetRoomType() != RoomTemplate.RoomType.EMPTY)
             {
                 Room room = GenerateRoom(roomTemplate, col, row, mapTransform);
                 if (roomTemplate.GetRoomType() == RoomTemplate.RoomType.SPAWN)
                 {
                     spawnPoint = room.GetSpawnPoint();
                 }
             }
         }
     }
 }
Пример #5
0
    public LevelTemplate GenerateLevelTemplate(int cols                        = DEFAULT_LEVEL_COLS,
                                               int rows                        = DEFAULT_LEVEL_ROWS,
                                               int mainLength                  = DEFAULT_LEVEL_MAIN_LENGTH,
                                               float offshootTemperature       = DEFAULT_LEVEL_OFFSHOOT_TEMPERATURE,
                                               float offshootLengthTemperature = DEFAULT_LEVEL_OFFSHOOT_LENGTH_TEMPERATURE)
    {
        LevelTemplate levelTemplate = new LevelTemplate(cols, rows);

        levelTemplate.SetSpawn(new int[] { cols / 2, rows / 2 });
        SetFirstMain(levelTemplate);

        // connect the spawn to the first main room
        ConnectRooms(levelTemplate, levelTemplate.GetSpawnCoords(), levelTemplate.GetMainHead());

        for (int i = 0; i < mainLength; i++)
        {
            ProceedMain(levelTemplate);
        }
        levelTemplate.SetExit();

        // connect the exit to the last main room
        ConnectRooms(levelTemplate, levelTemplate.GetMainHead(), levelTemplate.GetExitCoords());

        List <int[]> mainCoords = levelTemplate.GetMainCoords();

        foreach (int[] mainCoord in mainCoords)
        {
            List <int[]> surroundingAvailableCoords = GetSurroundingAvailableCoords(levelTemplate, mainCoord);
            if (surroundingAvailableCoords.Count > 0 && rand.NextDouble() < offshootTemperature)
            {
                int[] offshootCoord = surroundingAvailableCoords[rand.Next(surroundingAvailableCoords.Count)];
                levelTemplate.SetOffshoot(offshootCoord);
                RoomTemplate mainRoom     = levelTemplate.GetMap(mainCoord);
                RoomTemplate offshootRoom = levelTemplate.GetMap(offshootCoord);
                ConnectRooms(mainRoom, offshootRoom);
                while (rand.NextDouble() < offshootLengthTemperature)
                {
                    List <int[]> availableNextOffshootCoords = GetSurroundingAvailableCoords(levelTemplate, offshootCoord);
                    if (availableNextOffshootCoords.Count == 0)
                    {
                        break;
                    }
                    int[] oldCoords = offshootCoord;
                    offshootCoord = availableNextOffshootCoords[rand.Next(availableNextOffshootCoords.Count)];
                    levelTemplate.SetOffshoot(offshootCoord);
                    RoomTemplate newOffShootRoom = levelTemplate.GetMap(offshootCoord);
                    ConnectRooms(levelTemplate.GetMap(oldCoords), newOffShootRoom);
                    List <RoomTemplate> potentialConnectRooms = GetPotentialConnectRooms(levelTemplate, offshootCoord, oldCoords);
                    if (potentialConnectRooms.Count < 2)
                    {
                        foreach (RoomTemplate potentialRoom in potentialConnectRooms)
                        {
                            ConnectRooms(newOffShootRoom, potentialRoom);
                        }
                    }
                    offshootLengthTemperature /= 2;
                }
            }
        }

        return(levelTemplate);
    }
Пример #6
0
 private void ConnectRooms(LevelTemplate levelTemplate, int[] fromRoomCoords, int[] toRoomCoords)
 {
     ConnectRooms(levelTemplate.GetMap(fromRoomCoords), levelTemplate.GetMap(toRoomCoords));
 }