public static IEnumerator move(List <MazeNode> Path) { GamePlay.counterUp(); GamePlay.scoreUp(10); GamePlay.updateCounters(); MazeBuilder.ClearMaze(); int x = Path[Path.Count - 1].x; int y = Path[Path.Count - 1].y; ColorPallet.CallRecolor(); while (Path.Count > 1) { Vector3 last = new Vector3(Path[0].x, Path[0].y, 0) * 10; Vector3 next = new Vector3(Path[1].x, Path[1].y, 0) * 10; float tween = 0; while (Vector3.Distance(motionControl.tr.position, next) > 0.5f) { motionControl.tr.position = Vector3.Lerp(last, next, tween); tween += Time.deltaTime * motionControl.s; yield return(new WaitForEndOfFrame()); } Path.RemoveAt(0); } SaveData.saveMove(new MazeNodeData(x, y), GamePlay.getCounter(), GamePlay.getScore()); MazeBuilder.SetClickZone(x, y); }
public static void CallVictory(bool b) { if (victory != null) { ColorPallet.CallRecolor(); victory(b); } }
public void ChangeColor(int i) { if (i >= -1 && i <= 7) { ColorPallet.SetIndex(i); ColorPallet.CallRecolor(); } }
public static void counterUp() { counter++; int output = remaining - counter; if (output < 0 && gameOver != null) { ColorPallet.CallRecolor(); gameOver(); } }
public void BuildTheMaze() { setValues(); maze = new List <MazeNode>(); solution = new List <MazeNode>(); toBeginning = new List <MazeNode>(); toEnd = new List <MazeNode>(); ground = new List <List <GameObject> > (); vertWalls = new List <List <GameObject> > (); horiWalls = new List <List <GameObject> > (); cam = _camera.GetComponent <CameraControl> (); // ******************** Size Camera ********************** _camera.transform.position = new Vector3((width - 1) * 5, (((17F / 3F) * height) - 6), -10); cam.setMax(((17f / 3f) * height) + 1); // ******************** Full Grid Build ************************* if (width > 0 && height > 0) { o = Instantiate(goal, new Vector3((width - 1) * 10, (height - 1) * 10, -1), Quaternion.identity) as GameObject; o = Instantiate(baseFloor, new Vector3((width - 1) * 5, (height - 1) * 5, 3), Quaternion.Euler(270, 0, 0)) as GameObject; o.transform.localScale = new Vector3(width, 1, height); o.transform.parent = floorParent.transform; for (int i = 0; i <= width; i++) { List <GameObject> column = new List <GameObject>(); List <GameObject> vert = new List <GameObject>(); List <GameObject> hori = new List <GameObject>(); for (int j = 0; j < height; j++) { if (i < width) { // Floors o = Instantiate(floor, new Vector3(i * 10, j * 10, 1), Quaternion.Euler(270, 0, 0)) as GameObject; o.GetComponent <FloorController>().x = i; o.GetComponent <FloorController>().y = j; o.transform.parent = floorParent.transform; column.Add(o); maze.Add(new MazeNode(i, j)); // Horizontal Walls o = Instantiate(wall, new Vector3((i * 10) + 1, (j * 10) - 5, 0), Quaternion.Euler(0, -90, 90)) as GameObject; o.transform.parent = wallParent.transform; hori.Add(o); } // Vertical Walls o = Instantiate(wall, new Vector3((i * 10) - 5, (j * 10) - 1, 0), Quaternion.Euler(-90, 0, 0)) as GameObject; o.transform.parent = wallParent.transform; vert.Add(o); } // Top Horizontal Walls if (i < width) { o = Instantiate(wall, new Vector3((i * 10) + 1, (height * 10) - 5, 0), Quaternion.Euler(0, -90, 90)) as GameObject; o.transform.parent = wallParent.transform; } ground.Add(column); vertWalls.Add(vert); horiWalls.Add(hori); } } foreach (MazeNode node in maze) { node.FindAdjacentNodes(maze); } // ***************** Create Maze ******************* start = maze[Random.Range(0, maze.Count)]; start.start = true; start.makeMaze(); solution = GetSolution(toBeginning, toEnd); // **************** Delete Walls to Form Maze ******************* foreach (MazeNode node in maze) { if (node.back != null) { if (node.back.x != node.x) { vertWalls[Mathf.Max(node.x, node.back.x)][node.y].transform.parent = null; vertWalls[Mathf.Max(node.x, node.back.x)][node.y].GetComponent <CustomColoring>().removeMe(); Destroy(vertWalls[Mathf.Max(node.x, node.back.x)][node.y]); } if (node.back.y != node.y) { horiWalls[node.x][Mathf.Max(node.y, node.back.y)].transform.parent = null; horiWalls[node.x][Mathf.Max(node.y, node.back.y)].GetComponent <CustomColoring>().removeMe(); Destroy(horiWalls[node.x][Mathf.Max(node.y, node.back.y)]); } } } // ***************** Set Remaining Object to Maze Parent Object *************** current = maze[0]; ClearMaze(); SetClickZone(0, 0); ColorPallet.SetIndex(SaveData.GetSave().ColorIndex); ColorPallet.CallRecolor(); GamePlay.setRemaining(solution.Count); MeshFilter[] meshFilters = wallParent.GetComponentsInChildren <MeshFilter>(); CombineInstance[] combine = new CombineInstance[meshFilters.Length - 1]; int z = 0; for (int n = 0; n < meshFilters.Length; n++) { if (meshFilters[n].sharedMesh == null) { continue; } combine[z].mesh = meshFilters[n].sharedMesh; combine[z++].transform = meshFilters[n].transform.localToWorldMatrix; meshFilters[n].gameObject.SetActive(false); } wallParent.GetComponent <MeshFilter>().mesh = new Mesh(); wallParent.GetComponent <MeshFilter>().mesh.CombineMeshes(combine); wallParent.gameObject.SetActive(true); // ****************** Save Maze *********************************************** List <MazeNodeData> mazeData = new List <MazeNodeData>(); foreach (MazeNode node in maze) { mazeData.Add(node.convertToMazeNodeData()); } List <MazeNodeData> solutionData = new List <MazeNodeData>(); foreach (MazeNode node in solution) { solutionData.Add(node.convertToMazeNodeData()); } SaveData.savePuzzle(mazeData, level, solutionData, width, height); SaveData.saveMove(new MazeNodeData(0, 0), GamePlay.getCounter(), GamePlay.getScore()); }
public void BuildTheMaze(Save saveData) { data.LoadSavedData(saveData); setValues(); maze = new List <MazeNode>(); solution = new List <MazeNode>(); toBeginning = new List <MazeNode>(); toEnd = new List <MazeNode>(); ground = new List <List <GameObject> > (); vertWalls = new List <List <GameObject> > (); horiWalls = new List <List <GameObject> > (); cam = _camera.GetComponent <CameraControl> (); // ******************** Size Camera ********************** _camera.transform.position = new Vector3((width - 1) * 5, (((17F / 3F) * height) - 6), -10); cam.setMax(((17f / 3f) * height) + 1); // ******************** Full Grid Build ************************* if (width > 0 && height > 0) { o = Instantiate(goal, new Vector3((width - 1) * 10, (height - 1) * 10, -1), Quaternion.identity) as GameObject; o = Instantiate(baseFloor, new Vector3((width - 1) * 5, (height - 1) * 5, 3), Quaternion.Euler(270, 0, 0)) as GameObject; o.transform.localScale = new Vector3(width, 1, height); o.transform.parent = floorParent.transform; for (int i = 0; i <= width; i++) { List <GameObject> column = new List <GameObject>(); List <GameObject> vert = new List <GameObject>(); List <GameObject> hori = new List <GameObject>(); for (int j = 0; j < height; j++) { if (i < width) { // Floors o = Instantiate(floor, new Vector3(i * 10, j * 10, 1), Quaternion.Euler(270, 0, 0)) as GameObject; o.GetComponent <FloorController>().x = i; o.GetComponent <FloorController>().y = j; o.transform.parent = floorParent.transform; column.Add(o); maze.Add(new MazeNode(i, j)); // Horizontal Walls o = Instantiate(wall, new Vector3((i * 10) + 1, (j * 10) - 5, 0), Quaternion.Euler(0, -90, 90)) as GameObject; o.transform.parent = wallParent.transform; hori.Add(o); } // Vertical Walls o = Instantiate(wall, new Vector3((i * 10) - 5, (j * 10) - 1, 0), Quaternion.Euler(-90, 0, 0)) as GameObject; o.transform.parent = wallParent.transform; vert.Add(o); } // Top Horizontal Walls if (i < width) { o = Instantiate(wall, new Vector3((i * 10) + 1, (height * 10) - 5, 0), Quaternion.Euler(0, -90, 90)) as GameObject; } ground.Add(column); vertWalls.Add(vert); horiWalls.Add(hori); } } foreach (MazeNode node in maze) { node.FindAdjacentNodes(maze); } // ***************** Create Maze ******************* for (int i = 0; i < maze.Count; i++) { foreach (direction dir in saveData.CurrentMaze[i].dir) { maze[i].forwards.Add(maze[i].AdjacentNodes[(int)dir]); } } foreach (MazeNodeData node in saveData.CurrentSolution) { solution.Add(new MazeNode(node.x, node.y)); } // **************** Delete Walls to Form Maze ******************* foreach (MazeNode node in maze) { if (node.forwards.Count > 0) { foreach (MazeNode forward in node.forwards) { if (node.x != forward.x) { int x = Mathf.Max(node.x, forward.x); if (vertWalls[x][node.y] != null) { vertWalls[x][node.y].transform.parent = null; vertWalls[x][node.y].GetComponent <CustomColoring>().removeMe(); Destroy(vertWalls[x][node.y]); } } if (node.y != forward.y) { int y = Mathf.Max(node.y, forward.y); if (horiWalls[node.x][y] != null) { horiWalls[node.x][y].transform.parent = null; horiWalls[node.x][y].GetComponent <CustomColoring>().removeMe(); Destroy(horiWalls[node.x][y]); } } } } } // ***************** Set Remaining Object to Maze Parent Object *************** current = maze[(saveData.CurrentPosition.x * height) + saveData.CurrentPosition.y]; ClearMaze(); SetClickZone(saveData.CurrentPosition.x, saveData.CurrentPosition.y); ColorPallet.SetIndex(SaveData.GetSave().ColorIndex); ColorPallet.CallRecolor(); GamePlay.setRemainingFromSave(SaveData.GetSave().CurrentRemainingMoves); GamePlay.setScore(SaveData.GetSave().CurrentScore); MeshFilter[] meshFilters = wallParent.GetComponentsInChildren <MeshFilter>(); CombineInstance[] combine = new CombineInstance[meshFilters.Length - 1]; int z = 0; for (int n = 0; n < meshFilters.Length; n++) { if (meshFilters[n].sharedMesh == null) { continue; } combine[z].mesh = meshFilters[n].sharedMesh; combine[z++].transform = meshFilters[n].transform.localToWorldMatrix; meshFilters[n].gameObject.SetActive(false); } wallParent.GetComponent <MeshFilter>().mesh = new Mesh(); wallParent.GetComponent <MeshFilter>().mesh.CombineMeshes(combine); wallParent.gameObject.SetActive(true); // **************** Set Player Starting Position ****************************** hero.transform.position = new Vector3(current.x, current.y, 0) * 10; }
public void CallRecolor() { ColorPallet.CallRecolor(); }