Ejemplo n.º 1
0
    def _platform_additional_check(self, platform: Platform):
        """
        The additional checking for the condition that the ball passes the corner of the platform
        """
        if self.rect.bottom > platform.rect.top:
            routine_a = (Vector2(self._last_pos.bottomleft), Vector2(self.rect.bottomleft))
            routine_b = (Vector2(self._last_pos.bottomright), Vector2(self.rect.bottomright))

            return (physics.rect_collideline(platform.rect, routine_a) or
                    physics.rect_collideline(platform.rect, routine_b))

        return False
Ejemplo n.º 2
0
    def _ball_routine_hit_platform(self, target_platform: Platform, \
        routine_for_left, routine_for_right) -> bool:
        """
        Check if the ball routine hits the platform

        @param target_platform Specify the target platform
        @param routine_for_left A tuple (Vector2, Vector2) presenting the checking routine
               for the condition that the ball is at the left side of the platform
        @param routine_for_right Similar to `routine_for_left` but
               for the condition that the ball is at the right side of the platform
        """
        return (self.rect.right < target_platform.rect.left and \
                physics.rect_collideline(target_platform.rect, routine_for_left)) or \
               (self.rect.left > target_platform.rect.right and \
                physics.rect_collideline(target_platform.rect, routine_for_right))
Ejemplo n.º 3
0
    def _ball_routine_hit_rect(self, rect: pygame.Rect, routines) -> bool:
        """
        Check if the ball hits the `rect`
        by checking if any of ball routine collide with the `rect`.
        """
        rect_expand = rect.inflate(1, 1)
        for routine in routines:
            # Exclude the case of the ball goes from the surface
            if not rect_expand.collidepoint(routine[0]) and \
               physics.rect_collideline(rect, routine):
                return True

        return False