Пример #1
0
    void Start()
    {
        SubDungeon rootSubDungeon = new SubDungeon(new Rect(0, 0, boardRows, boardColumns));

        CreateBSP(rootSubDungeon);
        rootSubDungeon.CreateRoom();

        boardPositionsFloor = new GameObject[boardRows, boardColumns];
        DrawRooms(rootSubDungeon);
        DrawCorridors(rootSubDungeon);
        DrawWalls();
    }
Пример #2
0
        public bool Split(int minRoomSize, int maxRoomSize)
        {
            if (!IAmLeaf())
            {
                return(false);
            }

            // choose a vertical or horizontal split depending on the proportions
            // i.e. if too wide split vertically, or too long horizontally,
            // or if nearly square choose vertical or horizontal at random
            bool splitH;

            if (rect.width / rect.height >= 1.25)
            {
                splitH = false;
            }
            else if (rect.height / rect.width >= 1.25)
            {
                splitH = true;
            }
            else
            {
                splitH = Random.Range(0.0f, 1.0f) > 0.5;
            }

            if (Mathf.Min(rect.height, rect.width) / 2 < minRoomSize)
            {
                Debug.Log("Sub-dungeon " + debugId + " will be a leaf");
                return(false);
            }

            if (splitH)
            {
                // split so that the resulting sub-dungeons widths are not too small
                // (since we are splitting horizontally)
                int split = Random.Range(minRoomSize, (int)(rect.width - minRoomSize));

                left  = new SubDungeon(new Rect(rect.x, rect.y, rect.width, split), corridorWidth);
                right = new SubDungeon(
                    new Rect(rect.x, rect.y + split, rect.width, rect.height - split), corridorWidth);
            }
            else
            {
                int split = Random.Range(minRoomSize, (int)(rect.height - minRoomSize));

                left  = new SubDungeon(new Rect(rect.x, rect.y, split, rect.height), corridorWidth);
                right = new SubDungeon(
                    new Rect(rect.x + split, rect.y, rect.width - split, rect.height), corridorWidth);
            }

            return(true);
        }
 public void ListRooms(SubDungeon root, List <SubDungeon> allRooms)
 {
     if (root.IAmLeaf())
     {
         Debug.Log("Added Room");
         allRooms.Add(root);
     }
     else
     {
         ListRooms(root.left, allRooms);
         ListRooms(root.right, allRooms);
     }
 }
Пример #4
0
    public void DrawRoomWalls(SubDungeon subDungeon)
    {
        if (subDungeon == null)
        {
            return;
        }

        if (subDungeon.IAmLeaf())
        {
            //first we create holders for the rooms
            //room prefab
            GameObject  roomParent = Instantiate(_roomHolder, dungeonRoomsParent);
            DungeonRoom thisRoom   = new DungeonRoom(roomParent, dungeonRoomsParent.childCount, subDungeon.room);
            _dungeonRooms.Add(thisRoom);
            //wall holder of room prefab
            Transform roomWallHolder = roomParent.transform.GetChild(2);

            //room top walls
            for (int i = (int)subDungeon.room.x + 1; i < subDungeon.room.xMax - 1; i++)
            {
                DrawWall(dungeonWalls.top, i, (int)subDungeon.room.yMax - 1, roomWallHolder);
            }
            //room bottom walls
            for (int i = (int)subDungeon.room.x + 1; i < subDungeon.room.xMax - 1; i++)
            {
                DrawWall(dungeonWalls.bottom, i, (int)subDungeon.room.y, roomWallHolder);
            }
            //room left walls
            for (int i = (int)subDungeon.room.y + 1; i < subDungeon.room.yMax - 1; i++)
            {
                DrawWall(dungeonWalls.left, (int)subDungeon.room.x, i, roomWallHolder);
            }
            //room right walls
            for (int i = (int)subDungeon.room.y + 1; i < subDungeon.room.yMax - 1; i++)
            {
                DrawWall(dungeonWalls.right, (int)subDungeon.room.xMax - 1, i, roomWallHolder);
            }

            //room corner walls
            DrawWall(dungeonWalls.topLeftCorner, (int)subDungeon.room.x, (int)subDungeon.room.yMax - 1, roomWallHolder);
            DrawWall(dungeonWalls.topRightCorner, (int)subDungeon.room.xMax - 1, (int)subDungeon.room.yMax - 1, roomWallHolder);
            DrawWall(dungeonWalls.bottomLeftCorner, (int)subDungeon.room.x, (int)subDungeon.room.y, roomWallHolder);
            DrawWall(dungeonWalls.bottomRightCorner, (int)subDungeon.room.xMax - 1, (int)subDungeon.room.y, roomWallHolder);
        }
        else
        {
            DrawRoomWalls(subDungeon.leftDungeon);
            DrawRoomWalls(subDungeon.rightDungeon);
        }
    }
