Пример #1
0
        public void Initialize(Size gameAreaSize)
        {
            _gameAreaRectangle = new Rectangle(new Point(0, 0), gameAreaSize);
            _quadTree = new QuadTree<GameObject>(new Size(1, 1), _gameAreaRectangle);
            GameObject.QuadTree = _quadTree;

            Size test = _gameAreaRectangle.Size;
            _gameAreaSize = gameAreaSize;

            CharacterGroup b1 = new CharacterGroup();
            CharacterGroup b2 = new CharacterGroup();

            int count1 = 3;

            for (int i = 0; i < count1; i++)
            {
                Character c1 = ObjectFactory.GetKnight(0, BehaviorType.NoAI);
                c1.ID = i;
                c1.Initialize(b1, b2);
                //c1.Location = new Point(100, 100);
                c1.Location = new Point((_gameAreaSize.Width / (count1 + 1)) * (i + 1),  c1.Size.Height * 2 + 100);
                //c1.SetBehavior(BehaviorType.NoAI);
                objects.Add(c1);
                _quadTree.Insert(c1);
            }

            int count = 10 ;

            for (int i = 0; i < count; i++)
            {
                Character c2 = ObjectFactory.GetPeasant(1, BehaviorType.SmartAttack);
                c2.Initialize(b2, b1);
                //c2.Location = new Point(200,100);
                c2.Location = new Point(1000 + (i + 1) * ((_gameAreaSize.Width - 1000) / (count +1)), _gameAreaSize.Height - c2.Size.Height * 2);
                objects.Add(c2);
                //c2.SetBehavior(BehaviorType.SmartAttack);
                _quadTree.Insert(c2);
            }

            GameObject house = ObjectFactory.House();
            house.Location = new Point(400, _gameAreaSize.Height - 400);
            _quadTree.Insert(house);

            GameObject f1 = ObjectFactory.FenceHorizontal();
            f1.Location = new Point(400, _gameAreaSize.Height - 700);
            _quadTree.Insert(f1);

            GameObject f2 = ObjectFactory.FenceVertical();
            f2.Location = new Point(800, _gameAreaSize.Height - 400);
            _quadTree.Insert(f2);

            init(b1, b2);
        }
Пример #2
0
        private void Subdivide()
        {
            var x = Bounds.X;
              var y = Bounds.Y;
              var subWidth = Bounds.Width / 2;
              var subHeight = Bounds.Height / 2;

              Nodes[0] = new QuadTree(Level + 1, new Rect(x + subWidth, y, subWidth, subHeight));
              Nodes[1] = new QuadTree(Level + 1, new Rect(x, y, subWidth, subHeight));
              Nodes[2] = new QuadTree(Level + 1, new Rect(x, y + subHeight, subWidth, subHeight));
              Nodes[3] = new QuadTree(Level + 1, new Rect(x + subWidth, y + subHeight, subWidth, subHeight));
        }