protected MoveResponse ResolveAllCollisions(ICollisionComponent source)
        {
            MoveResponse response = new MoveResponse();

            //As long as at least one collision occurred attempt to resolve it.
            //And, of course, only resolve collisions if we're supposed to!
            if (higherPriorityCollisionList.Count > 0)
            {
                correctionVectors.Clear();

                for (int i = 0; i < tempCollisionList.Count; i++)
                {
                    var vector = GetCorrectionVector(source, tempCollisionList[i]);
                    correctionVectors.Add(vector);

                    //Notify of a collision
                    NotifyCollision(source, tempCollisionList[i], vector);
                }

                //Now determine the direction for the X and Y axis.
                CorrectionVector2 directions = GetDirections(correctionVectors);

                //Correct the movement of this object if we're supposed to
                if (ResolveCollisions)
                {
                    CorrectMovement(source, tempCollisionList, directions);

                    //Mark this object as having moved and put it back into the QuadTree.
                    response.moved = true;
                }
            }

            return(response);
        }
        /// <summary>
        /// Requests that the CollidableGameObject be moved to the location where its ProjectedBoundingBox currently resides.
        /// </summary>
        /// <param name="objectToMove">The IGameObject to be moved.</param>
        /// <returns>A MoveResponse object providing information related to the movement.</returns>
        protected MoveResponse RequestMove(ICollisionComponent objectToMove)
        {
            MoveResponse response = new MoveResponse(false);

            HandleObjectMovement(objectToMove);

            return(response);
        }
        /// <summary>
        /// Resolves all collisions against the source ICollidable object.
        /// </summary>
        /// <param name="source">The source ICollidable object that has moved and requires collision testing.</param>
        protected MoveResponse HandleObjectMovement(ICollisionComponent source)
        {
            tempCollisionList.Clear();
            higherPriorityCollisionList.Clear();
            lowerPriorityCollisionList.Clear();
            resolvedCollisions.Clear();

            finalCorrectionVector = new CorrectionVector2();

            MoveResponse response = new MoveResponse();

            collisionTree.GetCollidingWith(source, ref tempCollisionList);

            while (tempCollisionList.Count > 0)
            {
                if (source.Solid)
                {
                    for (int i = 0; i < tempCollisionList.Count; i++)
                    {
                        ICollisionComponent currObject = tempCollisionList[i];

                        //Check if the object we are colliding with has a priority greater than ours.
                        //If so, then add it to the list of collisions we need to resolve!
                        //We will also consider objects with the same priority so long as both of use are flagged as being able to collide with 
                        //objects of the same priority.
                        if (currObject.Solid)
                        {
                            if (currObject.CollisionPriority > source.CollisionPriority ||
                                (
                                 (currObject.CollisionPriority == source.CollisionPriority)))
                            {
                                higherPriorityCollisionList.Add(currObject);
                            }

                                //If we've collided with anything of lower priority then we need to push IT out of the way.
                            else if (currObject.CollisionPriority < source.CollisionPriority)
                            {
                                lowerPriorityCollisionList.Add(currObject);
                            }
                        }
                    }
                }

                //Now let's resolve those collisions!
                ResolveAllCollisions(source);

                //Resolve all of the individual collisions that we are pushing away.
                for (int j = 0; j < lowerPriorityCollisionList.Count; j++)
                {
                    ResolveIndividualCollision(source, lowerPriorityCollisionList[j]);
                }

                //Notify all the ICollisionComponents that they have collided with something.
                //for (int j = 0; j < tempCollisionList.Count; j++)
                //{
                   // if (collisionEvents.ContainsKey(source.Parent.GUID) && collisionEvents[source.Parent.GUID] != null)
                   //     collisionEvents[source.Parent.GUID](source, tempCollisionList[j], finalCorrectionVector);

                   // if (collisionEvents.ContainsKey(tempCollisionList[j].Parent.GUID) && collisionEvents[tempCollisionList[j].Parent.GUID] != null)
                   //     collisionEvents[tempCollisionList[j].Parent.GUID](tempCollisionList[j], source, finalCorrectionVector);
               // }

                tempCollisionList.Clear();
                higherPriorityCollisionList.Clear();
                lowerPriorityCollisionList.Clear();

                //Only check again if we're resolving collisions!
                if (ResolveCollisions)
                {
                    collisionTree.GetCollidingWith(source, ref tempCollisionList);
                }
            }

            return response;
        }
        protected MoveResponse ResolveAllCollisions(ICollisionComponent source)
        {
            MoveResponse response = new MoveResponse();

            //As long as at least one collision occurred attempt to resolve it.
            //And, of course, only resolve collisions if we're supposed to!
            if (higherPriorityCollisionList.Count > 0)
            {
                correctionVectors.Clear();
                
                for (int i = 0; i < tempCollisionList.Count; i++)
                {
                    var vector = GetCorrectionVector(source, tempCollisionList[i]);
                    correctionVectors.Add(vector);

                    //Notify of a collision
                    NotifyCollision(source, tempCollisionList[i], vector);
                }

                //Now determine the direction for the X and Y axis.
                CorrectionVector2 directions = GetDirections(correctionVectors);

                //Correct the movement of this object if we're supposed to
                if (ResolveCollisions)
                {
                    CorrectMovement(source, tempCollisionList, directions);

                    //Mark this object as having moved and put it back into the QuadTree.
                    response.moved = true;
                }
            }

            return response;
        }
        /// <summary>
        /// Requests that the CollidableGameObject be moved to the location where its ProjectedBoundingBox currently resides.
        /// </summary>
        /// <param name="objectToMove">The IGameObject to be moved.</param>
        /// <returns>A MoveResponse object providing information related to the movement.</returns>
        protected MoveResponse RequestMove(ICollisionComponent objectToMove)
        {
            MoveResponse response = new MoveResponse(false);            

            HandleObjectMovement(objectToMove);

            return response;
        }
        /// <summary>
        /// Resolves all collisions against the source ICollidable object.
        /// </summary>
        /// <param name="source">The source ICollidable object that has moved and requires collision testing.</param>
        protected MoveResponse HandleObjectMovement(ICollisionComponent source)
        {
            tempCollisionList.Clear();
            higherPriorityCollisionList.Clear();
            lowerPriorityCollisionList.Clear();
            resolvedCollisions.Clear();

            finalCorrectionVector = new CorrectionVector2();

            MoveResponse response = new MoveResponse();

            collisionTree.GetCollidingWith(source, ref tempCollisionList);

            while (tempCollisionList.Count > 0)
            {
                if (source.Solid)
                {
                    for (int i = 0; i < tempCollisionList.Count; i++)
                    {
                        ICollisionComponent currObject = tempCollisionList[i];

                        //Check if the object we are colliding with has a priority greater than ours.
                        //If so, then add it to the list of collisions we need to resolve!
                        //We will also consider objects with the same priority so long as both of use are flagged as being able to collide with
                        //objects of the same priority.
                        if (currObject.Solid)
                        {
                            if (currObject.CollisionPriority > source.CollisionPriority ||
                                (
                                    (currObject.CollisionPriority == source.CollisionPriority)))
                            {
                                higherPriorityCollisionList.Add(currObject);
                            }

                            //If we've collided with anything of lower priority then we need to push IT out of the way.
                            else if (currObject.CollisionPriority < source.CollisionPriority)
                            {
                                lowerPriorityCollisionList.Add(currObject);
                            }
                        }
                    }
                }

                //Now let's resolve those collisions!
                ResolveAllCollisions(source);

                //Resolve all of the individual collisions that we are pushing away.
                for (int j = 0; j < lowerPriorityCollisionList.Count; j++)
                {
                    ResolveIndividualCollision(source, lowerPriorityCollisionList[j]);
                }

                //Notify all the ICollisionComponents that they have collided with something.
                //for (int j = 0; j < tempCollisionList.Count; j++)
                //{
                // if (collisionEvents.ContainsKey(source.Parent.GUID) && collisionEvents[source.Parent.GUID] != null)
                //     collisionEvents[source.Parent.GUID](source, tempCollisionList[j], finalCorrectionVector);

                // if (collisionEvents.ContainsKey(tempCollisionList[j].Parent.GUID) && collisionEvents[tempCollisionList[j].Parent.GUID] != null)
                //     collisionEvents[tempCollisionList[j].Parent.GUID](tempCollisionList[j], source, finalCorrectionVector);
                // }

                tempCollisionList.Clear();
                higherPriorityCollisionList.Clear();
                lowerPriorityCollisionList.Clear();

                //Only check again if we're resolving collisions!
                if (ResolveCollisions)
                {
                    collisionTree.GetCollidingWith(source, ref tempCollisionList);
                }
            }

            return(response);
        }