Пример #5
0
 private void CreateBSP(SubDungeon subDungeon)
 {
     if (subDungeon.IAmLeaf())
     {
         if (subDungeon._rect.width > _maxRoomSize || subDungeon._rect.height > _maxRoomSize) // || Random.Range(0.0f, 1.0f) > 0.25)
         {
             if (subDungeon.Split(_minRoomSize, _maxRoomSize))
             {
                 CreateBSP(subDungeon._right);
                 CreateBSP(subDungeon._left);
             }
         }
     }
 }
Пример #6
0
    // Szoba rajzolása
    public void DrawRooms(SubDungeon subDungeon)
    {
        if (subDungeon == null)
        {
            return;
        }
        // ha a rész levél, akkor végigmegy rajza és lerak egységenként egy floorTilet
        if (subDungeon.IAmLeaf())
        {
            int typeOfRoom;
            typeOfRoom = Random.Range(0, 2);
            FurnishInterface furnisher;
            switch (typeOfRoom)
            {
            case 0:
                furnisher = new LampOnDesk();
                break;

            case 1:
                furnisher = new ChairBesideDesk();
                break;

            default:
                furnisher = new LampOnDesk();
                break;
            }
            furnisher.placeItems(subDungeon.room);
            GameObject lamp         = roomTemplates [Random.Range(0, 2)].lamp;
            Texture    floorTexture = roomTemplates[Random.Range(0, 3)].floorTexture;
            for (int i = (int)subDungeon.room.x; i < subDungeon.room.xMax; i++)
            {
                for (int j = (int)subDungeon.room.y; j < subDungeon.room.yMax; j++)
                {
                    //GameObject instance = Instantiate (floorTile, new Vector3 (i, j, 0f), Quaternion.Identity) as GameObject;
                    GameObject instance = Instantiate(floorTile, new Vector3(i, 0f, j), Quaternion.Euler(90, 0, 0)) as GameObject;
                    instance.GetComponent <MeshRenderer> ().material.mainTexture = floorTexture;
                    instance.transform.SetParent(transform);
                    boardPositionsFloor [i, j] = instance;
                }
            }
            DrawWallsAround(subDungeon);
            //Instantiate(lamp,new Vector3((subDungeon.room.x+subDungeon.room.xMax)/2,0f,(subDungeon.room.y+subDungeon.room.yMax)/2),Quaternion.Euler(new Vector3(0,-90,0)));
        }
        else                            //ha nem levél, akkor halad tovább a gyerekeire
        {
            DrawRooms(subDungeon.left);
            DrawRooms(subDungeon.right);
        }
    }
    // called once on start
    void Start()
    {
        // retrieve dungeon dimensions
        width  = PlayerPrefs.GetInt("ppWidth");
        height = PlayerPrefs.GetInt("ppWidth");

        // create the dungeon
        SubDungeon rootSubDungeon = new SubDungeon(new Rect(0, 0, height, width));

        GenerateBinarySpacePartition(rootSubDungeon);
        rootSubDungeon.CreateRoom();

        // set up the dungeon 2d array
        Init2DArray();
        AddRoomsToDungeonArray(rootSubDungeon);
        AddCorridorsToDungeonArray(rootSubDungeon);
        //PrintDungeonInConsole();

        // this block of code is just adding a border of walls around the generated dungeon
        int borderSize = 5;

        int[,] borderedDungeon = new int[width + borderSize * 2, height + borderSize * 2];

        // iterate through the 2d array. GetLength(0) returns the width of the array
        for (int column = 0; column < borderedDungeon.GetLength(0); column++)
        {
            // GetLength(1) returns the height of the array
            for (int row = 0; row < borderedDungeon.GetLength(1); row++)
            {
                // putting the original array into the bordered one
                if (column >= borderSize && column < width + borderSize && row >= borderSize && row < height + borderSize)
                {
                    borderedDungeon[column, row] = dungeon[column - borderSize, row - borderSize];
                }
                else // add the border
                {
                    borderedDungeon[column, row] = 1;
                }
            }
        }

        // create the 3d mesh
        MeshGenerator gen = GetComponent <MeshGenerator>();

        gen.GenerateMesh(borderedDungeon, 1);

        //export to csv
        FindObjectOfType <GameManager>().ExportDungeonData(borderedDungeon);
    }
