static void Main()
    {
        WaveFunctionCollapse wfc = new WaveFunctionCollapse();

        wfc.Run();

        wfc.ToImage("./map.png");
        wfc.ToJson("./map.json", "testMap", true);
    }
Exemple #2
0
    public override void OnInspectorGUI()
    {
        WaveFunctionCollapse myScript = (WaveFunctionCollapse)target;

        base.OnInspectorGUI();
        if (GUILayout.Button("Run WFC"))
        {
            myScript.Run();
        }
    }
Exemple #3
0
    //public methods
    public Room GenerateRoom(int level, int difficulty, List <Piece> pieceSet)
    {
        Room toReturn = new Room(1, "test name");

        //Generate a new room based on the given level and difficulty
        // First create the outline of the room - this will be some number of slots in some shape
        // determine the number of slots by the current level and difficulty
        int numSlots = GetNumSlots(level, difficulty);

        //Create the slots
        roomSlots = new Slot[numSlots, numSlots];
        for (int x = 0; x < numSlots; x++)
        {
            for (int y = 0; y < numSlots; y++)
            {
                roomSlots[x, y] = new Slot(new Vector2Int(x, y), pieceSet);
            }
        }

        // determine which slots will be "active" and which will be "inactive"
        DetermineSlotActivity(numSlots);

        //Next we collapse the active slots following the WFC algo
        WaveFunctionCollapse.SetSlots(ref roomSlots, pieceSet);

        while (!WaveFunctionCollapse.IsCollapsed())
        {
            WaveFunctionCollapse.Iterate();
        }

        //The wave function is complete and our room is ready
        //Add the active slots with prefabs instantiated into the room
        AddCollapsedSlotsToRoom(ref toReturn);

        return(toReturn);
    }
Exemple #4
0
 public void CreateWFC()
 {
     wfc = new WaveFunctionCollapse(this.inputImage, this.outputImage, patternSize, this.outputWidth, this.outputHeight, this.maxIterations, this.equalWeights);
 }
Exemple #5
0
    // Start is called before the first frame update
    void Start()
    {
        Mode            gameMode             = LevelModeSetup.mode;
        List <CellMode> proceduralGeneration = new List <CellMode>();

        /*
         *  WAVE FUNCTION COLLAPSE
         */
        if (gameMode == Mode.Wfc)
        {
            wfc = new WaveFunctionCollapse(inputTilemap, outupTilemap, 1, LEVEL_WIDTH, LEVEL_HEIGHT, 500, true);
            wfc.CreateNewTileMap();
            Tilemap    tl       = wfc.GetOutputTileMap();
            BoundsInt  bounds   = tl.cellBounds;
            TileBase[] allTiles = tl.GetTilesBlock(bounds);


            // 5 tries to create a level with wfc
            int triesMax = 5;
            int tries    = 0;

            while (allTiles.Length == 0 || tries < triesMax)
            {
                Debug.Log("tries");
                Debug.Log(tries);
                wfc.CreateNewTileMap();
                tl       = wfc.GetOutputTileMap();
                bounds   = tl.cellBounds;
                allTiles = tl.GetTilesBlock(bounds);

                tries++;
            }

            // Create a level with wfc tiles
            if (allTiles.Length > 0)
            {
                setPGFromWFCOutput(allTiles, proceduralGeneration);
            }
            else
            {
                proceduralGeneration = generateMap();
            }
        }

        /*
         *  Safety
         */
        if (gameMode == Mode.Safety)
        {
            proceduralGeneration = generateMap();
        }

        // Instantiate level
        for (int i = 0; i < proceduralGeneration.Count; i++)
        {
            instantiateFor(proceduralGeneration[i], i);
        }

        // Place end portal
        PlacePortal(proceduralGeneration);
    }