private RoomComponent CreateRoom(BoardComponent board, CorridorComponent corridor, ref Unity.Mathematics.Random random) { var roomWidth = random.NextInt(3, board.MaxRoomSize); var roomHeight = random.NextInt(3, board.MaxRoomSize); var roomX = 0; var roomY = 0; switch (corridor.Direction) { case Direction.Up: roomHeight = math.clamp(roomHeight, 0, board.Size.y - 2 - corridor.EndY); roomY = corridor.EndY; roomX = random.NextInt(corridor.EndX - roomWidth + 1, corridor.EndX + 1); roomX = math.clamp(roomX, 2, board.Size.x - 2 - roomWidth); break; case Direction.Left: roomWidth = math.clamp(roomWidth, 0, board.Size.x - 2 - corridor.EndX); roomX = corridor.EndX; roomY = random.NextInt(corridor.EndY - roomHeight + 1, corridor.EndY + 1); roomY = math.clamp(roomY, 2, board.Size.y - 2 - roomHeight); break; case Direction.Down: roomHeight = math.clamp(roomHeight, 0, corridor.EndY); roomY = corridor.EndY - roomHeight + 1; roomX = random.NextInt(corridor.EndX - roomWidth + 1, corridor.EndX + 1); roomX = math.clamp(roomX, 2, board.Size.x - 2 - roomWidth); break; case Direction.Right: roomWidth = math.clamp(roomWidth, 0, corridor.EndX); roomX = corridor.EndX - roomWidth + 1; roomY = random.NextInt(corridor.EndY - roomHeight + 1, corridor.EndY + 1); roomY = math.clamp(roomY, 2, board.Size.y - 2 - roomHeight); break; } return(new RoomComponent { X = math.clamp(roomX, 2, board.Size.x - 2), Y = math.clamp(roomY, 2, board.Size.y - 2), Size = new int2(roomWidth, roomHeight), EnteringCorridor = corridor.Direction }); }
private void OnStarPressed(StarComponent star) { if (solved || !activated) { return; } if (selectedStar == null) { selectedStar = star; star.Selected = true; return; } if (selectedStar == star) { Unselect(); return; } if (star.connectedStars.Contains(selectedStar)) { selectedStar.connectedStars.Remove(star); star.connectedStars.Remove(selectedStar); CorridorComponent corridorToDelete = corridors.Find(c => (c.connection.Key == star && c.connection.Value == selectedStar) || (c.connection.Key == selectedStar && c.connection.Value == star) ); Audio.PlaySoundAtTransform("StarmapReconstructionStarsDisconnected", corridorToDelete.transform); corridors.Remove(corridorToDelete); Destroy(corridorToDelete.gameObject); } else { star.connectedStars.Add(selectedStar); selectedStar.connectedStars.Add(star); CorridorComponent corridor = Instantiate(CorridorPrefab); corridor.connection = new KeyValuePair <StarComponent, StarComponent>(star, selectedStar); corridor.transform.parent = MapContainer.transform; corridor.UpdatePosition(); Audio.PlaySoundAtTransform("StarmapReconstructionStarsConnected", corridor.transform); corridors.Add(corridor); } Unselect(); }