public void levelDefeat() { //parse level string corresponding to current level string[] splitState = gameStates [currentLevel].Split(' '); int rows = Int32.Parse(splitState [0]); int cols = Int32.Parse(splitState [1]); string state = splitState [2]; int startRow = Int32.Parse(splitState [3]); int startCol = Int32.Parse(splitState [4]); int endRow = Int32.Parse(splitState [5]); int endCol = Int32.Parse(splitState [6]); string bananaString = splitState[7]; //destroy current gameobjects foreach (List <GameObject> r in generator.objectGrid) { foreach (GameObject g in r) { Destroy(g); } r.Clear(); } generator.objectGrid.Clear(); foreach (GameObject b in bananaGen.bananaList) { Destroy(b); } //generate the actual grid - also based on whether transposition is set if (!transposed) { generator.actualGenerateGrid(rows, cols, state, startRow, startCol, endRow, endCol); bananaGen.GenerateBananas(rows, cols, bananaString); } else { generator.generateTransposedGrid(rows, cols, state, startRow, startCol, endRow, endCol); bananaGen.generateTBananas(rows, cols, bananaString); } //set necessary values on player GameObject obj = generator.objectGrid [startRow - 1] [startCol - 1]; player.StopMovement(); player.birded = false; player.birdMoves = 0; // Move to new start player.transform.position = new Vector3(obj.transform.position.x, player.transform.position.y, obj.transform.position.z); //obj.transform.position.z player.bananaCount = 0; }
IEnumerator generate() { //wait for first map to be generated (otherwise this will be overrided yield return(new WaitForSeconds(1f)); GM = GameObject.FindGameObjectWithTag("GameMaster").GetComponent <gameMaster> (); BananaGenerator bananaGen = GameObject.FindGameObjectWithTag("GameController").GetComponent <BananaGenerator> (); Monkey player = GameObject.FindGameObjectWithTag("Monkey").GetComponent <Monkey> (); //follow standard level generation steps - see GameMaster script string[] splitState = GM.gameStates [level].Split(' '); int rows = Int32.Parse(splitState [0]); int cols = Int32.Parse(splitState [1]); string state = splitState [2]; int startRow = Int32.Parse(splitState [3]); int startCol = Int32.Parse(splitState [4]); int endRow = Int32.Parse(splitState [5]); int endCol = Int32.Parse(splitState [6]); string bananaString = splitState[7]; gridRoot generator = GameObject.FindGameObjectWithTag("GameController").GetComponent <gridRoot> (); foreach (List <GameObject> r in generator.objectGrid) { foreach (GameObject g in r) { Destroy(g); } r.Clear(); } generator.objectGrid.Clear(); foreach (GameObject b in bananaGen.bananaList) { Destroy(b); } generator.actualGenerateGrid(rows, cols, state, startRow, startCol, endRow, endCol); //generator.generateTransposedGrid(rows, cols, state, startRow, startCol, endRow, endCol); bananaGen.GenerateBananas(rows, cols, bananaString); GameObject obj = generator.objectGrid [startRow - 1] [startCol - 1]; //Stop motion player.StopMovement(); player.birded = false; player.birdMoves = 0; // Move to new start player.transform.position = new Vector3(obj.transform.position.x, player.transform.position.y, obj.transform.position.z); //obj.transform.position.z player.bananaCount = 0; GM.currentLevel = level; }