Пример #8
0
 public void SpacePartition(SubDungeon subDungeon)
 {
     if (subDungeon.IAmLeaf())
     {
         //split subDungeon if it's large
         if (subDungeon.rectangle.width > _roomSideSize || subDungeon.rectangle.height > _roomSideSize)
         {
             if (subDungeon.Split(_roomSideSize))
             {
                 SpacePartition(subDungeon.leftDungeon);
                 SpacePartition(subDungeon.rightDungeon);
             }
         }
     }
 }
Пример #9
0
 public void CreateBSP(SubDungeon subDungeon)
 {
     if (subDungeon.IAmLeaf())
     {
         // Si el subdungeon es muy largo
         if (subDungeon.rect.width > maxRoomSize || subDungeon.rect.height > maxRoomSize || Random.Range(0.0f, 1.0f) > 0.25)
         {
             if (subDungeon.Split(minRoomSize, maxRoomSize))
             {
                 CreateBSP(subDungeon.left);
                 CreateBSP(subDungeon.right);
             }
         }
     }
 }
Пример #10
0
    public bool Split(int minRoomSize, int maxRoomSize)
    {
        //ha nem levél, akkor nem kell szétválasztani
        if (!IAmLeaf())
        {
            return(false);
        }

        bool splitH, shouldSplit;

        if (rect.width / rect.height >= 1.25)
        {
            splitH = false;             //ha a pálya jóval szélesebb, mint magasabb, akkor függőlegesen szétválasztunk
            //shouldSplit=true;
        }
        else if (rect.height / rect.width >= 1.25)
        {
            splitH = true;             //ha a pálya jóval  magasabb, mint szélesebb, akkor víszintesen szétválasztunk
            //shouldSplit=true;
        }
        else
        {
            splitH = Random.Range(0.0f, 1.0f) > 0.5;              //egyébként random
            //shouldSplit=false;
        }

        if (Mathf.Min(rect.height, rect.width) / 2 < minRoomSize)
        {
            return(false);            // ha túl alacsony a rész magassága vagy szélessége, mint a minimum size, akkor az levél lesz, nem kell szétválasztani
        }
        //ha vízszintesen választunk
        if (splitH)
        {
            //hol válasszunk szét, figyelve arra, hogy ne legyen túl kicsi a keletkező rész
            int split = Random.Range(minRoomSize, (int)(rect.width - minRoomSize));
            //Létrehozzuk a két új részt
            left  = new SubDungeon(new Rect(rect.x, rect.y, rect.width, split));
            right = new SubDungeon(new Rect(rect.x, rect.y + split, rect.width, rect.height - split));
        }
        else                    //függőleges választás
        {
            int split = Random.Range(minRoomSize, (int)(rect.height - minRoomSize));

            left  = new SubDungeon(new Rect(rect.x, rect.y, split, rect.height));
            right = new SubDungeon(new Rect(rect.x + split, rect.y, rect.width - split, rect.height));
        }
        return(true);
    }
