public void BuildTree() { CreateSubNode(); if (LeftTop == null) { return; } foreach (ObjectGame o in listObj) { Rectangle r = new Rectangle(o.location.X, o.location.Y, o.bm.Width, o.bm.Height); if (LeftTop.rec.IntersectsWith(r)) { LeftTop.listObj.Add(o); } if (RightTop.rec.IntersectsWith(r)) { RightTop.listObj.Add(o); } if (LeftBot.rec.IntersectsWith(r)) { LeftBot.listObj.Add(o); } if (RightBot.rec.IntersectsWith(r)) { RightBot.listObj.Add(o); } } LeftTop.BuildTree(); RightTop.BuildTree(); LeftBot.BuildTree(); RightBot.BuildTree(); listObj.Clear(); }
private void btnSaveMatrix_Click(object sender, EventArgs e) { String s = ""; SaveFileDialog sv = new SaveFileDialog(); sv.ShowDialog(); StreamWriter writer = new StreamWriter(sv.FileName + ".txt"); s += listobjmap.Count + "\r\n" + "\r\n"; foreach (ObjectGame obj in listobjmap) { s += obj.ID + "\r\n"; if (obj.ID == 11) //unknow { int i = 0; foreach (ObjectGame o in listobjmap) { if (o.location.X == obj.location.X && o.location.Y == obj.location.Y - 16) { s += i + "\r\n"; } i++; } } if (obj.ID == 10) // brick { int i = 0; foreach (ObjectGame o in listobjmap) { if (o.ID == 10) { s += "0" + "\r\n"; } if (o.ID != 10 && o.location.X == obj.location.X && o.location.Y == obj.location.Y - 16) { s += i + "\r\n"; } i++; } } s += obj.location.X + "\r\n"; s += obj.location.Y + "\r\n"; s += obj.bm.Width + "\r\n"; s += obj.bm.Height + "\r\n"; s += "\r\n"; } writer.Write(s); writer.Close(); StreamWriter quadtree = new StreamWriter(sv.FileName + "Quadtree.txt"); rootNode = new QuadNode("0", new Rectangle(0, 0, pbMap.Width, pbMap.Height)); int ind = 0; foreach (ObjectGame obj in listobjmap) { obj.index = ind; ind++; } rootNode.listObj = listobjmap; rootNode.BuildTree(); rootNode.Save(quadtree); quadtree.Close(); MessageBox.Show("Saved"); }