//Определить размеры комнат public void CreateRoom() { if (left != null) { left.CreateRoom(); } if (right != null) { right.CreateRoom(); } if (left != null && right != null) { CreateCorridorBetween(left, right); } if (IAmLeaf()) { int roomWidth = (int)Random.Range(rect.width / 1.7f, rect.width - 2); int roomHeight = (int)Random.Range(rect.height / 1.7f, rect.height - 2); int roomX = (int)Random.Range(1, rect.width - roomWidth - 1); int roomY = (int)Random.Range(1, rect.height - roomHeight - 1); room = new Rect(rect.x + roomX, rect.y + roomY, roomWidth, roomHeight); roomType = RoomType.regularRoom; //Debug.Log("Created room " + room + " in sub-dungeon " + debugId + ": " + rect); } }
public void CreateRoom() { if (left != null) { left.CreateRoom(); } if (right != null) { right.CreateRoom(); } if (left != null && right != null) { CreateCorridorBetween(left, right); } if (IAmLeaf()) { int roomWidth = (int)Random.Range(rect.width / 2, rect.width - 2); int roomHeight = (int)Random.Range(rect.height / 2, rect.height - 2); int roomX = (int)Random.Range(1, rect.width - roomWidth - 1); int roomY = (int)Random.Range(1, rect.height - roomHeight - 1); // room position will be absolute in the board, not relative to the sub-dungeon room = new Rect(rect.x + roomX, rect.y + roomY, roomWidth, roomHeight); Debug.Log("Created room " + room + " in sub-dungeon " + debugId + " " + rect); } }
//Создание уровня public void SetupScene(int level) { activeTileset = Random.Range(0, 3); leaves = new List <SubDungeon>(); dungeonHolder = new GameObject("DungeonHolder").transform; entityHolder = new GameObject("Entities").transform; SubDungeon rootSubdungeon = new SubDungeon(new Rect(0, 0, boardRows, boardColumns)); freePositions = new List <Vector2Int>(); CreateBSP(rootSubdungeon); rootSubdungeon.CreateRoom(); firstNode = rootSubdungeon; pathingPositions = new PathingNode[boardRows, boardColumns]; DrawRooms(rootSubdungeon); DrawCorridors(rootSubdungeon); FillInCorridorGaps(rootSubdungeon); PlacePlayer(); PlaceExit(); blocksCount = new Count(freePositions.Count / 12, freePositions.Count / 8); LayoutObjectsAtRandom(tiles[activeTileset].blockTiles, blocksCount.minimum, blocksCount.maximum, true, true); LayoutObjectsAtRandom(tiles[activeTileset].interactableTiles, interactablesCount.minimum, interactablesCount.maximum, false, false); int trapCount = (int)Mathf.Clamp(Mathf.Pow(1.8f, level), 20, freePositions.Count / 13f); LayoutObjectsAtRandom(tiles[activeTileset].trapTiles, trapCount, trapCount, true, false); int enemyCount = (int)Mathf.Clamp(Mathf.Pow(2f, level), 18, freePositions.Count / 10f); LayoutObjectsAtRandom(tiles[activeTileset].enemyTiles, enemyCount, enemyCount, false, false); }
public void CreateRoom() { if (left != null) { left.CreateRoom(); } if (right != null) { right.CreateRoom(); } if (IAmLeaf()) { int roomWidth = (int)Random.Range(rect.width / 2, rect.width - 2); int roomHeight = (int)Random.Range(rect.height / 2, rect.height - 2); int roomX = (int)Random.Range(1, rect.width - roomWidth - 1); int roomY = (int)Random.Range(1, rect.height - roomHeight - 1); // La room tendra posicion absoluta en el board, no relativa al sub-dungeon room = new Rect(rect.x + roomX, rect.y + roomY, roomWidth, roomHeight); } if (right != null && left != null) { CreateCorridorBetween(left, right); } }
public void CreateRoom() { if (left != null) { left.CreateRoom(); } if (right != null) { right.CreateRoom(); } if (left != null && right != null) { CreateCorridorBetween(left, right); } if (IAmLeaf()) { int roomWidth = (int)Random.Range(rect.width / 2, rect.width - 2); int roomHeight = (int)Random.Range(rect.height / 2, rect.height - 2); int roomX = (int)Random.Range(1, rect.width - roomWidth - 1); int roomY = (int)Random.Range(1, rect.height - roomHeight - 1); // room position will be absolute in the board, not relative to the sub-deungeon room = new Rect(rect.x + roomX, rect.y + roomY, roomWidth, roomHeight); //Debug.Log("Created room " + room + " in sub-dungeon " + debugId + " " + rect); int shouldEditRoom = Random.Range(0, 4); // 25% chance for editing the shape of the room if (shouldEditRoom == 0) { removedPiece = GetPieceToRemove(); } } }
public void CreateRoom() { if (left != null || right != null) { if (left != null) { left.CreateRoom(); } if (right != null) { right.CreateRoom(); } if (left != null && right != null) { CreateCorridor(left, right); } } if (isLeaf()) { int width = (int)Random.Range(rect.width / 2, rect.width - 2); int height = (int)Random.Range(rect.height / 2, rect.height - 2); int roomX = (int)Random.Range(1, rect.width - width - 1); int roomY = (int)Random.Range(1, rect.height - height - 1); room = new Rect(rect.x + roomX, rect.y + roomY, width, height); //Debug.Log("Created room " + room + " in sub-dungeon " + debugId + " " + rect); } }
// creates the rooms public void CreateRoom() { // if there is a left sub dungeon, create a room if (left != null) { left.CreateRoom(); } // if there is a right sub dungeon, create a room if (right != null) { right.CreateRoom(); } // if the left and right sub dungeons aren't empty, create a corridor between them if (left != null && right != null) { // create a corridor connecting two sister nodes CreateCorridorBetween(left, right); } // if it has no child nodes, set up the room if (IsLeaf()) { // store the rooms dimensions and position int roomWidth = (int)Random.Range(rect.width / 2, rect.width - 2); int roomHeight = (int)Random.Range(rect.height / 2, rect.height - 2); int roomX = (int)Random.Range(1, rect.width - roomWidth - 1); int roomY = (int)Random.Range(1, rect.height - roomHeight - 1); // room position will be reletive to the dungeon, not relative to the sub-dungeon room = new Rect(rect.x + roomX, rect.y + roomY, roomWidth, roomHeight); } }
public void CreateRoom() { //ha vannak gyerekei, akkor halad lefelé a fában, nem hoz létre szobát addig még nem talál levél részt if (left != null) { left.CreateRoom(); } if (right != null) { right.CreateRoom(); } if (left != null && right != null) { CreateCorridorBetween(left, right); } if (IAmLeaf()) { //a legkisebb szoba fele akkora, mint a rész amiből kilett "vájva", a legnagyobb pedig 2-2 egységgel kisebb int roomWidth = (int)Random.Range(rect.width / 2, rect.width - 2); int roomHeight = (int)Random.Range(rect.height / 2, rect.height - 2); //starting koordináták int roomX = (int)Random.Range(1, rect.width - roomWidth - 1); int roomY = (int)Random.Range(1, rect.height - roomHeight - 1); // a keletkező szoba kezdőkoordinátáit a teljes maphoz vesszük, nem a részhez amiben keletkezik room = new Rect(rect.x + roomX, rect.y + roomY, roomWidth, roomHeight); } }
public void CreateDungeon(GameManager gameManager) { //Debug.Log("Creating dungeon..."); _gameManager = gameManager; // assigning Game Manager _rootSubDungeon = new SubDungeon(new Rect(GameConfigData.Instance.DungeonPadding, GameConfigData.Instance.DungeonPadding, GameConfigData.Instance.DungeonRows, GameConfigData.Instance.DungeonColumns)); CreateBSP(_rootSubDungeon); _rootSubDungeon.CreateRoom(); _dungeonFloorPositions = new GameObject[GameConfigData.Instance.DungeonRows + (2 * GameConfigData.Instance.DungeonPadding), GameConfigData.Instance.DungeonColumns + (2 * GameConfigData.Instance.DungeonPadding)]; _dungeonTiles = new int[GameConfigData.Instance.DungeonRows + (2 * GameConfigData.Instance.DungeonPadding), GameConfigData.Instance.DungeonColumns + (2 * GameConfigData.Instance.DungeonPadding)]; _objectSpawnPos = new int[GameConfigData.Instance.DungeonRows + (2 * GameConfigData.Instance.DungeonPadding), GameConfigData.Instance.DungeonColumns + (2 * GameConfigData.Instance.DungeonPadding)]; _bridgeTilesPos = new List <Vector2Int>(); DrawRooms(_rootSubDungeon); DrawCorridors(_rootSubDungeon); DetermineBridges(_rootSubDungeon); DrawBridges(); DrawWaters(); _bridgeTilesPos.Clear(); // deleting the list since it completes its purpose DrawWalls(); PlaceLamps(_dungeonTiles); _enemyIndexes = new int[, ] { { 0, 1 }, { 0, 2 }, { 1, 2 }, { 0, 3 }, { 1, 3 }, { 1, 4 }, { 1, 5 } }; // start and end indexes of Enemies array accorcding to the dungeon level //Debug.Log("Dungeon creation ended."); }
public void CreateRoom() { if (_left != null) { _left.CreateRoom(); } if (_right != null) { _right.CreateRoom(); } if (_left != null && _right != null) { CreateCorrider(_left, _right); } if (IAmLeaf()) { _levelGenerator._rectList.Add(_rect); // 가로형 던젼 if (_rect.width / _rect.height >= 1.33) { int rand = Random.Range(0, 3); switch (rand) { case 0: MakeRoom(14, 10, RoomType.Col15); break; case 1: MakeRoom(18, 10, RoomType.Col20); break; case 2: MakeRoom(20, 10, RoomType.Col24); break; } } // 세로형 던젼 else if (_rect.height / _rect.width >= 1.33) { int rand = Random.Range(0, 3); switch (rand) { case 0: MakeRoom(10, 14, RoomType.Row15); break; case 1: MakeRoom(10, 18, RoomType.Row20); break; case 2: MakeRoom(10, 20, RoomType.Row24); break; } } // 정사각형 else { int rand = Random.Range(0, 2); switch (rand) { case 0: MakeRoom(10, 10, RoomType.Square10); break; case 1: MakeRoom(12, 12, RoomType.Square15); break; } } } }
void Start() { SubDungeon rootSubDungeon = new SubDungeon(new Rect(0, 0, Rows, Columns)); CreateBSP(rootSubDungeon); rootSubDungeon.CreateRoom(); positionsFloor = new GameObject[Rows, Columns]; DrawRooms(rootSubDungeon); DrawCorridors(rootSubDungeon); }
private void Start() { SubDungeon subdungeon = new SubDungeon(new Rect(0, 0, maxRows, maxColumns)); CreateBSP(subdungeon); subdungeon.CreateRoom(); boardPositionsFloor = new GameObject[maxRows + 1, maxColumns + 1]; DrawRooms(subdungeon); DrawWalls(subdungeon); }
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(); }
// 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); }
public void CreateRoom(int minRoomWidth, int minRoomHeight, int maxRoomWidth, int maxRoomHeight, RoomSizeRandomness randomnessLevel) { if (GameManager.Instance.generationFailed) { return; } if (leftDungeon != null) { leftDungeon.CreateRoom(minRoomWidth, minRoomHeight, maxRoomWidth, maxRoomHeight, randomnessLevel); } if (rightDungeon != null) { rightDungeon.CreateRoom(minRoomWidth, minRoomHeight, maxRoomWidth, maxRoomHeight, randomnessLevel); } if (leftDungeon != null && rightDungeon != null) { CreateCorridorBetween(leftDungeon, rightDungeon); } if (IAmLeaf()) { int roomWidth = 0, roomHeight = 0; if (randomnessLevel == RoomSizeRandomness.FullRandom) { roomWidth = (int)Random.Range(rectangle.width / 2, rectangle.width - 2); roomHeight = (int)Random.Range(rectangle.height / 2, rectangle.height - 2); } else if (randomnessLevel == RoomSizeRandomness.BigRooms) { roomWidth = (int)rectangle.width - 2; roomHeight = (int)rectangle.height - 2; } else if (randomnessLevel == RoomSizeRandomness.SmallRooms) { roomWidth = (int)rectangle.width / 2; roomHeight = (int)rectangle.height / 2; } int roomX = (int)Random.Range(1, rectangle.width - roomWidth - 1); int roomY = (int)Random.Range(1, rectangle.height - roomHeight - 1); if (roomWidth < minRoomWidth || roomWidth > maxRoomWidth || roomHeight < minRoomHeight || roomHeight > maxRoomHeight) { GameManager.Instance.generationFailed = true; } // room position will be absolute in the board, not relative to the sub-dungeon room = new Rect(rectangle.x + roomX, rectangle.y + roomY, roomWidth, roomHeight); } }
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(); }
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() { EnemyAI enemyAI = enemy.GetComponent <EnemyAI>(); enemyAI.target = Player; SubDungeon rootSubDungeon = new SubDungeon(new Rect(0, 0, boardRows, boardColumns)); CreateBSP(rootSubDungeon); rootSubDungeon.CreateRoom(); boardPositionsFloor = new GameObject[boardRows, boardColumns]; boardPositionsUnits = new GameObject[boardRows, boardColumns]; NumberOfEnemy = 0; DrawRooms(rootSubDungeon); DrawCorridors(rootSubDungeon); DrawWallsRooms(rootSubDungeon); DrawWallsCorridors(rootSubDungeon); CreatePathFinder(rootSubDungeon); }
public void CreateRoom()//나눠진 공간에 방을 만드는 작업 { if (left != null) { left.CreateRoom(); } if (right != null) { right.CreateRoom(); } if (IAmLeaf())//잎 노드는 충분히 나눠진 공간이므로 바로 방을 만듦 { int roomWidth = (int)Random.Range(rect.width / 2, rect.width - 2); int roomHeight = (int)Random.Range(rect.height / 2, rect.height - 2); int roomX = (int)Random.Range(1, rect.width - roomWidth - 1); int roomY = (int)Random.Range(1, rect.height - roomHeight - 1); room = new Rect(rect.x + roomX, rect.y + roomY, roomWidth, roomHeight); } }
public void CreateRoom() { if (left != null) { left.CreateRoom(); } if (right != null) { right.CreateRoom(); } if (IAmLeaf()) { int roomWidth = (int)(rect.width - 1); int roomHeight = (int)(rect.height - 1); int roomX = 1; int roomY = 1; // room position will be absolute in the board, not relative to the sub-dungeon room = new Rect(rect.x + roomX, rect.y + roomY, roomWidth, roomHeight); //Debug.Log("Created room " + room + " in sub-dungeon " + debugId + " " + rect); } }
void Start() { int generationFailedCount = 0; _roomSideSize = Mathf.CeilToInt(Mathf.Sqrt(averageMinRoomTiles)); _roomHolder = Resources.Load <GameObject>("Room"); _corridorHolder = Resources.Load <GameObject>("Corridor"); dungeonRoomFloors = RandomTools.Instance.CreateWeightedObjectsArray(dungeonRoomFloors); dungeonRoomInteriorsWallAttachedGlobal = RandomTools.Instance.CreateWeightedObjectsArray(dungeonRoomInteriorsWallAttachedGlobal); dungeonWallDecos = RandomTools.Instance.CreateWeightedObjectsArray(dungeonWallDecos); dungeonCorridorFloors = RandomTools.Instance.CreateWeightedObjectsArray(dungeonCorridorFloors); do { GameManager.Instance.generationFailed = false; SubDungeon rootSubDungeon = new SubDungeon(new Rect(0, 0, boardColumns, boardRows)); tilesPosition = new GameObject[boardColumns, boardRows]; SpacePartition(rootSubDungeon); rootSubDungeon.CreateRoom(minRoomWidth, minRoomHeight, maxRoomWidth, maxRoomHeight, roomSizeRandomness); if (GameManager.Instance.generationFailed == false) { DebugController.Instance.StartMeasuringMethod(); DrawRoomWalls(rootSubDungeon); DebugController.Instance.StopMeasuringMethod("Walls draw:"); SpawnPlayer(); DebugController.Instance.StartMeasuringMethod(); DefineRooms(); DebugController.Instance.StopMeasuringMethod("Room interiors and floors draw:"); DebugController.Instance.StartMeasuringMethod(); DrawCorridors(rootSubDungeon); DebugController.Instance.StopMeasuringMethod("Corridors draw:"); DebugController.Instance.StartMeasuringMethod(); GenerateGateways(); DebugController.Instance.StopMeasuringMethod("Gateways draw:"); DebugController.Instance.StartMeasuringMethod(); DrawWallAttachedObjects(); DebugController.Instance.StopMeasuringMethod("Attached objects draw:"); DebugController.Instance.StartMeasuringMethod(); DrawWallDecos(); DebugController.Instance.StopMeasuringMethod("Wall decos draw:"); GameManager.Instance.InitializeDungeon(this); GameManager.Instance.ManageLoadingScreen(false); } else { generationFailedCount += 1; Debug.Log("Generation Failed"); if (generationFailedCount >= 1000) { Debug.LogError("Couldn't generate dungeon with current config"); } } } while (GameManager.Instance.generationFailed && generationFailedCount < 1000); }
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); //create walls for (int i = 0; i < boardRows; i++) { for (int j = 0; j < boardColumns; j++) { RaycastHit2D hit = Physics2D.Raycast(new Vector2(i, j), new Vector2(i, j), 0); if (hit.collider == null) { Instantiate(Wall, new Vector3(i, j, 1f), Quaternion.identity); } } } // create doors, enemies, keys for (int i = 0; i < boardRows; i++) { for (int j = 0; j < boardColumns; j++) { RaycastHit2D hitup = Physics2D.Raycast(new Vector2(i, j + 1), new Vector2(i, j + 1), 0); RaycastHit2D hitdown = Physics2D.Raycast(new Vector2(i, j - 1), new Vector2(i, j - 1), 0); RaycastHit2D hitright = Physics2D.Raycast(new Vector2(i + 1, j), new Vector2(i + 1, j), 0); RaycastHit2D hitleft = Physics2D.Raycast(new Vector2(i - 1, j), new Vector2(i - 1, j), 0); RaycastHit2D hit = Physics2D.Raycast(new Vector2(i, j), new Vector2(i, j), 0); //door if (doorSpawn != maxKeyDoorValue) { if (hitup.collider != null && hitdown.collider != null) { if (hitup.collider.gameObject.tag.Equals("Wall") && hitdown.collider.gameObject.tag.Equals("Wall") && hit.collider.gameObject.tag.Equals("Ground")) { if (lastdoorPos.y != j) { Instantiate(Door, new Vector3(i, j, -1f), Quaternion.identity); lastdoorPos = new Vector2(i, j); doorSpawn++; } } } } //keys if (keySpawn != maxKeyDoorValue) { if (hit.collider.gameObject.tag.Equals("Player")) { Instantiate(Key, new Vector3(i, j - 1, -1f), Quaternion.identity); keySpawn++; } if (hit.collider.gameObject.tag.Equals("Ground")) { float random = Random.Range(0f, 1f); if (random <= .01f) { Instantiate(Key, new Vector3(i, j, -1f), Quaternion.identity); keySpawn++; } } } //enemy if (hitup.collider != null && hitdown.collider != null && hitright.collider != null && hitleft.collider != null) { if (hitup.collider.gameObject.tag.Equals("Ground") && hitdown.collider.gameObject.tag.Equals("Ground") && hit.collider.gameObject.tag.Equals("Ground") && hitleft.collider.gameObject.tag.Equals("Ground") && hitright.collider.gameObject.tag.Equals("Ground")) { if (enemySpawn <= maxAmountOfEnemies) { if (Vector2.Distance(playerstartPos, new Vector2(i, j)) >= minimumSafeDistance) { if (Vector2.Distance(lastenemyPos, new Vector2(i, j)) >= 5) { Instantiate(Enemy, new Vector3(i, j, -1f), Quaternion.identity); lastenemyPos = new Vector2(i, j); enemySpawn++; } } } } } //flag float distance = Vector2.Distance(hit.transform.position, playerstartPos); if (flagSpawn < 1) { if (distance >= ((boardColumns + boardRows) * .4)) { if (hit.collider.gameObject.tag.Equals("Ground")) { Instantiate(Flag, new Vector3(i, j, -1f), Quaternion.identity); flagSpawn++; } } } //swords if (swordSpawn <= maxAmountOfEnemies) { if (hit.collider.gameObject.tag.Equals("Player")) { Instantiate(Sword, new Vector3(i + 1, j, -1f), Quaternion.identity); Instantiate(Sword, new Vector3(i - 1, j, -1f), Quaternion.identity); swordSpawn++; } if (hit.collider.gameObject.tag.Equals("Ground")) { float random = Random.Range(0f, 1f); if (random <= .01f) { Instantiate(Sword, new Vector3(i, j, -1f), Quaternion.identity); swordSpawn++; } } } } } }