Пример #11
0
        public bool Split(int minRoomSize, int maxRoomSize) //현재 트리의 자식 노드를 추가하는 함수
        {
            if (!IAmLeaf())                                 //자식이 있는 가지 노드면 이미 나누었으므로 나눌 필요 없음
            {
                return(false);
            }

            //가로로 자를지 세로로 자를지 정함
            //만약 너무 넓으면 세로로, 길면 가로로 자름
            //정사각형에 가깝다면 가로, 세로를 랜덤으로 정함

            bool splitH;                          //true 면 가로, false면 세로

            if (rect.width / rect.height >= 1.25) //밑변이 길면 세로로 자름
            {
                splitH = false;
            }
            else if (rect.height / rect.width >= 1.25)//높이가 길면 가로로 자름
            {
                splitH = true;
            }
            else//거의 같으면 랜덤으로 정함
            {
                splitH = Random.Range(0.0f, 1.0f) > 0.5;
            }

            if (Mathf.Min(rect.height, rect.width) / 2 < minRoomSize)//최소 길이보다 더 짧아지면 나누기 종료
            {
                return(false);
            }

            if (splitH)
            {//너무 작지 않게 가로로 자름
                split  = Random.Range(minRoomSize, (int)(rect.width - minRoomSize));
                isline = 1;
                left   = new SubDungeon(new Rect(rect.x, rect.y, rect.width, split));                               //현재 좌표에서 랜덤으로 정해진 높이만큼의 공간을 가짐
                right  = new SubDungeon(new Rect(rect.x, rect.y + split + 7, rect.width, rect.height - split - 7)); //자른 만큼의 y 좌표를 이동하여 자르고 나머지 공간을 가짐
            }
            else
            {//너무 작지 않게 세로로 자름
                split  = Random.Range(minRoomSize, (int)(rect.height - minRoomSize));
                isline = 2;
                left   = new SubDungeon(new Rect(rect.x, rect.y, split, rect.height));                              //현재 좌표에서 랜덤으로 정해진 밑변 길이 만큼의 공간을 가짐
                right  = new SubDungeon(new Rect(rect.x + split + 7, rect.y, rect.width - split - 7, rect.height)); //자르고 남은 공간 차지하는 객체를 생성
            }

            return(true);//트리가 나눠졌음을 확인
        }
Пример #12
0
        public bool Split(int minSize, int maxSize)
        {
            if (!isLeaf())
            {
                return(false);
            }

            // choose a vertical or horizontal split
            bool splitH;

            if (rect.width / rect.height >= 1.25)
            {
                splitH = false;
            }
            else if (rect.height / rect.width >= 1.25)
            {
                splitH = true;
            }
            else
            {
                splitH = Random.Range(0.0f, 1.0f) > 0.5;
            }

            if (Mathf.Min(rect.height, rect.width) / 2 < minSize)
            {
                //Debug.Log("Sub-dungeon " + debugId + " will be a leaf");
                return(false);
            }

            if (splitH)
            {
                // split so that the resulting sub-dungeons widths are not too small (split horizontally)
                int split = Random.Range(minSize, (int)(rect.width - minSize));
                left  = new SubDungeon(new Rect(rect.x, rect.y, rect.width, split));
                right = new SubDungeon(
                    new Rect(rect.x, rect.y + split, rect.width, rect.height - split));
            }
            else
            {
                // split so that the resulting sub-dungeons widths are not too small (split vertically)
                int split = Random.Range(minSize, (int)(rect.height - minSize));
                left  = new SubDungeon(new Rect(rect.x, rect.y, split, rect.height));
                right = new SubDungeon(
                    new Rect(rect.x + split, rect.y, rect.width - split, rect.height));
            }

            return(true);
        }
Пример #13
0
    void Start()
    {
        //inicializáljuk a teljes kezdőterületet és megkezdjük a bsp kialakítását
        SubDungeon rootSubDungeon = new SubDungeon(new Rect(0, 0, GetComponent <MapBuilder>().mapRows, GetComponent <MapBuilder>().mapColumns));

        GetComponent <MapGenerator>().CreateBSP(rootSubDungeon);
        //szobák kialakítása
        rootSubDungeon.CreateRoom();

        //szobák rajzolása
        GetComponent <MapBuilder>().DrawRooms(rootSubDungeon);
        GetComponent <MapBuilder>().DrawCorridors(rootSubDungeon);
        GetComponent <MapBuilder>().DestroyWalls();
        GetComponent <MapBuilder>().PutWallsAroundCorridors();
        SpawnPlayer();
    }
    void Start()
    {
        allRooms = new List <SubDungeon>();
        root     = new SubDungeon(new Rect(0, 0, boardRows, boardColumns));
        CreateBSP(root);
        root.CreateRoom();
        root.ListRooms(root, allRooms);
        chooseRooms();

        boardPositionsFloor = new GameObject[boardRows, boardColumns];
        DrawRooms(root);
        DrawCorridors(root);

        placePlayer();
        MakeWalls();
    }
