コード例 #1
0
ファイル: Level.cs プロジェクト: brucelevis/pacing-fighter
    /// <summary>
    /// Generates a level given the properties defined by its member variables.
    /// </summary>
    /// <param name="startPosition">The center position of the first cell in the level grid.</param>
    /// <param name="startCellAnchor">The position of the first cell, relative to the grid. .</param>
    /// <param name="endCellAnchor">The position to which the last cell of the grid is anchored (i.e., is the final
    /// cell at the top, bottom, left or right of the grid?) </param>
    public void GenerateLevel(Vector2 startCellPosition, CellAnchor startCellAnchor, CellAnchor endCellAnchor)
    {
        if (paused)
        {
            return;
        }

        // Store the given arguments in their respective member variables
        this.startCellPosition = startCellPosition;
        this.startCellAnchor   = startCellAnchor;
        this.endCellAnchor     = endCellAnchor;

        // Create the level grid which stores the GameObjects and cell information for all cells in the level.
        grid = new LevelCell[rows, columns];

        // Set the seed for the random number generator. Ensures that, given the same seed, the same level will be reproduced.
        Random.seed = this.seed;

        // Compute and store the (row,column) coordinates of the starting/ending cells of the level grid.
        startCellCoordinates = ComputeStartCellCoordinates();
        endCellCoordinates   = ComputeEndCellCoordinates();

        // Create the GameObject which will act as a parent to every GameObject in the level.
        levelHolder = new GameObject("Level").transform;

        Debug.Log("Branch Navigator: " + branchNavigator.ToString());

        // Generate the golden path for the level. This is the main road that leads from start to finish.
        GenerateGoldenPath();

        Debug.Log("Branch Navigator: " + branchNavigator.ToString());

        // Generate the branches in the level maze. These are divergences in the maze that lead to nowhere
        GenerateBranches();

        Debug.Log("Branch Navigator: " + branchNavigator.ToString());

        // Iterate through the level grid and populate all the non-occupied cells with obstacles.
        GenerateObstacleCells();

        // Generates the level cells which close off the level.
        GenerateBoundaries();

        // Update the 'vertical/horizontalBounds' variables to store the positional bounds of the level.
        UpdateVerticalBounds();
        UpdateHorizontalBounds();
    }