private QMazeEngine createChildMaze(QRectInt rect, QMazeEngine mazeEngine) { mazeEngine.setMazeWidth(rect.width); mazeEngine.setMazeHeight(rect.height); mazeEngine.transform.position = new Vector3(0, 0, 0); mazeEngine.transform.position = mazeEngine.transform.TransformPoint(new Vector3(rect.x, -3, -rect.y)); List <QVector2IntDir> finishPositionList = new List <QVector2IntDir>(); finishPositionList.Add(new QVector2IntDir(rect.width / 2, rect.height / 2, QMazeOutputDirection.NotSpecified)); mazeEngine.setFinishPositionList(finishPositionList); List <QVector2IntDir> exitPositionList = new List <QVector2IntDir>(); QVector2IntDir mazeExit = getExitForRect(rect); exitPositionList.Add(mazeExit); mazeEngine.setExitPositionList(exitPositionList); List <QVector2IntDir> baseMazeEngineExitPositionlist = baseMazeEngine.getExitPositionList(); baseMazeEngineExitPositionlist.Add(new QVector2IntDir(rect.x + mazeExit.x + QMazeOutput.dx[mazeExit.direction], rect.y + mazeExit.y + QMazeOutput.dy[mazeExit.direction], QMazeOutput.opposite[mazeExit.direction])); baseMazeEngine.setExitPositionList(baseMazeEngineExitPositionlist); return(mazeEngine); }
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)); } } }
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; }