public HallwayMeta FindMatchingDoors(RoomTransformation otherRoom) { float distance = float.MaxValue; Vector3 thisPosition = new Vector3(rect.x, 0f, rect.y); Vector3 otherPosition = new Vector3(otherRoom.Rect.x, 0f, otherRoom.Rect.y); HallwayMeta hallwayMeta = new HallwayMeta(null, null); foreach (DoorDefinition thisDoor in availableDoors) { foreach (DoorDefinition otherDoor in otherRoom.availableDoors) { float tmpDistance = Vector3.Distance(thisDoor.RelPosition + thisPosition, otherDoor.RelPosition + otherPosition); if (tmpDistance < distance) { hallwayMeta.StartDoor = thisDoor; hallwayMeta.EndDoor = otherDoor; distance = tmpDistance; } } } availableDoors.Remove(hallwayMeta.StartDoor); otherRoom.availableDoors.Remove(hallwayMeta.EndDoor); return(hallwayMeta); }
private void GenerateLevel(RoomNode node, RoomTransformation prevChunk) { //Place the Chunk somewhere, where it won't collide with another chunk GameObject chunk = InstantiateChunk(node, new Vector3(tmpChunkPos, 0f, tmpChunkStep)); if (isConstraintError) { return; } tmpChunkPos += tmpChunkStep; //Obtain the actual position, the chunk will have later on Vector3 chunkSize = ChunkSize(chunk); RoomTransformation roomTransform = new RoomTransformation(chunk, node.Position, chunkSize, spacing); roomTransform.AddConnection(prevChunk); positionMeta.Add(roomTransform); debugData.AddRoomMeta(chunk, node); if (prevChunk != null) { HallwayMeta hallway = prevChunk.FindMatchingDoors(roomTransform); hallwayMeta.Add(hallway); } //Recursively generate subrooms foreach (RoomNode subNode in node.Connections) { GenerateLevel(subNode, roomTransform); } }
//Is neccessary to calculate the furthest distance (see below) //Will store a reference to a connecting room and vice versa public void AddConnection(RoomTransformation otherChunk) { if (!connections.Contains(otherChunk) && otherChunk != null) { connections.Add(otherChunk); otherChunk.AddConnection(this); } }
public RoomInstanceMeta(RoomTransformation input) { this.connections = new List <GameObject> (); this.doors = new List <DoorMetadata> (); this.chunk = input.Chunk; this.position = input.Position; this.rect = input.Rect; input.Connections.ForEach(c => connections.Add(c.Chunk)); input.Doors.ForEach(d => doors.Add(new DoorMetadata(d.RelPosition, d.Direction, d.Position))); this.bounds = FindBounds(); this.tags = FindChunkTags(); }
private void AddLevelMetadataRoom(RoomTransformation roomTransformation) { levelMetadata.Rooms.Add(new RoomInstanceMeta(roomTransformation)); }