Пример #15
0
 public void CreateBSP(SubDungeon subDungeon) // 트리 만들기
 {
     if (subDungeon.IAmLeaf())                //잎 노드일때
     {                                        //나눈 방이 많이 클 시
         if (subDungeon.rect.width > maxRoomSize ||
             subDungeon.rect.height > maxRoomSize ||
             Random.Range(0.0f, 1.0f) > 0.25)
         {
             if (subDungeon.Split(minRoomSize, maxRoomSize))
             {
                 CreateBSP(subDungeon.left);
                 CreateBSP(subDungeon.right);
             }
         }
     }
 }
Пример #16
0
        public bool Split(int roomSideSize)
        {
            if (!IAmLeaf())
            {
                return(false);
            }

            bool splitHorizontal;

            if (rectangle.width / rectangle.height >= 1.25)
            {
                splitHorizontal = false;
            }
            else if (rectangle.height / rectangle.width >= 1.25)
            {
                splitHorizontal = true;
            }
            else
            {
                splitHorizontal = Random.Range(0.0f, 1.0f) > 0.5;
            }

            if (Mathf.Min(rectangle.height, rectangle.width) / 2 < roomSideSize)
            {
                return(false);
            }


            if (splitHorizontal)
            {
                // split so that the resulting sub-dungeons widths are not too small
                // (since we are splitting horizontally)
                int split = Random.Range(roomSideSize, (int)(rectangle.width - roomSideSize));

                leftDungeon  = new SubDungeon(new Rect(rectangle.x, rectangle.y, rectangle.width, split));
                rightDungeon = new SubDungeon(new Rect(rectangle.x, rectangle.y + split, rectangle.width, rectangle.height - split));
            }
            else
            {
                int split = Random.Range(roomSideSize, (int)(rectangle.height - roomSideSize));

                leftDungeon  = new SubDungeon(new Rect(rectangle.x, rectangle.y, split, rectangle.height));
                rightDungeon = new SubDungeon(new Rect(rectangle.x + split, rectangle.y, rectangle.width - split, rectangle.height));
            }

            return(true);
        }
Пример #17
0
        public bool Split(int minRoomSize, int maxRoomSize)
        {
            if (!IAmLeaf())
            {
                return(false);
            }

            bool splitH;

            if (rect.width / rect.height >= 1.25)
            {
                splitH = false;
            }
            else if (rect.height / rect.width >= 1.25)
            {
                splitH = true;
            }
            else
            {
                splitH = Random.Range(0.0f, 1.0f) > 0.5;
            }

            if (Mathf.Min(rect.height, rect.width) / 2 < minRoomSize)
            {
                Debug.Log("Sub-dungeon " + debugId + " will be a leaf");
                return(false);
            }

            if (splitH)
            {
                int split = Random.Range(minRoomSize, (int)(rect.width - minRoomSize));

                left  = new SubDungeon(new Rect(rect.x, rect.y, rect.width, split));
                right = new SubDungeon(
                    new Rect(rect.x, rect.y + split, rect.width, rect.height - split));
            }
            else
            {
                int split = Random.Range(minRoomSize, (int)(rect.height - minRoomSize));

                left  = new SubDungeon(new Rect(rect.x, rect.y, split, rect.height));
                right = new SubDungeon(
                    new Rect(rect.x + split, rect.y, rect.width - split, rect.height));
            }

            return(true);
        }
Пример #18
0
    private void DebugDrawBspNode(SubDungeon node)
    {
        Gizmos.color = Color.green;
        Gizmos.DrawLine(new Vector3(node.rect.x, node.rect.y, 0), new Vector3(node.rect.xMax, node.rect.y, 0));
        Gizmos.DrawLine(new Vector3(node.rect.xMax, node.rect.y, 0), new Vector3(node.rect.xMax, node.rect.yMax, 0));
        Gizmos.DrawLine(new Vector3(node.rect.x, node.rect.yMax, 0), new Vector3(node.rect.xMax, node.rect.yMax, 0));
        Gizmos.DrawLine(new Vector3(node.rect.x, node.rect.y, 0), new Vector3(node.rect.x, node.rect.yMax, 0));

        if (node.left != null)
        {
            DebugDrawBspNode(node.left);
        }
        if (node.right != null)
        {
            DebugDrawBspNode(node.right);
        }
    }
