Esempio n. 1
0
    private void ExpandNodeChance(int expandThreshold = 33)
    {
        int[,] _newMapGrid = _mapGrid;

        for (int y = 0; y < mapSize; y++)
        {
            for (int x = 0; x < mapSize; x++)
            {
                if (_mapGrid[y, x] != 0)
                {
                    continue;
                }

                int[,] neighbours = GridMath.GetNeighbours(_mapGrid, new Vector2Int(x, y));
                if (!GridMath.NeighboursContainsX(neighbours, 1))
                {
                    continue;
                }


                if (Roll(33))
                {
                    _newMapGrid[y, x] = 1;
                }
            }
        }

        _mapGrid = _newMapGrid;
    }
Esempio n. 2
0
    private void LightGenerate(Room room, int[,] collideGrid)
    {
        for (int y = 0; y < room.Height; y++)
        {
            for (int x = 0; x < room.Width; x++)
            {
                if (collideGrid[y, x] != 3)
                {
                    continue;
                }

                int[,] neighbours = GridMath.GetNeighbours(collideGrid, new Vector2Int(x, y), 0);

                // if empty below
                if (neighbours[2, 1] == 0)
                {
                    if (Roll.Chance(5))
                    {
                        Vector3 worldLocation = new Vector3(x - Mathf.FloorToInt(room.Width / 2) + 0.5f, y - Mathf.FloorToInt(room.Height / 2) + 0.5f, 0f);

                        GameObject torch = Instantiate(_torchPrefab, worldLocation, Quaternion.identity);
                        torch.transform.parent = room.LightContainer;
                    }
                }
            }
        }
    }
Esempio n. 3
0
    private Tile SelectPadTile(Vector2Int loc, int[,] padGrid)
    {
        int[,] neighbours = GridMath.GetNeighbours(padGrid, loc);
        string gridType = GridMath.Comparison(neighbours, GridMath.PadComparisonGrids, 1);

        if (gridType != null)
        {
            return(_padTiles[gridType]);
        }

        return(_wallTiles["wall"]);
    }
Esempio n. 4
0
    private Tile SelectWallTile(Vector2Int loc, int[,] collideGrid)
    {
        int[,] neighbours = GridMath.GetNeighbours(collideGrid, loc);
        string gridType = GridMath.Comparison(neighbours, GridMath.WallComparisonGrids);

        if (gridType != null)
        {
            return(_wallTiles[gridType]);
        }

        return(_wallTiles["wall"]);
    }
Esempio n. 5
0
    private void RemoveUnreachableNodes()
    {
        for (int y = 0; y < mapSize; y++)
        {
            for (int x = 0; x < mapSize; x++)
            {
                int[,] neighbours = GridMath.GetNeighbours(_mapGrid, new Vector2Int(x, y), 0);

                if (GridMath.CheckSurroundedCardinal(neighbours, 0))
                {
                    _mapGrid[y, x] = 0;
                }
            }
        }
    }
Esempio n. 6
0
    private void RemoveSurroundedNodes()
    {
        for (int y = 0; y < mapSize; y++)
        {
            for (int x = 0; x < mapSize; x++)
            {
                int[,] neighbours = GridMath.GetNeighbours(_mapGrid, new Vector2Int(x, y), 1);

                if (GridMath.CheckSurroundedFully(neighbours, 1))
                {
                    _mapGrid[y, x] = 0;
                }
            }
        }
    }
Esempio n. 7
0
 private void WallsFillSurrounded(Room room, int[,] collideGrid)
 {
     for (int y = 0; y < room.Height; y++)
     {
         for (int x = 0; x < room.Width; x++)
         {
             if (collideGrid[y, x] == 0)
             {
                 Vector2Int loc = new Vector2Int(x, y);
                 int[,] neighbours = GridMath.GetNeighbours(collideGrid, loc);
                 if (GridMath.CheckSurroundedCardinal(neighbours, 2))
                 {
                     collideGrid[y, x] = 2;
                 }
             }
         }
     }
 }
Esempio n. 8
0
    private int[] CalculateGatesNeeded(Vector2Int loc)
    {
        int[] gates = { 0, 0, 0, 0 };
        int[,] neighbours = GridMath.GetNeighbours(_mapGrid, new Vector2Int(loc.x, loc.y), 0);

        if (neighbours[0, 1] == 1)
        {
            gates[0] = 1;
        }
        if (neighbours[1, 2] == 1)
        {
            gates[1] = 1;
        }
        if (neighbours[2, 1] == 1)
        {
            gates[2] = 1;
        }
        if (neighbours[1, 0] == 1)
        {
            gates[3] = 1;
        }

        return(gates);
    }