FloorTile SpawnRoom(int x, int y, int itter) { FloorTile tile = new FloorTile(); matrix[x, y] = tile; tile.index = FloorManager.Instance.GetRandomFloor1MapIndex(); if (totalRooms < colors.Length) { tile.color = colors[(int)totalRooms]; } totalRooms++; if (x + 1 < maxFloorSize && Random.Range(0f, 100f) < ((float)itter / 8f) * 100f) { if (matrix[x + 1, y] == null) { SpawnRoom(x + 1, y, itter - 1).connections[3] = true; tile.connections[1] = true; } } if (y + 1 < maxFloorSize && Random.Range(0f, 100f) < ((float)itter / 8f) * 100f) { if (matrix[x, y + 1] == null) { SpawnRoom(x, y + 1, itter - 1).connections[2] = true; tile.connections[0] = true; } } if (x - 1 >= 0 && Random.Range(0f, 100f) < ((float)itter / 8f) * 100f) { if (matrix[x - 1, y] == null) { SpawnRoom(x - 1, y, itter - 1).connections[1] = true; tile.connections[3] = true; } } if (y - 1 >= 0 && Random.Range(0f, 100f) < ((float)itter / 8f) * 100f) { if (matrix[x, y - 1] == null) { SpawnRoom(x, y - 1, itter - 1).connections[0] = true; tile.connections[2] = true; } } return(tile); }
void SpawnInitalRoom(int x, int y) { matrix[x, y] = new FloorTile(); matrix[x, y].index = FloorManager.Instance.GetRandomFloor1MapIndex(); if (totalRooms < colors.Length) { matrix[x, y].color = colors[(int)totalRooms]; } int averageChain = 6; totalRooms++; for (int i = 0; i < 4; i++) { if (Random.Range(0f, 100f) > 33f) { matrix[x, y].connections[i] = true; } } int n = matrix[x, y].TotalNeighbors(); while (n < 2) { matrix[x, y].connections[Random.Range(0, 4)] = true; n = matrix[x, y].TotalNeighbors(); } for (int i = 0; i < matrix[x, y].connections.Length; i++) { if (matrix[x, y].connections[i]) { int opposite = i + 2 < 4 ? i + 2 : i - 2; if (matrix[x + (int)matrix[x, y].connectionMults[i].x, y + (int)matrix[x, y].connectionMults[i].y] == null) { SpawnRoom(x + (int)matrix[x, y].connectionMults[i].x, y + (int)matrix[x, y].connectionMults[i].y, averageChain).connections[opposite] = true; } else { matrix[x + (int)matrix[x, y].connectionMults[i].x, y + (int)matrix[x, y].connectionMults[i].y].connections[opposite] = true; } } } }
public void AddTransitions() { FloorTile tile = FloorManager.Instance.GetCurrentFloorTile(); float subtractor = -1.5f; float offset = GridMetrics.squareSize * 15 - subtractor; for (int i = 0; i < tile.connections.Length; i++) { if (tile.connections[i]) { GameObject ob = Instantiate(roomTranistionPrefab, Vector3.zero, Quaternion.identity); roomTransitions.Add(ob); ob.GetComponentInChildren <RoomConnection>().direction = new IntVector2((int)tile.connectionMults[i].x, (int)tile.connectionMults[i].y); ob.transform.position = new Vector3(tile.connectionMults[i].x * offset + subtractor, 0, tile.connectionMults[i].y * offset + subtractor); if (i % 2 != 0) { ob.transform.Rotate(0, 90, 0); } } } }
public void AddRoom(Vector3 pos, FloorTile tile, int x, int y) { GameObject ob; ob = Instantiate(roomGraphic, transform.position, transform.rotation); ob.transform.SetParent(transform); ob.GetComponent <RectTransform>().localPosition = pos; currentUIObjects.Add(ob); ob.GetComponent <Image>().color = tile.color; ob.GetComponentInChildren <Text>().text = x.ToString() + "," + y.ToString() + "\n" + tile.index; float offset = roomSpacing + roomJointSpacing; Vector3 offsetVector = new Vector3(offset, offset, 0); for (int i = 0; i < tile.connections.Length; i++) { if (tile.connections[i]) { ob = Instantiate(roomJointGraphic, transform.position, transform.rotation); ob.transform.SetParent(transform); ob.GetComponent <RectTransform>().localPosition = pos + Vector3.Scale(offsetVector, tile.connectionMults[i]); } } }