public BattleState(BattleConfiguration configuration) { _configuration = configuration; _random = new IntRandom(0); _tick = 0; _prevTick = 0; }
void CalculateLenghts(int[] lenghts) { IntRandom binary = new IntRandom(0, 1); int biggest; biggest = binary.Random; rect1Y = lenghts[2 + biggest]; rect2X = lenghts[2 + (biggest + 1) % 2]; biggest = binary.Random; rect1X = lenghts[biggest]; rect2Y = lenghts[(biggest + 1) % 2]; }
void GenerateCaves() { Debug.Log("Sala tipo Caverna: Gerando cavernas..."); //Vou fazer 42% dos tiles serem aleatoriamente paredes. O resto vai ser chao int totalTiles = columns * rows; int wallTiles = Mathf.RoundToInt(wallQuant * totalTiles); //Variaveis para pegar randomicamente int xPos; int yPos; IntRandom xPosGen = new IntRandom(0, columns); IntRandom yPosGen = new IntRandom(0, rows); //Inicializando tudo como chao for (int i = 0; i < columns; i++) { for (int j = 0; j < rows; j++) { tiles[i][j] = TileType.Floor; } } //Sorteando 2 numeros aleatorios, 1 pra linha e 1 pra coluna, wallTiles-vezes for (int i = 0; i < wallTiles; i++) { xPos = xPosGen.Random; yPos = yPosGen.Random; while (tiles[xPos][yPos] == TileType.Wall) { xPos = xPosGen.Random; yPos = yPosGen.Random; } tiles[xPos][yPos] = TileType.Wall; } //Fazendo as bordas serem paredes for (int i = 0; i < columns; i++) { for (int j = 0; j < rows; j++) { if (i == 0 || i == columns - 1 || j == 0 || j == rows - 1) { tiles[i][j] = TileType.Wall; } } } //Removendo o ruido for (int i = 0; i < smoothness; i++) { SmoothLevel(); } }
//Função ficou bem mal escrita. Reescrever void GenerateOtherRooms() { //Ver quantos tipos de sala tem int numRoomTypes = System.Enum.GetNames(typeof(RoomType)).Length; IntRandom intRoomType = new IntRandom(0, numRoomTypes); RoomType roomType; int contador = 0; int xMerge = 0; int yMerge = 0; bool foundSpace = false; while (contador < maxIterations) { foundSpace = false; roomType = (RoomType)intRoomType.Random; rooms = new Room(); rooms.SetupRoom(columns, rows, smoothness, wallQuant, minLenght, maxLenght, roomType, chanceOfCorridor); secTiles = rooms.tiles; for (int i = 2; i < columns - (rooms.highestX - rooms.lowestX) - 2 && !foundSpace; i++) { for (int j = 2; j < rows - (rooms.highestY - rooms.lowestY) - 2 && !foundSpace; j++) { if (CheckForSpace(i, j)) { Debug.Log("FOUND"); foundSpace = true; xMerge = i; yMerge = j; } //yield return new WaitForEndOfFrame(); //yield return null; } } if (foundSpace) { Merge(xMerge - rooms.lowestX, yMerge - rooms.lowestY); } contador++; } AddDoor(); InstantiateTiles(); SpawnPlayer(); }
//Gerar a primeira sala centralizada void GenerateFirstRoom() { //Ver quantos tipos de sala tem int numRoomTypes = System.Enum.GetNames(typeof(RoomType)).Length; IntRandom intRoomType = new IntRandom(0, numRoomTypes); RoomType roomType; //Escolher uma aleatória roomType = (RoomType)intRoomType.Random; Debug.Log("Primeira sala. Tipo escolhido: " + roomType.ToString()); //Gerando rooms = new Room(); rooms.SetupRoom(columns, rows, smoothness, wallQuant, minLenght, maxLenght, roomType, 0); secTiles = rooms.tiles; //O deslocamento do grid secundário será de metade das (colunas/fileiras - lowestX/lowestY) para centralizar, menos um ajuste de coluna/20 para considerar a largura da sala int deltaX = (columns / 2) - rooms.lowestX - (columns / 10); int deltaY = (rows / 2) - rooms.lowestY - (rows / 10); Merge(deltaX, deltaY); }
public void SetupRoom(int roomColumns, int roomRows, int minLenght, int maxLength) { columns = roomColumns; rows = roomRows; IntRandom roomLenght = new IntRandom(minLenght, maxLength); int[] lenghts = new int[4]; InitializeTilesArray(); for (int i = 0; i < 4; i++) { lenghts[i] = roomLenght.Random; } while (lenghts[1] == lenghts[0]) { lenghts[1] = roomLenght.Random; } while (lenghts[2] == lenghts[1] || lenghts[2] == lenghts[0]) { lenghts[2] = roomLenght.Random; } while (lenghts[3] == lenghts[2] || lenghts[3] == lenghts[1] || lenghts[3] == lenghts[0]) { lenghts[3] = roomLenght.Random; } System.Array.Sort(lenghts); CalculateLenghts(lenghts); FindIntersection(); GenerateRoom(); }