Ejemplo n.º 1
0
    def test_pygame2_base_Rect_collidelist(self):

        # __doc__ (as of 2008-10-17) for pygame2.base.Rect.collidelist:

        # Rect.collidelist (list) -> index
        # 
        # Test if one rectangle in a list intersects.
        # 
        # Test whether the rectangle collides with any in a sequence of
        # rectangles. The index of the first collision found is
        # returned. If no collisions are found an index of -1 is
        # returned.

        r = Rect(1, 1, 10, 10)
        l = [Rect(50, 50, 1, 1), Rect(5, 5, 10, 10), Rect(15, 15, 1, 1)]

        self.assertEqual(r.collidelist(l), 1)
        self.assertEqual(r.collidelist(l, lambda x, y: x.top < y.top), 0)

        f = [Rect(50, 50, 1, 1), Rect(100, 100, 4, 4)]
        self.assertEqual(r.collidelist(f), -1)
        self.assertEqual(r.collidelist(l, lambda x, y: x.top > y.top), -1)