示例#1
0
    private void AddFinishPoints()
    {
        //The maze engine provides a method called getFinishPositionList, which returns a list of finish points
        //Get the list of finish points from the mazeEngine and store them in the variable finishPoints
        List <QVector2IntDir> finishPoints = mazeEngine.getFinishPositionList();

        //Loop through the finish points and instantiate them
        foreach (QVector2IntDir finishPoint in finishPoints)
        {
            //Instantiate a new game object
            GameObject goFinish = Instantiate(finishPrefab) as GameObject;

            //Set the object's parent to the maze so it is correctly positioned within the maze
            goFinish.transform.parent = mazeEngine.transform;

            //Position the finish object relative to its parent (local position)
            //Scale the x and z position according to the maze's width and height
            //The y-position is fixed at 0.01f;
            float x = finishPoint.x * mazeEngine.getMazePieceWidth();
            float z = -finishPoint.y * mazeEngine.getMazePieceHeight();
            goFinish.transform.localPosition = new Vector3(x, 0.01f, z);
        }
    }
        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++;
        }
        void generateNewMaze()
        {
            mazeEngine.destroyImmediateMazeGeometry();
            mazeEngine.generateMaze();

            List <QVector2IntDir> finishPointList = mazeEngine.getFinishPositionList();

            for (int i = 0; i < finishPointList.Count; i++)
            {
                QVector2IntDir finishPosition        = finishPointList[i];
                GameObject     finishTriggerInstance = (GameObject)GameObject.Instantiate(finishTriggerPrefab);
                finishTriggerInstance.transform.parent        = mazeEngine.transform;
                finishTriggerInstance.transform.localPosition = new Vector3(finishPosition.x * mazeEngine.getMazePieceWidth(), 0.01f, -finishPosition.y * mazeEngine.getMazePieceHeight());
            }

            QFinishTrigger[] finishTriggerArray = FindObjectsOfType <QFinishTrigger>();
            if (finishTriggerArray != null)
            {
                for (int i = 0; i < finishTriggerArray.Length; i++)
                {
                    finishTriggerArray[i].triggerHandlerEvent += finishHandler;
                }
            }

            List <QVector2IntDir> startPointList = mazeEngine.getStartPositionList();

            QFPSController fpsController = FindObjectOfType <QFPSController>();

            if (fpsController != null)
            {
                if (startPointList.Count == 0)
                {
                    fpsController.gameObject.transform.position = new Vector3(0, 1, 0);
                }
                else
                {
                    QVector2IntDir startPoint = startPointList[0];
                    fpsController.gameObject.transform.position = new Vector3(startPoint.x * mazeEngine.getMazePieceWidth(), 0.9f, -startPoint.y * mazeEngine.getMazePieceHeight());
                    fpsController.setRotation(Quaternion.AngleAxis((int)startPoint.direction * 90, Vector3.up));
                }
            }

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