Пример #1
0
        private void generateNextLevel()
        {
            baseMazeEngine.destroyImmediateMazeGeometry();

            List <QVector2IntDir> exitPositionList = baseMazeEngine.getExitPositionList();

            if (exitPositionList.Count > 1)
            {
                exitPositionList.RemoveAt(0);
                baseMazeEngine.setExitPositionList(exitPositionList);
            }

            List <QVector2Int> obstaclePositionList = new List <QVector2Int>();

            if (prevMazeEngine == null)
            {
                prevRect = new QRectInt(QMath.getRandom(1, baseMazeEngine.getMazeWidth() - CHILD_MAZE_SIZE - 2),
                                        QMath.getRandom(1, baseMazeEngine.getMazeHeight() - CHILD_MAZE_SIZE - 2), CHILD_MAZE_SIZE, CHILD_MAZE_SIZE);
                obstaclePositionList.AddRange(rectToList(prevRect));
                prevMazeEngine = createChildMaze(prevRect, childMazeEngine_1);
                prevMazeEngine.generateMaze();

                player.setPosition(prevMazeEngine.transform.TransformPoint(prevMazeEngine.getFinishPositionList()[0].toVector3()));
            }
            else
            {
                prevMazeEngine.destroyImmediateMazeGeometry();
                prevRect       = nextRect;
                prevMazeEngine = nextMazeEngine;
                obstaclePositionList.AddRange(rectToList(prevRect));
            }

            nextRect = new QRectInt(QMath.getRandom(1, baseMazeEngine.getMazeWidth() - CHILD_MAZE_SIZE - 2),
                                    QMath.getRandom(1, baseMazeEngine.getMazeHeight() - CHILD_MAZE_SIZE - 2), CHILD_MAZE_SIZE, CHILD_MAZE_SIZE);
            while (isRectNear(prevRect, nextRect))
            {
                nextRect.x = QMath.getRandom(1, baseMazeEngine.getMazeWidth() - CHILD_MAZE_SIZE - 2);
                nextRect.y = QMath.getRandom(1, baseMazeEngine.getMazeHeight() - CHILD_MAZE_SIZE - 2);
            }

            obstaclePositionList.AddRange(rectToList(nextRect));

            baseMazeEngine.setObstaclePositionList(obstaclePositionList);
            nextMazeEngine = createChildMaze(nextRect, prevMazeEngine == childMazeEngine_1 ? childMazeEngine_2 : childMazeEngine_1);
            nextMazeEngine.generateMaze();
            List <QVector2IntDir> nextMazeEngineFinishPositionList = nextMazeEngine.getFinishPositionList();

            finishTransform.parent        = nextMazeEngine.getMazeData()[nextMazeEngineFinishPositionList[0].x][nextMazeEngineFinishPositionList[0].y].geometry.transform;
            finishTransform.localPosition = new Vector3();

            player.setGoal(nextMazeEngine.transform.TransformPoint(nextMazeEngineFinishPositionList[0].toVector3()), goalReachedHandler);

            baseMazeEngine.generateMaze();

            currentLevel++;
            levelText.text = "LEVEL: " + currentLevel;
        }
Пример #2
0
    public void PositionPlayer()
    {
        //Check if there is a FPC in the scene and position it
        //Get the QFPSController component attached to the player
        QFPSController fpsController = player.GetComponent <QFPSController>();

        //Get the list of start points from the mazeEngine and store them in the variable startPoints
        List <QVector2IntDir> startPoints = mazeEngine.getStartPositionList();

        //Check that the fpsController is not null
        if (fpsController != null)
        {
            //Check if start list count is zero
            if (startPoints.Count == 0) //no start points specified
            {
                //Set the start point to a Random position
                fpsController.transform.position = new Vector3(Random.Range(0, mazeEngine.getMazeWidth()), 1, Random.Range(0, mazeEngine.getMazeHeight()));
            }
            else
            {
                //Set it to the first start position in the list
                QVector2IntDir startPoint = startPoints[Random.Range(0, startPoints.Count - 1)];

                //Position the player object rand scale the x and z position according to the maze's width and height
                //The y-position is fixed at 0.01f
                fpsController.transform.position = new Vector3(startPoint.x * mazeEngine.getMazePieceWidth(), 0.01f, -startPoint.y * mazeEngine.getMazePieceHeight());

                //Rotate the Player
                fpsController.setRotation(Quaternion.AngleAxis((int)startPoint.direction * 90, Vector3.up));
            }
        }
    }
Пример #3
0
        private void generateNextPart()
        {
            QMazeEngine mazeEngine = (QMazeEngine)GameObject.Instantiate(mazeEnginePrefab);

            mazeEngine.getMazePiecePack().getPiece(QMazePieceType.Intersection).use = false;
            mazeEngine.transform.position = new Vector3(currentPartId * mazeEngine.getMazeWidth() * mazeEngine.getMazePieceWidth(), 0, 0);
            parts.Enqueue(mazeEngine);

            if (currentPartId == 0)
            {
                List <QVector2IntDir> startPositionList = new List <QVector2IntDir>();
                startPositionList.Add(new QVector2IntDir(0, 0, QMazeOutputDirection.NotSpecified));
                mazeEngine.setStartPositionList(startPositionList);

                lastExitY = QMath.getRandom(0, mazeEngine.getMazeHeight() - 1);

                List <QVector2IntDir> exitPositionList = new List <QVector2IntDir>();
                exitPositionList.Add(new QVector2IntDir(mazeEngine.getMazeWidth() - 1, lastExitY, QMazeOutputDirection.E));
                mazeEngine.setExitPositionList(exitPositionList);
            }
            else
            {
                List <QVector2IntDir> exitPositionList = new List <QVector2IntDir>();
                exitPositionList.Add(new QVector2IntDir(0, lastExitY, QMazeOutputDirection.W));

                lastExitY = QMath.getRandom(0, mazeEngine.getMazeHeight() - 1);

                exitPositionList.Add(new QVector2IntDir(mazeEngine.getMazeWidth() - 1, lastExitY, QMazeOutputDirection.E));
                mazeEngine.setExitPositionList(exitPositionList);
            }

            GameObject block = (GameObject)GameObject.Instantiate(blockPrefab);

            block.transform.parent   = mazeEngine.gameObject.transform;
            block.transform.position = new Vector3(((currentPartId + 1) * mazeEngine.getMazeWidth() - 0.5f) * mazeEngine.getMazePieceWidth(), 0, -lastExitY * mazeEngine.getMazePieceHeight());
            block.GetComponent <QBlock>().triggerHandlerEvent += blockHandler;
            mazeEngine.generateMazeAsync(this, 0.016f);

            levelText.text = "LEVEL: " + currentPartId;
            currentPartId++;
        }