コード例 #1
0
    override protected void GenerateWithAlgorithm(VirtualMap map, VirtualMap vmapBelow)
    {
        // Make sure the map is full of walls
        map.ResetToRocks();
        //return;

        // Pick the cell to start from
        CellLocation starting_location = default(CellLocation);

        if (vmapBelow != null)
        {
            starting_location = vmapBelow.end;
        }
        else
        {
            starting_location = map.PickRandomUnvisitedLocation();
        }
        //Debug.Log(starting_location);

        DiggingMapGeneratorAlgorithm alg = null;

        switch (algorithmChoice)
        {
        case DiggingMapGeneratorAlgorithmChoice.RecursiveBacktracker:       alg = new RecursiveBacktrackerDiggingMapGeneratorAlgorithm(); break;

        case DiggingMapGeneratorAlgorithmChoice.HuntAndKill:                alg = new HuntAndKillDiggingMapGeneratorAlgorithm(); break;
        }
        alg.StartDigging(map, starting_location, directionChangeModifier);

        Sparsify(map, vmapBelow);
        if (verbose)
        {
            Console.WriteLine("Sparsified!");
        }

        OpenDeadEnds(map);
        if (verbose)
        {
            Console.WriteLine("Opened dead ends!");
        }

        if (createRooms)
        {
            CreateRooms(map);
            if (verbose)
            {
                Console.WriteLine("Added rooms!");
            }
        }
    }
コード例 #2
0
    public int maxCorridorWidth   = 2;    // [1,2]

    // bool ONE_DOOR_PER_CORRIDOR = true;

    override protected void GenerateWithAlgorithm(VirtualMap map, VirtualMap vmapBelow)
    {
        // Start full of rocks
        map.ResetToRocks();
        //return;

        // Pick the cell to start from
        CellLocation starting_location = default(CellLocation);

        if (vmapBelow != null)
        {
            starting_location = vmapBelow.end;
        }
        else
        {
            starting_location = CellLocation.INVALID;
        }
        //Debug.Log(starting_location);

        // We start our tree with the full dungeon bounds (only counting FLOOR cells)
        BSPTree tree = new BSPTree();

        tree.root = new BSPTreeNode(0, 0, map.ActualWidth, map.ActualHeight);

        // Pick a random initial direction
        BSPSplitDirection splitDir = (BSPSplitDirection)DungeonGenerator.Random.Instance.Next(0, (int)BSPSplitDirection.MAX - 1);

        // Start the algorithm
        List <BSPTreeNode> leafNodes = new List <BSPTreeNode>();

        SplitNode(tree.root, splitDir, splitRange, nSplits, leafNodes);

        // Create the rooms
        RoomGenerator roomGenerator = new RoomGenerator();

        map.rooms = new List <VirtualRoom>();
        foreach (BSPTreeNode node in leafNodes)
        {
            VirtualRoom room = CreateRoom(map, roomGenerator, node, starting_location);
            if (room != null)
            {
                room.sequentialId = map.rooms.Count;
                map.rooms.Add(room);
            }
        }

        // Create the corridors
        LinkCorridors(tree.root, map, 0);
    }