// private void Start() // { // if (mazeSize < 5) // mazeSize = 5; // else if (mazeSize > 100) // mazeSize = 100; // } public void GenerateNewMaze(int newMazeSize) { mazeSize = newMazeSize; if (mazeSize < 5) { mazeSize = 5; } else if (mazeSize > 100) { mazeSize = 100; } GenerateMazeSlots(); SetReferences(); GeneratePath(); GenerateFillers(); foreach (GameObject[] yLine in _mazeArray) { foreach (GameObject objElem in yLine) { MazeElement mazeElem = objElem.GetComponent <MazeElement>(); mazeElem.ShowPath(true); } } // Set Final cell area final.transform.position = _mazeArray[mazeSize - 1][mazeSize - 1].transform.position; }
public static void ParseData(string content, string fileName) { if (fileName.Contains("Element")) { MazeElement element = new MazeElement(); element.elementId_ = int.Parse(fileName.Substring(fileName.LastIndexOf("_") + 1, fileName.IndexOf(".xml") - 1 - fileName.LastIndexOf("_"))); MazeElement.ParseXML(content, element); mazeElements_.Add(element.elementId_, element); } else { MazeData data = new MazeData(); data.mazeFileId_ = int.Parse(fileName.Substring(fileName.LastIndexOf("_") + 1, fileName.IndexOf(".xml") - 1 - fileName.LastIndexOf("_"))); data.Init(); ParseXML(content, data); if (metaData_.ContainsKey(data.id_)) { ClientLog.Instance.LogError("Same id in SceneData :" + data.id_); return; } metaData_.Add(data.mazeFileId_, data); } }
private void GenFiller(MazeElement current) { while (current != null) { current.state = "filler"; current = current.RandFiller(); } }
private void GenerateFillers() { foreach (GameObject[] yLine in _mazeArray) { foreach (GameObject objElem in yLine) { MazeElement mazeElem = objElem.GetComponent <MazeElement>(); if (mazeElem.state == "empty") { GenFiller(mazeElem); } } } }
private void SetReferences() { int y = 0; while (y < _mazeArray.Length) { int x = 0; while (x < _mazeArray[y].Length) { MazeElement current = _mazeArray[y][x].GetComponent <MazeElement>(); current.links = new MazeElement[4]; // Left 0 // Down 1 // Right 2 // Up 3 // Set Left Link if (x > 0) { current.links[0] = _mazeArray[y][x - 1].GetComponent <MazeElement>(); } // Set Down Link if (y < mazeSize - 1) { current.links[1] = _mazeArray[y + 1][x].GetComponent <MazeElement>(); } // Set Right Link if (x < mazeSize - 1) { current.links[2] = _mazeArray[y][x + 1].GetComponent <MazeElement>(); } // Set Up Link if (y > 0) { current.links[3] = _mazeArray[y - 1][x].GetComponent <MazeElement>(); } current.posY = y; current.posX = x; x++; } y++; } }
public void Clone(MazeElement ele) { this.elementId_ = ele.elementId_; this.parent_ = ele.parent_; this.rotateX_ = ele.rotateX_; this.rotateY_ = ele.rotateY_; this.rotateZ_ = ele.rotateZ_; this.rotateW_ = ele.rotateW_; this.x_ = ele.x_; this.y_ = ele.y_; this.z_ = ele.z_; this.name_ = ele.name_; if (ele.lights_ != null) { this.lights_ = new List <Mazelight>(ele.lights_); } for (int i = 0; i < ele.elements_.Count; ++i) { elements_.Add(ele.elements_[i]); } }
private void GeneratePath() { // Initialize at start MazeElement curElem = _mazeArray[0][0].GetComponent <MazeElement>(); // Start coordinates of maze int y = 0; int x = 0; curElem.OpenSide(3, true); curElem.OpenSide(0, true); // Random Walk till the last line; while (y < mazeSize - 1) { // Debug.Log("y - " + y + " x - " + x); curElem = curElem.RandForward(); curElem.RefreshCoordinates(ref y, ref x); curElem.state = "path"; } // When on last line, go to final cell while (x < mazeSize - 1) { // Debug.Log("y - " + y + " x - " + x); curElem = curElem.FinishForward(); curElem.RefreshCoordinates(ref y, ref x); curElem.state = "path"; } if (x == mazeSize - 1 && y == mazeSize - 1) { curElem.state = "finish"; curElem.OpenSide(1, true); curElem.OpenSide(2, true); return; } throw new Exception("Generator didn't make it to Finish"); }
// public ParamData(int iv, MazeElement element) { iParam = iv; mazeElement = element; }
public static void ParseXML(string content, MazeElement data) { XmlDocument doc = new XmlDocument(); doc.LoadXml(content); XmlNode rootNode = doc.SelectSingleNode("/MazeTerrain"); MazeElement element = null; foreach (XmlNode subNode in rootNode.ChildNodes) { if (subNode.Name.Equals("cubes")) { foreach (XmlNode cubeNode in subNode.ChildNodes) { if (cubeNode.Name.Equals("MCube")) { element = new MazeElement(); foreach (XmlAttribute attr in cubeNode.Attributes) { if (attr.Name.Equals("parent")) { element.parent_ = attr.Value; } if (attr.Name.Equals("rw")) { element.rotateW_ = float.Parse(attr.Value); } if (attr.Name.Equals("rx")) { element.rotateX_ = float.Parse(attr.Value); } if (attr.Name.Equals("ry")) { element.rotateY_ = float.Parse(attr.Value); } if (attr.Name.Equals("rz")) { element.rotateZ_ = float.Parse(attr.Value); } if (attr.Name.Equals("x")) { element.x_ = float.Parse(attr.Value); } if (attr.Name.Equals("y")) { element.y_ = float.Parse(attr.Value); } if (attr.Name.Equals("z")) { element.z_ = float.Parse(attr.Value); } if (attr.Name.Equals("name")) { element.name_ = attr.Value; } } } data.elements_.Add(element); } if (subNode.Name.Equals("lights")) { if (data.lights_ == null) { data.lights_ = new List <Mazelight>(); } Mazelight light = new Mazelight(); foreach (XmlAttribute attr in subNode.Attributes) { if (attr.Name.Equals("name")) { light.name_ = attr.Value; } if (attr.Name.Equals("Intensity")) { light.intensity_ = float.Parse(attr.Value); } if (attr.Name.Equals("Range")) { light.range_ = float.Parse(attr.Value); } if (attr.Name.Equals("SpotAngle")) { light.spotAngle_ = float.Parse(attr.Value); } if (attr.Name.Equals("CookieSize")) { light.cookieSize_ = float.Parse(attr.Value); } if (attr.Name.Equals("x")) { light.x_ = float.Parse(attr.Value); } if (attr.Name.Equals("y")) { light.y_ = float.Parse(attr.Value); } if (attr.Name.Equals("z")) { light.z_ = float.Parse(attr.Value); } if (attr.Name.Equals("a")) { light.a_ = float.Parse(attr.Value); } if (attr.Name.Equals("r")) { light.r_ = float.Parse(attr.Value); } if (attr.Name.Equals("g")) { light.g_ = float.Parse(attr.Value); } if (attr.Name.Equals("b")) { light.b_ = float.Parse(attr.Value); } if (attr.Name.Equals("rx")) { light.rx_ = float.Parse(attr.Value); } if (attr.Name.Equals("ry")) { light.ry_ = float.Parse(attr.Value); } if (attr.Name.Equals("rz")) { light.rz_ = float.Parse(attr.Value); } if (attr.Name.Equals("rw")) { light.rw_ = float.Parse(attr.Value); } } data.lights_.Add(light); } } } }