Пример #19
0
 public void CreateBSP(SubDungeon subDungeon)
 {
     if (subDungeon.IAmLeaf())                 // ha a rész levél
     //ha a rész magassága, vagy szélessége nagyobb mint a maximum megengedett
     {
         if (subDungeon.rect.width > maxRoomSize || subDungeon.rect.height > maxRoomSize || Random.Range(0.0f, 1.0f) > 0.25)
         {
             //szétválasztható
             if (subDungeon.Split(minRoomSize, maxRoomSize))
             {
                 //szétválasztani és meghívni a gyerekeire is
                 CreateBSP(subDungeon.left);
                 CreateBSP(subDungeon.right);
             }
         }
     }
 }
 // this is where we create the binary space partition tree
 public void GenerateBinarySpacePartition(SubDungeon subDungeon)
 {
     // checks to see if the node has no children
     if (subDungeon.IsLeaf())
     {
         // if the sub-dungeon is too big, then split it
         if ((subDungeon.rect.width > maxRoomSize) || (subDungeon.rect.height > maxRoomSize) || (Random.Range(0.0f, 1.0f) > 0.25))
         {
             // if we split, then recursively continue spliting the sub dungeons
             if (subDungeon.Split(minRoomSize, maxRoomSize))
             {
                 GenerateBinarySpacePartition(subDungeon.left);
                 GenerateBinarySpacePartition(subDungeon.right);
             }
         }
     }
 }
Пример #21
0
    //******************Конец отрисовки границ участков узлов для дебага************

    //Попытка поставить выход(неудачная в случае, если на случайно выбранной позиции нет верхней стены комнаты)
    private bool AttemptPlaceExit(SubDungeon leaf)
    {
        int randomPosition = (int)Random.Range(leaf.room.x + 2, leaf.room.xMax - 2);

        if (pathingPositions[randomPosition, (int)leaf.room.yMax - 1].obj.CompareTag("Wall") &&
            pathingPositions[randomPosition + 1, (int)leaf.room.yMax - 1].obj.CompareTag("Wall") &&
            pathingPositions[randomPosition - 1, (int)leaf.room.yMax - 1].obj.CompareTag("Wall"))
        {
            Replace(randomPosition, (int)leaf.room.yMax - 1, tiles[activeTileset].exitTile);

            PlaceAbove(randomPosition, (int)leaf.room.yMax - 1, tiles[activeTileset].exitArch);

            leaf.roomType = SubDungeon.RoomType.endRoom;
            return(true);
        }
        return(false);
    }
Пример #22
0
    void Start()
    {
        SubDungeon rootSubDungeon = new SubDungeon(new Rect(0, 0, boardRows, boardColumns));

        buildHash = new int[building.Length];
        CreateBSP(rootSubDungeon);
        //rootSubDungeon.CreateRoom();
        rootSubDungeon.CreateLine();
        boardPositionsFloor = new GameObject[boardRows, boardColumns];
        thingPositionsFloor = new GameObject[boardRows, boardColumns];
        DrawRooms(rootSubDungeon);
        DrawLines(rootSubDungeon);
        DrawBuilding(rootSubDungeon);
        DrawBlock();

        DrawLamp(rootSubDungeon);
        Drawtrashcan(rootSubDungeon);
    }
Пример #23
0
    public void DrawWall(SubDungeon subDungeon)
    {
        if (subDungeon == null)
        {
            return;
        }

        DrawWall(subDungeon.left);
        DrawWall(subDungeon.right);

        foreach (Rect co in subDungeon.corridors)
        {
            for (int k = (int)co.x; k < co.xMax; k++)
            {
                for (int l = (int)co.y; l < co.yMax; l++)
                {
                    if (boardPositionsFloor[k - 1, l] == null)
                    {
                        GameObject instance = Instantiate(wallTile, new Vector3(k - 1, l, 0f), Quaternion.identity) as GameObject;
                        instance.transform.SetParent(transform);
                        boardPositionsFloor[k - 1, l] = instance;
                    }
                    if (boardPositionsFloor[k + 1, l] == null)
                    {
                        GameObject instance = Instantiate(wallTile, new Vector3(k + 1, l, 0f), Quaternion.identity) as GameObject;
                        instance.transform.SetParent(transform);
                        boardPositionsFloor[k + 1, l] = instance;
                    }
                    if (boardPositionsFloor[k, l - 1] == null)
                    {
                        GameObject instance = Instantiate(wallTile, new Vector3(k, l - 1, 0f), Quaternion.identity) as GameObject;
                        instance.transform.SetParent(transform);
                        boardPositionsFloor[k, l - 1] = instance;
                    }
                    if (boardPositionsFloor[k, l + 1] == null)
                    {
                        GameObject instance = Instantiate(wallTile, new Vector3(k, l + 1, 0f), Quaternion.identity) as GameObject;
                        instance.transform.SetParent(transform);
                        boardPositionsFloor[k, l + 1] = instance;
                    }
                }
            }
        }
    }
