예제 #1
0
    /**
     * Generate grid centered on (0,0) with all walls intact
     */
    private IEnumerator GenerateGrid(MazeOptions mazeOptions)
    {
        mazeData = new GridCellData[mazeOptions.Width, mazeOptions.Height];
        int centerX = (mazeOptions.Width - 1) / 2;
        int centerY = (mazeOptions.Height - 1) / 2;

        //center X and center Y will be located at 0, 0
        for (int y = 0; y < mazeOptions.Height; y++)
        {
            for (int x = 0; x < mazeOptions.Width; x++)
            {
                mazeData[x, y] = CreateCell(x, y, centerX, centerY);
                if (x == 0 && y == 0)
                {
                    startPoint.transform.position         = mazeData[0, 0].transform.position;
                    gameContext.player.transform.position = new Vector3(
                        startPoint.transform.position.x,
                        gameContext.player.transform.position.y,
                        startPoint.transform.position.z);
                    gameContext.playerBody.transform.position = new Vector3(
                        startPoint.transform.position.x,
                        gameContext.playerBody.transform.position.y,
                        startPoint.transform.position.z);
                }
                yield return(null);
            }
        }

        StartCoroutine(GenerateMaze(mazeData, gameContext.mazeOptions, mazeData[0, 0]));
    }
예제 #2
0
 private void Awake()
 {
     // singleton pattern implementation
     // Check if another version of this static class is active in the scene
     if (instance != null && instance != this)
     {
         // If so then destroy it
         Destroy(gameObject);
     }
     else
     {
         instance = this;
     }
 }
예제 #3
0
    private IEnumerator GenerateMaze(GridCellData[,] mazeData, MazeOptions mazeOptions, GridCellData startingCell)
    {
        int maxX   = mazeData.GetLength(0) - 1;
        int maxY   = mazeData.GetLength(1) - 1;
        int startX = startingCell.x;
        int startY = startingCell.y;
        List <GridCellData> deadEnds = new List <GridCellData>();
        // Stack for recursive generation algorithm
        Stack <GridCellData> stack = new Stack <GridCellData>();

        GridCellData currentCell = startingCell;

        bool nextCellFound = false;

        do
        {
            currentCell.isVisited = true;                                      // Marking current cell as visited
            GridCellData nextCell = GetRandomNeighbour(currentCell, mazeData); // Get random neighbor cell as a next one
            if (nextCell != null)                                              // If there is available next cell, push current cell to stack and assigning next to current
            {
                // If there is at least one available neighbor, remove walls between current and next cell
                RemoveWalls(currentCell, nextCell);
                stack.Push(currentCell);
                currentCell   = nextCell;
                nextCellFound = true;
            }
            else// Else backtrack to cell that has at least one available neighbor
            {
                if (nextCellFound && // If next cell was found in previous iteration but not in this one, this is a dead end
                    (currentCell.x != startX || currentCell.y != startY)    // Dont make the starting point also the exit point
                    )
                {
                    deadEnds.Add(currentCell);
                }
                if (stack.Count > 0)
                {
                    currentCell = stack.Pop();
                }
                nextCellFound = false;
            }
            yield return(null);
        } while (stack.Count != 0);
        // Relocate exit point
        exitCell = deadEnds.Count > 0 ? deadEnds[rand.Next(deadEnds.Count)] : mazeData[maxX, maxY];
        exitPoint.transform.position = new Vector3(exitCell.floor.transform.position.x, exitCell.floor.transform.position.y, exitCell.floor.transform.position.z);
    }
예제 #4
0
        /// <summary>
        /// Load graphics content for the screen.
        /// </summary>
        public override void LoadContent()
        {
            this._content = new ContentManager(this.ScreenManager.Game.Services, "Content");

            MazeOptions options = new MazeOptions(
                new Vector2(2, 3),
                28,
                13,
                Content.Load <Texture2D>(Constants.SOFTPRODOLLAR_TEXTURE));

            _maze = new Maze(this.ScreenManager.GraphicsDevice, options);

            _bossTexture           = Content.Load <Texture2D>("Textures/Objects/MazeGame/Boss");
            _conferenceRoomTexture = Content.Load <Texture2D>("Textures/Objects/MazeGame/ConferenceRoom");

            base.LoadContent();
        }
예제 #5
0
 void Awake()
 {
     if (instance == null)
     {
         DontDestroyOnLoad(gameObject);
         DontDestroyOnLoad(player);
         DontDestroyOnLoad(playerBody);
         DontDestroyOnLoad(exitPoint);
         instance    = this;
         preferences = new Preferences();
         upgrades    = new Upgrades();
         mazeOptions = new MazeOptions();
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }