예제 #1
0
    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);
    }
예제 #2
0
    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);
        }
    }