Пример #24
0
    private void SpawnEnemies(SubDungeon subDungeon, int dungeonLevel)
    {
        if (subDungeon == null)
        {
            return;
        }

        if (subDungeon.IAmLeaf())
        {
            if (_enemySpawnData.Current <= _enemySpawnData.Max)
            {
                int minEnemyNumber         = (int)((subDungeon.room.width * subDungeon.room.height) / 8);
                int enemyNumberForThisRoom = Random.Range(minEnemyNumber, minEnemyNumber + 1);
                for (int i = 0; i < enemyNumberForThisRoom; i++)
                {
                    _randomPos = GetRandomPosInRoom(subDungeon.room);
                    // if the randomPos != invalidPos, then spawn the object
                    if (Vector3.Distance(_randomPos, _invalidPos) != 0)
                    {
                        int enemyIndex = 0;
                        do                                      // make sure that there is only one turret in a room
                        {
                            enemyIndex = (int)Random.Range(_enemyIndexes[dungeonLevel, 0], _enemyIndexes[dungeonLevel, 1] + 1);
                        } while (subDungeon.hasTurret && enemyIndex == 2);                                      // check if the room has a turret and new enemy is turret

                        GameObject instance = Instantiate(Enemies[enemyIndex], _randomPos, Quaternion.identity) as GameObject;
                        instance.transform.SetParent(Dungeon.transform.GetChild((int)Objects.Enemies).gameObject.transform);
                        _enemySpawnData.Current++;
                        _objectSpawnPos[(int)_randomPos.x, (int)_randomPos.y] = 1;
                        if (enemyIndex == 2)
                        {
                            subDungeon.hasTurret = true;
                        }
                    }
                }
            }
        }
        else
        {
            SpawnEnemies(subDungeon.left, dungeonLevel);
            SpawnEnemies(subDungeon.right, dungeonLevel);
        }
    }
Пример #25
0
        // 공간을 나누는 함수
        public bool Split(int minRoomSize, int maxRoomSize)
        {
            if (!IAmLeaf())
            {
                return(false);
            }

            bool SplitH;

            if (_rect.width / _rect.height >= 1.25)
            {
                SplitH = false;
            }
            else if (_rect.height / _rect.width >= 1.25)
            {
                SplitH = true;
            }
            else
            {
                SplitH = Random.Range(0.0f, 1.0f) > 0.5;
            }

            if (Mathf.Min(_rect.height, _rect.width) / 2 < minRoomSize)
            {
                return(false);
            }

            // 수평으로 나눌 때
            if (SplitH)
            {
                int split = Random.Range(minRoomSize, (int)(_rect.height - minRoomSize));
                _right = new SubDungeon(new Rect(_rect.x, _rect.y, _rect.width, split));
                _left  = new SubDungeon(new Rect(_rect.x, _rect.y + split, _rect.width, _rect.height - split));
            }
            // 수직으로 나눌 때
            else
            {
                int split = Random.Range(minRoomSize, (int)(_rect.width - minRoomSize));
                _left  = new SubDungeon(new Rect(_rect.x, _rect.y, split, _rect.height));
                _right = new SubDungeon(new Rect(_rect.x + split, _rect.y, _rect.width - split, _rect.height));
            }
            return(true);
        }
Пример #26
0
    private void CreateBSP(SubDungeon subDungeon)
    {
        //Debug.Log("Splitting sub-dungeon " + subDungeon.debugId + ": " + subDungeon.rect);
        if (subDungeon.IAmLeaf())
        {
            // if the subdungeon is too large
            if (subDungeon.rect.width > GameConfigData.Instance.MaxRoomSize || subDungeon.rect.height > GameConfigData.Instance.MaxRoomSize || Random.Range(0.0f, 1.0f) > 0.25)
            {
                if (subDungeon.Split(GameConfigData.Instance.MinRoomSize, GameConfigData.Instance.MaxRoomSize))
                {
                    //Debug.Log ("Splitted sub-dungeon " + subDungeon.debugId + " in " + subDungeon.left.debugId + ": " + subDungeon.left.rect + ", "
                    //+ subDungeon.right.debugId + ": " + subDungeon.right.rect);

                    CreateBSP(subDungeon.left);
                    CreateBSP(subDungeon.right);
                }
            }
        }
    }
