private void BuildChildRooms(ref WorldData world, WorldData.RoomCell cell, int length) { var room = cell.Reference; room.IsMainRoom = !Info.HasBoss; length = room.IsMainRoom ? CorridorLength : length - 1; int possibleCount; List <Room.DoorDirection> directions = CheckFreeConnections(ref world, out possibleCount, cell); int roomCount = Mathf.Min(possibleCount, Info.RoomsLeft); while (roomCount > 0 && Info.RoomsLeft > 0 && directions.Any() && length > 0) { int index = Random.Range(0, directions.Count); Room.DoorDirection dir = directions[index]; roomCount--; Info.RoomsLeft--; directions.RemoveAt(index); var newRoom = BuildRoomsRecurrent(ref world, room.MapPosition + Room.RoomOffset[dir], length); room.SetConnection(dir, newRoom, cell); if (!allowLoops) { directions = CheckFreeConnections(ref world, out possibleCount, cell); roomCount = Mathf.Min(possibleCount, Info.RoomsLeft); } } }
public Vector3 GetDoorOffset(Room room, Room.DoorDirection direction, float distance = 0.5f) { Vector3 result = Vector3.zero; switch (direction) { case Room.DoorDirection.Left: result = new Vector3(-distance * room.RoomSize.x, 0, 0); break; case Room.DoorDirection.Right: result = new Vector3(distance * room.RoomSize.x, 0, 0); break; case Room.DoorDirection.Down: result = new Vector3(0, 0, -distance * room.RoomSize.z); break; case Room.DoorDirection.Up: result = new Vector3(0, 0, distance * room.RoomSize.z); break; } return(result); }
public WorldData.RoomCell GetGlobalRoomCell(WorldData data, Room.DoorDirection direction) { var offset = RoomOffset[direction]; var pos = MapPosition + offset; if (HasEdge(data, direction)) { return(new WorldData.RoomCell()); } WorldData.RoomCell result = data.RoomMap[pos.x][pos.y]; return(result); }
public void Init(WorldController world, Room.DoorDirection left, Key keyInstance) { if (!Anim) { Anim = GetComponent <Animator>(); } KeyInstance = keyInstance; World = world; Direction = left; if (KeyInstance != null && Renderer && MaterialInstance < Renderer.materials.Length) { Renderer.materials[MaterialInstance].color = KeyInstance.color; } }
public Image GetImage(Room.DoorDirection dir) { switch (dir) { case Room.DoorDirection.Left: return(Left); case Room.DoorDirection.Right: return(Right); case Room.DoorDirection.Down: return(Down); case Room.DoorDirection.Up: return(Up); } return(null); }
private Room.DoorDirection CheckFreeConnections(ref WorldData world, out int count, WorldData.RoomCell cell) { Room.DoorDirection result = Room.DoorDirection.None; count = 0; foreach (Room.DoorDirection dir in Room.AllDirs) { var room = cell.Reference.GetGlobalRoomCell(world, dir); if (room.Type == Room.RoomType.Empty && !cell.Reference.HasEdge(world, dir)) { result |= dir; count++; } } return(result); }
public void OnEnterDoor(Room.DoorDirection direction) { if (!CurrentRoom.IsCleared) { return; } CurrentRoom.KeyLock = null; var inverse = Room.InverseDirection[direction]; var room = CurrentRoom.GetGlobalRoomCell(Data, direction); var doorPos = room.Reference.GetDoorPosition(inverse); if (doorPos.magnitude < 0.1f) { doorPos = GetDoorOffset(room.Reference, inverse); } doorPos -= Room.DoorForward[inverse]; doorPos.y = 0; ActivateRoom(room.Reference, doorPos); }
public bool HasRoom(WorldData data, Room.DoorDirection direction) { WorldData.RoomCell cell = GetGlobalRoomCell(data, direction); return(cell.Type != RoomType.Empty); }