private void BuildRoom(string roomKey) { CurrentRoomName = roomKey; var room = RoomMap.GetRoom(CurrentRoomName); CurrentRoom = room; HasActiveRoom = true; BuildColliders(room.Colliders); foreach (var layer in CurrentRoom.Tiles.TileLayers) { foreach (var tile in CurrentRoom.Tiles.GetAll(layer)) { BuildTile(tile); } } }
private void BuildRoom(string roomKey) { CurrentRoomName = roomKey; var room = RoomMap.GetRoom(CurrentRoomName); CurrentRoom = room; HasActiveRoom = true; BuildColliders(room.Colliders); foreach (var layer in CurrentRoom.Tiles.TileLayers) { var tiles = CurrentRoom.Tiles.GetAll(layer); var go = new GameObject(layer.Name); go.transform.parent = transform; layerGameobjects.Add(layer, go); foreach (var tile in tiles) { BuildTile(tile, go.transform); } } }
void CreateLayout() { int roomCtr = 1; int attempCtr = 0; int currentX = FloorWidth / 2; int currentY = FloorHeight / 2; m_map.AddRoom(currentX, currentY, m_roomFactory.CreateRoom()); while (roomCtr < MaxRoomCount && attempCtr++ < MaxAttemptCount) { int lastX = currentX; int lastY = currentY; Direction dir = (Direction)Mathf.Round(Random.value * 4); switch (dir) { case Direction.NORTH: ++currentY; break; case Direction.SOUTH: --currentY; break; case Direction.EAST: ++currentX; break; case Direction.WEST: --currentX; break; } if (currentX < 0 || currentY < 0 || currentY >= FloorWidth || currentX >= FloorHeight) { currentX = lastX; currentY = lastY; continue; } if (m_map.GetRoom(currentX, currentY) == null) { m_map.AddRoom(currentX, currentY, m_roomFactory.CreateRoom(m_map.GetRoom(lastX, lastY), dir)); ++roomCtr; } else { switch (dir) { case Direction.NORTH: m_map.GetRoom(currentX, currentY).exits.South = true; m_map.GetRoom(lastX, lastY).exits.North = true; break; case Direction.SOUTH: m_map.GetRoom(currentX, currentY).exits.North = true; m_map.GetRoom(lastX, lastY).exits.South = true; break; case Direction.EAST: m_map.GetRoom(currentX, currentY).exits.West = true; m_map.GetRoom(lastX, lastY).exits.East = true; break; case Direction.WEST: m_map.GetRoom(currentX, currentY).exits.East = true; m_map.GetRoom(lastX, lastY).exits.West = true; break; } } } }
void Update() { float currentRoomRelativeX = m_player.transform.position.x - m_currentRoom.transform.position.x; float currentRoomRelativeY = m_currentRoom.transform.position.y - m_player.transform.position.y; if (currentRoomRelativeX > RoomWidth + 2) { m_currentRoom.Exit(); m_currentRoom = m_map.GetRoom(++m_currentRoomX, m_currentRoomY); m_currentRoom.Enter(); } if (currentRoomRelativeX < -2) { m_currentRoom.Exit(); m_currentRoom = m_map.GetRoom(--m_currentRoomX, m_currentRoomY); m_currentRoom.Enter(); } if (currentRoomRelativeY > RoomHeight + 2) { m_currentRoom.Exit(); m_currentRoom = m_map.GetRoom(m_currentRoomX, --m_currentRoomY); m_currentRoom.Enter(); } if (currentRoomRelativeY < -2) { m_currentRoom.Exit(); m_currentRoom = m_map.GetRoom(m_currentRoomX, ++m_currentRoomY); m_currentRoom.Enter(); } // Debug.Log("Current X: " + currentRoomRelativeX + " CurrentY: " + currentRoomRelativeY); }