Пример #27
0
    public void CreateBSP(SubDungeon subDungeon)
    {
        // Debug.Log("Splitting sub-dungeon " + subDungeon.debug + ": " + subDungeon.rect);
        if (subDungeon.IAmLeaf())
        {
            if (subDungeon.rect.width > minRoom || subDungeon.rect.height > minRoom)
            {
                if (subDungeon.Split(minRoom))
                {
                    // Debug.Log("Splitted sub-dungeon " + subDungeon.debug + " in "
                    //   + subDungeon.left.debug + ": " + subDungeon.left.rect + ", "
                    // + subDungeon.right.debug + ": " + subDungeon.right.rect);

                    CreateBSP(subDungeon.left);
                    CreateBSP(subDungeon.right);
                }
            }
        }
    }
Пример #28
0
 public void CreateBSP(SubDungeon subDungeon)
 {
     //Debug.Log("Splitting sub-dungeon " + subDungeon.debugId + ": " + subDungeon.rect);
     if (subDungeon.isLeaf())
     {
         // if the sub-dungeon is too large
         if (subDungeon.rect.width > maxSize || subDungeon.rect.height > maxSize || Random.Range(0.0f, 1.0f) > 0.25)
         {
             if (subDungeon.Split(minSize, maxSize))
             {
                 //Debug.Log("Splitted sub-dungeon " + subDungeon.debugId + " in "
                 //+ subDungeon.left.debugId + ": " + subDungeon.left.rect + ", "
                 //+ subDungeon.right.debugId + ": " + subDungeon.right.rect);
                 CreateBSP(subDungeon.left);
                 CreateBSP(subDungeon.right);
             }
         }
     }
 }
Пример #29
0
    //Выбрать самую маленькую комнату для создания игрока
    private SubDungeon SmallestRoom()
    {
        SubDungeon smallestRoom     = leaves[0];
        float      smallestRoomSize = float.PositiveInfinity;

        foreach (SubDungeon leaf in leaves)
        {
            float leafRoomSize = leaf.room.width * leaf.room.height;
            if (leafRoomSize < smallestRoomSize)
            {
                smallestRoomSize = leafRoomSize;
                smallestRoom     = leaf;
            }
        }

        smallestRoom.roomType = SubDungeon.RoomType.startRoom;

        return(smallestRoom);
    }
Пример #30
0
    //Отрисовка частей коридора, соединяющихся с комнатами
    //Нужно потому, что, если рисовать весь коридор сразу, то другие коридоры, пересекающиеся с данным после, могут создать лишние стены
    private void FillInCorridorGaps(SubDungeon subdungeon)
    {
        if (subdungeon == null)
        {
            return;
        }

        FillInCorridorGaps(subdungeon.left);
        FillInCorridorGaps(subdungeon.right);

        foreach (Rect corridor in subdungeon.corridors)
        {
            for (int i = (int)corridor.x; i < corridor.xMax; i++)
            {
                for (int j = (int)corridor.y; j < corridor.yMax; j++)
                {
                    if (corridor.width > corridor.height)
                    {
                        if (pathingPositions[i, j + 1] != null && pathingPositions[i, j + 1].obj.CompareTag("Wall"))
                        {
                            PlaceAbove(i, j + 1, tiles[activeTileset].wallTiles[0]);
                        }
                        if (pathingPositions[i, j - 1] != null && pathingPositions[i, j - 1].obj.CompareTag("Wall"))
                        {
                            PlaceAbove(i, j - 1, tiles[activeTileset].wallTiles[4]);
                        }
                    }
                    else
                    {
                        if (pathingPositions[i + 1, j] != null && pathingPositions[i + 1, j].obj.CompareTag("Wall"))
                        {
                            PlaceAbove(i + 1, j, tiles[activeTileset].wallTiles[2]);
                        }
                        if (pathingPositions[i - 1, j] != null && pathingPositions[i - 1, j].obj.CompareTag("Wall"))
                        {
                            PlaceAbove(i - 1, j, tiles[activeTileset].wallTiles[6]);
                        }
                    }
                }
            }
        }
    }