예제 #1
0
    public List <Node> CalculateDungeon(
        int maxIterations,
        int roomWidthMin,
        int roomLengthMin,
        float roomBottomCornerModifier,
        float roomTopCornerModifier,
        int roomOffset,
        int corridorWidth)
    {
        //splits the room
        BinarySpacePartitioner bsp = new BinarySpacePartitioner(dungeonWidth, dungeonLength);

        allNodesCollection = bsp.PrepareNodesCollection(maxIterations, roomWidthMin, roomLengthMin);
        List <Node> roomSpaces = StructureHelper.TraverseGraphToExtractLowestLeafes(bsp.RootNode);

        RoomGenerator   roomGenerator = new RoomGenerator(maxIterations, roomLengthMin, roomWidthMin);
        List <RoomNode> roomList      = roomGenerator.GenerateRoomsInGivenSpace(roomSpaces,
                                                                                roomBottomCornerModifier,
                                                                                roomTopCornerModifier,
                                                                                roomOffset);

        CorridorGenerator corridorGenerator = new CorridorGenerator();
        var corridorList = corridorGenerator.CreateCorridor(allNodesCollection, corridorWidth);


        return(new List <Node>(roomList).Concat(corridorList).ToList());
    }
예제 #2
0
    public List <Node> CalculateDungeon(int maxPasses, int roomMinWidth, int roomMinLength, float bottomCornerModifier, float topCornerModifier, int roomOffset, int corridorWidth, EnemySpawner enemSpawner, DungeonCreator dungeonCreator, ItemSpawner itemSpawner, ObjectSpawner objSpawner)
    {
        BinarySpacePartitioner bsp = new BinarySpacePartitioner(dungeonWidth, dungeonLength);

        allSpaceNodes = bsp.PrepareNodesCollection(maxPasses, roomMinWidth, roomMinLength);
        List <Node>     roomSpaces    = StructureHelper.TraverseGraphToExtractLowestLeaves(bsp.rootNode);
        RoomGenerator   roomGenerator = new RoomGenerator(maxPasses, roomMinLength, roomMinWidth);
        List <RoomNode> roomList      = roomGenerator.GenerateRoomsInGivenSpaces(roomSpaces, bottomCornerModifier, topCornerModifier, roomOffset);
        //first room will be the spawn point for the player
        RoomNode firstRoom = roomList[0];

        UnityEngine.CharacterController player = GameObject.FindWithTag("Player").GetComponent <UnityEngine.CharacterController>();
        Vector2Int firstRoomCenter             = StructureHelper.CalculateMiddlePoint(firstRoom.BottomLeftCorner, firstRoom.TopRightCorner);
        Vector3    newPos = new Vector3(firstRoomCenter.x, 0.0f, firstRoomCenter.y);

        player.enabled            = false;
        player.transform.position = newPos;
        player.enabled            = true;

        //generate spawn points before we add the corridors
        for (int i = 0; i < roomList.Count; i++)
        {
            RoomNode room = roomList[i];

            if (enemSpawner != null)
            {
                GameObject newRoom = new GameObject("RoomObj", typeof(Room), typeof(BoxCollider));
                newRoom.tag = "RoomObject";
                BoxCollider col = newRoom.GetComponent <BoxCollider>();
                col.isTrigger = true;
                col.size      = new Vector3(1.2f, 1.2f, 1.2f);

                Vector2Int roomPos = StructureHelper.CalculateMiddlePoint(room.BottomLeftCorner, room.TopRightCorner);
                newRoom.transform.position = new Vector3(roomPos.x, 2, roomPos.y);
                Room roomComp = newRoom.GetComponent <Room>();
                room.roomObjReference        = roomComp;
                newRoom.transform.localScale = new Vector3(room.Width, 4, room.Length);
                roomComp.enemySpawnPoints    = new List <Vector3>();
                roomComp.itemSpawnPoints     = new List <Vector3>();
                roomComp.weaponSpawnPoints   = new List <Vector3>();
                roomComp.objectSpawnPoints   = new List <Vector3>();
                roomComp.doors = new List <Transform>();
                dungeonCreator.spawnedRooms.Add(roomComp);

                if (i != 0)
                {
                    enemSpawner.GenerateEnemySpawnPointsForRoom(room);
                    itemSpawner.GenerateItemSpawnPointsForRoom(room);
                    objSpawner.GenerateObjectSpawnPointsForRoom(room);
                }
            }
        }

        CorridorGenerator corridorGenerator = new CorridorGenerator();
        var corridorList = corridorGenerator.CreateCorridor(allSpaceNodes, corridorWidth);

        dungeonCreator.GenerateDoors(corridorList);

        return(new List <Node>(roomList).Concat(corridorList).ToList());
    }
    public List <Node> CalculateRooms(int maxIteration, int roomWidthMin, int roomLengthMin)
    {
        BinarySpacePartitioner bsp = new BinarySpacePartitioner(dungeonWidth, dungeonLength);

        allSpaceNodes = bsp.PrepareNodesCollection(maxIteration, roomWidthMin, roomLengthMin);
        List <Node> roomSpaces = StructureHelper.TraverseGraphToExtractLowestLeafes(bsp.RootNode);

        RoomGenerator   roomGenerator = new RoomGenerator(maxIteration, roomLengthMin, roomWidthMin);
        List <RoomNode> roomList      = roomGenerator.GenerateRoomsInGivenSpaces(roomSpaces);

        return(new List <Node>(allSpaceNodes));
    }
예제 #4
0
    public List <Node> BuildLevel(
        int maxIterations,
        int roomWidthMin,
        int roomLengthMin,
        int corridorWidth,
        float bottomLeftPointModifier,
        float topRightPointModifier,
        int offset)
    {
        BinarySpacePartitioner bsp = new BinarySpacePartitioner(levelWidth, levelLength);

        allNodesCollection = bsp.PrepareNodesCollection(maxIterations, roomWidthMin, roomLengthMin);
        List <Node> roomSpaces = StructureHelper.TraverseGraphToExtractLowestLeaf(bsp.RootNode);

        RoomGenerator   roomGenerator = new RoomGenerator(maxIterations, roomLengthMin, roomWidthMin);
        List <RoomNode> roomList      = roomGenerator.GenerateRoomInGivenSpace(roomSpaces, bottomLeftPointModifier, topRightPointModifier, offset);

        CorridorGenerator corridorGenerator = new CorridorGenerator();
        List <Node>       corridors         = corridorGenerator.CreateCorridor(allNodesCollection, corridorWidth);

        return(new List <Node>(roomList).Concat(corridors).ToList());
    }