コード例 #1
0
    void GenerateNewMaze()
    {
        //Check that the maze engine has been specified, if not return and exit early
        if (mazeEngine == null)
        {
            return;
        }

        //destory any existing maze
        mazeEngine.destroyImmediateMazeGeometry();

        //Generate new Maze
        mazeEngine.generateMaze();

        //Add the finish points
        AddFinishPoints();

        //Position Player
        PositionPlayer();

        //Position Enemy
        PositionEnemy();

        //Increase the level counter
        currentLevel++;
    }
コード例 #2
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;
        }
コード例 #3
0
        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;
        }
コード例 #4
0
 void Start()
 {
     mazeEngine.generateMaze();
     mazeTerrainEngine.generateTerrain(mazeEngine.mazeWidth, mazeEngine.mazeHeight, mazeEngine.mazePieceWidth, mazeEngine.mazePieceHeight);
 }