Exemple #1
0
        private void split()
        {
            int divWidth  = _bounds.Width / 2;
            int divHeight = _bounds.Height / 2;

            _nodes[0] = new Quadtree(_level + 1, new Rectangle(_bounds.X + divWidth, _bounds.Y, divWidth, divHeight));
            _nodes[1] = new Quadtree(_level + 1, new Rectangle(_bounds.X, _bounds.Y, divWidth, divHeight));
            _nodes[2] = new Quadtree(_level + 1, new Rectangle(_bounds.X, _bounds.Y + divHeight, divWidth, divHeight));
            _nodes[3] = new Quadtree(_level + 1, new Rectangle(_bounds.X + divWidth, _bounds.Y + divHeight, divWidth, divHeight));
        }
Exemple #2
0
        /// <summary>
        /// Checks for collisions with nearby objects and returns list of collided objects.
        /// </summary>
        /// <param name="collidables">A Quadtree off all collidable objects.</param>
        public List <ICollidable> GetCollisions(Quadtree quad)
        {
            List <ICollidable> collidables     = quad.SameNodeAs(this);
            List <ICollidable> collidedObjects = new List <ICollidable>();

            foreach (ICollidable obstacle in collidables)
            {
                if (obstacle != null && obstacle.Footprint.Intersects(this.Footprint))
                {
                    collidedObjects.Add(obstacle);
                }
            }

            return(collidedObjects);
        }
Exemple #3
0
        public int CheckCollisions(Quadtree quad)
        {
            List <ICollidable> collidedObjects = GetCollisions(quad);

            return(HandleCollisions(collidedObjects));
        }