Exemplo n.º 1
0
 private void drawQuadTree(Graphics g, QuadTree quadTree)
 {
 }
Exemplo n.º 2
0
        private void btnLoadMap_Click(object sender, EventArgs e)
        {
            try
            {

                OpenFileDialog f = new OpenFileDialog();
                f.Filter = "txt(*.txt) | *.txt";

                if (f.ShowDialog() == DialogResult.OK)
                {
                    using (XmlReader reader = XmlReader.Create(f.FileName.ToString()))
                    {
                        while (reader.Read())
                        {
                            // Only detect start elements.
                            if (reader.IsStartElement())
                            {
                                // Get element name and switch on it.
                                switch (reader.Name)
                                {
                                    case "map":
                                        // Detect this element.
                                        string attribute1 = reader["w"];
                                        if (attribute1 != null)
                                        {
                                            _mapWidth = int.Parse(attribute1);
                                        }

                                        string attribute3 = reader["h"];
                                        if (attribute1 != null)
                                        {
                                            _mapHeight = int.Parse(attribute3);
                                        }

                                        string attribute2 = reader["s"];

                                        if (attribute2 != null)
                                        {
                                            _mapSize = int.Parse(attribute2);
                                        }
                                        break;
                                    case "tile":
                                        string attribute = reader["t"];
                                        if (attribute != null)
                                        {
                                            _listTileMap.Add(int.Parse(attribute));
                                            _set.Add(int.Parse(attribute));
                                        }
                                        break;
                                }
                            }
                        }
                    }  //end using

                    _listUniqueTile = _set.ToList();

                    //load map
                    for (int j = 0; j <= _mapSize; j++)
                    {

                        for (int i = 0; i < _listTileMap.Count(); i++)
                        {
                            int x = ((i % _mapWidth) * _tileSize) + (_mapWidth * _tileSize) * j;
                            int y = (i / _mapWidth) * _tileSize;
                            int index = _listUniqueTile.FindIndex(u => u == _listTileMap.ElementAt(i));

                            Rectangle r = new Rectangle { X = index * _tileSize, Y = 0, Width = _tileSize, Height = _tileSize };
                            Bitmap clone = _tileSet.Clone(r, _tileSet.PixelFormat);
                            _listTile4Drawing.Add(new Tile { _x = x, _y = y, _texture = clone });

                        }
                    }

                    Image bg = makeMapBackground(_listTile4Drawing);
                    pictureBox1.Image = bg;

                    //save grid object
                    int nGridColumn = bg.Width / _gridSize;
                    int nGridRow = bg.Height / _gridSize;
                    int count = 1;

                    for (int i = 1; i <= nGridRow; i++)
                    {
                        for (int j = 1; j <= nGridColumn; j++)
                        {
                            int x = (j - 1) * _gridSize;
                            int y = (i - 1) * _gridSize;
                            System.Drawing.Rectangle r = new System.Drawing.Rectangle(x, y, _gridSize, _gridSize);
                            _listGridObject.Add(new NodeObject { _boxObject = r, _objectID = count });
                            count++;
                        }
                    }

                    //show map info
                    lbMap.Text = "Map: " + bg.Width.ToString() + " x " + bg.Height.ToString();

                    //quadtree grid
                    _quadTree4Grid = new QuadTree(0, 0, bg.Width, bg.Height, _listGridObject, _gridSize);

                } //end if

            }
            catch (Exception)
            {
                MessageBox.Show("Invalid map file", "Error", MessageBoxButtons.OK);
                return;
            }
        }
Exemplo n.º 3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //Create quadtree
            Tree = new QuadTree();

            LoadResources();
            LoadTypeObject();
            listContents = new List<ObjectGame>();
            nameObjects = new List<string>();
            controlSelected = pnObjects.Controls.OfType<RadioButton>().FirstOrDefault(r => r.Checked);
            //id = ObjectGame.GetIdFromText(controlSelected.Text.ToString());
            AddpnObjectsControlsClick();
            btCreate.PerformClick();
            ///---------
            foreach (Control c in pnObjects.Controls)
            {
                if (c is RadioButton)
                {
                    if (c.Enabled)
                    {
                        c.Click += pnObjects_Controls_Click;
                        nameObjects.Add(c.AccessibleName);
                    }
                }

            }
        }
Exemplo n.º 4
0
        private void saveQuadtreeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _allGameObject = new List<NodeObject>();

            foreach (GameObject item in _listGameObject)
            {
                _allGameObject.Add(new NodeObject
                {
                    _objectID = item._id,
                    _boxObject = new Rectangle(item._x, item._y, item._width, item._height)
                });
            }

            foreach (EnemyObject item in _listEnemyObject)
            {
                int x, y, width, height;

                width = item._width + item._patrolAreaWidth;
                height = item._height + item._patrolAreaHeight;

                if (item._direction == EnemyObject.Direction.Left)
                {
                    if (item._patrolAreaWidth != 0 && item._patrolAreaHeight == 0)
                    {
                        x = item._x - item._patrolAreaWidth;
                        y = item._y;
                    }
                    else if (item._patrolAreaWidth == 0 && item._patrolAreaHeight != 0)
                    {
                        x = item._x;
                        y = item._y - item._patrolAreaHeight;
                    }
                    else
                    {
                        x = item._x;
                        y = item._y;
                    }

                }
                else
                {
                    if (item._patrolAreaWidth == 0 && item._patrolAreaHeight != 0)
                    {
                        x = item._x;
                        y = item._y - item._patrolAreaHeight;
                    }
                    else
                    {
                        x = item._x;
                        y = item._y;
                    }
                }

                _allGameObject.Add(new NodeObject
                {
                    _objectID = item._id,
                    _boxObject = new Rectangle(x, y, width, height)
                });
            }

            //create with maximum object per node
            QuadTree quadTree = new QuadTree(0, 0, pictureBox1.Width, pictureBox1.Height, _allGameObject,400);
            //QuadTree quadTree = new QuadTree(0, 0, pictureBox1.Width, pictureBox1.Height, _allGameObject);

            SaveFileDialog s = new SaveFileDialog();
            s.Filter = "txt(*.txt) | *.txt";

            if (s.ShowDialog() == DialogResult.OK)
            {
                quadTree.saveQuadTree(s.FileName);
            }
        }
Exemplo n.º 5
0
 private void btCAll_Click(object sender, EventArgs e)
 {
     f = null;
     Tree = null;
     Tree = new QuadTree();
     listContents.Clear();
     pbGridMap.Invalidate();
     btCreate.PerformClick();
 }