Пример #1
0
        public void CreateSubNode()
        {
            int halfWidth  = rec.Width / 2;
            int halfHeight = rec.Height / 2;

            if (halfWidth < 136 || listObj.Count == 0)
            {
                LeftBot  = null;
                LeftTop  = null;
                RightBot = null;
                RightTop = null;
                return;
            }
            LeftTop  = new QuadNode(this.id + "0", new Rectangle(rec.Location, new Size(halfWidth, halfHeight)));
            RightTop = new QuadNode(this.id + "1", new Rectangle(new Point(rec.Left + halfWidth, rec.Top), new Size(halfWidth, halfHeight)));
            LeftBot  = new QuadNode(this.id + "2", new Rectangle(new Point(rec.Left, rec.Top + halfHeight), new Size(halfWidth, halfHeight)));
            RightBot = new QuadNode(this.id + "3", new Rectangle(new Point(rec.Left + halfWidth, rec.Top + halfHeight), new Size(halfWidth, halfHeight)));
        }
Пример #2
0
        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");
        }