예제 #1
0
 private void generateCave(WorldData worldData, Vector2Int pos)
 {
     for (int y = pos.y; y < pos.y + config.caveSizeBlocks; y++)
     {
         for (int x = pos.x; x < pos.x + config.caveSizeBlocks; x++)
         {
             worldData.Blocks[x, y] = WorldBlockUtils.getEmptyBlock();
         }
     }
 }
예제 #2
0
    private void connectTwoCaves(WorldData worldData, RectInt caveA, RectInt caveB)
    {
        RectInt topCaveRect         = caveA.y > caveB.y ? caveA : caveB;
        RectInt bottomCaveRect      = caveA.y < caveB.y ? caveA : caveB;
        bool    isTopCaveAtLeftSide = topCaveRect.x < bottomCaveRect.x;
        // RectInt leftCaveRect = caveA.x < caveB.x ? caveA : caveB;
        //  RectInt rightCaveRect = caveA.x > caveB.x ? caveA : caveB;

        /*Draw this part (marked with 1)
         * .:-------------:`                                                              .:-------------:`
         * :.             /.                                                              :-             /.
         * :.             /+------------------::                     /--------------------s-             /.
         * :.             //                  ./                     o                    o-             /.
         * :.             //                  ./                     o                    o-             /.
         * :.             /+--------------+/::/o                     -+-----+-------------o-             /.
         * ::....-------..+`              1    1                      1     1             -:.....-----.../.
         * `````s...../:``               1    1                      1     1              ``````s---s````
         * 1      1                 1    1                      1     1                    1   1
         * 1      1                 1`   1                      1     1                    1   1
         * 1      1           -/----/::::/---/.            `+---+:::::/---:-               1   1
         * 1      1           :-             :.            `/             ./               1   1
         * 1      1-----------o-             :.            `/             .h---------------/---/-/
         * 1`````o-           h-             :.            `/             .d                     o
         * ------::-----------o-             :.            `/             .h---------------------/
         *                :-             :.            `/             ./
         *                ./-------------/.            `/-------------:-
         */

        int     rectX      = topCaveRect.x + (topCaveRect.width / 2) - (config.pathWidthBlocks / 2);
        int     rectY      = bottomCaveRect.y + (bottomCaveRect.height / 2) - (config.pathHeightBlocks / 2);
        int     rectWidth  = config.pathWidthBlocks;
        int     rectHeight = topCaveRect.y - rectY;
        RectInt pathRect   = new RectInt(rectX, rectY, rectWidth, rectHeight);

        for (int y = pathRect.y; y < pathRect.yMax; y++)
        {
            for (int x = pathRect.x; x < pathRect.xMax; x++)
            {
                worldData.Blocks[x, y] = WorldBlockUtils.getEmptyBlock();
            }
        }

        /*Draw this part (marked with 1)
         * .:-------------:`                                                              .:-------------:`
         * :.             /.                                                              :-             /.
         * :.             /+111111111111111111::                     /11111111111111111111s-             /.
         * :.             //                  ./                     o                    o-             /.
         * :.             //                  ./                     o                    o-             /.
         * :.             /+11111111111111+/::/o                     1+11111+1111111111111o-             /.
         * ::....-------..+`              o    o                      o     o             -:.....-----.../.
         * `````s...../:``               o    o                      o     o              ``````s---s````
         * o     :-                 o    o                      o     o                    o   o
         * o     :-                 o`   o                      o     o                    o   o
         * o     :-           -/----/::::/---/.            `+---+:::::/---:-               o   o
         * o     :-           :-             :.            `/             ./               o   o
         * o     //11111111111o-             :.            `/             .h111111111111111/---/-/
         * o`````o-           h-             :.            `/             .d                     o
         * ------::11111111111o-             :.            `/             .h111111111111111111111/
         *                :-             :.            `/             ./
         *                ./-------------/.            `/-------------:-
         */

        rectX = isTopCaveAtLeftSide ? topCaveRect.x + (topCaveRect.width / 2) : bottomCaveRect.xMax;
        rectY = bottomCaveRect.y + (bottomCaveRect.height / 2) - (config.pathHeightBlocks / 2);
        if (isTopCaveAtLeftSide)
        {
            //extrude path  to left
            rectWidth = bottomCaveRect.x - rectX;
        }
        else
        {
            //extrude path to right
            rectWidth = topCaveRect.x + (topCaveRect.width / 2) - rectX;
        }
        rectHeight = config.pathHeightBlocks;
        pathRect   = new RectInt(rectX, rectY, rectWidth, rectHeight);
        for (int y = pathRect.y; y < pathRect.yMax; y++)
        {
            for (int x = pathRect.x; x < pathRect.xMax; x++)
            {
                worldData.Blocks[x, y] = WorldBlockUtils.getEmptyBlock();
            }
        }
    }