Beispiel #1
0
        public static VectorRectangle CalculateIntersect(VectorRectangle first, VectorRectangle second)
        {
            VectorRectangle intersect = new VectorRectangle();

            if (first.Intersects(second))
            {
                float intersectLeft = Math.Max(first.Left, second.Left);
                float intersectRight = Math.Min(first.Right, second.Right);
                float intersectTop = Math.Max(first.Top, second.Top);
                float intersectBottom = Math.Min(first.Bottom, second.Bottom);

                intersect.Position = new Vector2(intersectLeft, intersectTop);
                intersect.Size = new Vector2(intersectRight - intersectLeft, intersectBottom - intersectTop);
            }

            return intersect;
        }
        public List<PhysicalObject2D> CalculateCollisions(VectorRectangle firstRectangle)
        {
            List<PhysicalObject2D> collisions = new List<PhysicalObject2D>();

            foreach (CollisionRectangle secondRectangle in _allRectangles)
            {
                if (!secondRectangle.Object.IsMovable() && firstRectangle.Intersects(secondRectangle))
                {
                    if (secondRectangle.Children != null)
                        collisions.AddRange(secondRectangle.Children.CalculateCollisions(firstRectangle));
                    else if (secondRectangle.Object != null)
                        collisions.Add(secondRectangle.Object);

                    // TODO checking sprite make use of CollisionDictionary
                }
            }

            return collisions;
        }