main.py
def brick_collisions(self):
        """
        This function identifies bricks that the ball has collided with and determines the
        side the ball impacted first. Based on the side first impacted, the ball's direction
        is updated.
        """
        # get list of collisions between ball and bricks
        brick_collisions = arcade.check_for_collision_with_list(self.ball_sprite, self.brick_list)
        
        # variables to track whether ball should change its x,y direction based on a collision
        change_y = False
        change_x = False

        # determine what direction ball should rebound from brick collisions.
        # there are 12 ways the ball could impact the brick, which are accounted for in this if statement
        for brick in brick_collisions:
            # if contacting the brick from top left
            if self.ball_sprite.center_y > brick.top and self.ball_sprite.center_x < brick.left:
                # if ball impacted top of brick before the left side (center of ball is further from top 
                # than the side), reverse y-speed
                if abs(self.ball_sprite.center_y - brick.top) >= abs(self.ball_sprite.center_x - brick.left):
                    change_y = True
                # if ball impacted the left side before the top, reverse x-speed
                else:
                    change_x = True
            # if colliding from top right side
            elif self.ball_sprite.center_y > brick.top and self.ball_sprite.center_x > brick.right:
                # if ball impacted top of brick before the right side, reverse y-speed
                if abs(self.ball_sprite.center_y - brick.top) >= abs(self.ball_sprite.center_x - brick.right):
                    change_y = True
                # if ball impacted the left side before the top, reverse x-speed
                else:
                    change_x = True
            # if contacting the brick from bottom left
            elif self.ball_sprite.center_y < brick.bottom and self.ball_sprite.center_x < brick.left:
                # if ball impacted bottom of brick before the left side (center of ball is further from bottom 
                # than the side), reverse y-speed
                if abs(self.ball_sprite.center_y - brick.bottom) >= abs(self.ball_sprite.center_x - brick.left):
                    change_y = True
                # if ball impacted the left side before the bottom, reverse x-speed
                else:
                    change_x = True
            # if colliding from bottom right side
            elif self.ball_sprite.center_y < brick.bottom and self.ball_sprite.center_x > brick.right:
                # if ball impacted bottom of brick before the right side, reverse y-speed
                if abs(self.ball_sprite.center_y - brick.bottom) >= abs(self.ball_sprite.center_x - brick.right):
                    change_y = True
                # if ball impacted the right side before the bottom, reverse x-speed
                else:
                    change_x = True
            # if colliding with top or bottom in-between the sides, reverse y-speed
            elif self.ball_sprite.center_y > brick.top or self.ball_sprite.center_y < brick.bottom:
                change_y = True
            # if contacting the brick from the left or right, reverse x-speed
            else:
                change_x = True

            # remove all bricks the ball collided with
            brick.remove_from_sprite_lists()

            # gain points for each brick removed
            self.score += BRICK_SCORE

        # change the ball's direction based on the collisions
        if change_y:
            self.ball_sprite.change_y *= -1
        if change_x:
            self.ball_sprite.change_x *= -1

        This function identifies bricks that the ball has collided with and determines the
        side the ball impacted first. Based on the side first impacted, the ball's direction
        is updated.
        
This function identifies bricks that the ball has collided with and determines the
side the ball impacted first. Based on the side first impacted, the ball's direction
is updated.
This function identifies bricks that the ball has collided with and determines the side the ball impacted first . Based on the side first impacted the ball ' s direction is updated .
def brick_collisions(self):
        brick_collisions = arcade.check_for_collision_with_list(self.ball_sprite, self.brick_list)
        change_y = False
        change_x = False
        for brick in brick_collisions:
            if self.ball_sprite.center_y > brick.top and self.ball_sprite.center_x < brick.left:
                if abs(self.ball_sprite.center_y - brick.top) >= abs(self.ball_sprite.center_x - brick.left):
                    change_y = True
                else:
                    change_x = True
            elif self.ball_sprite.center_y > brick.top and self.ball_sprite.center_x > brick.right:
                if abs(self.ball_sprite.center_y - brick.top) >= abs(self.ball_sprite.center_x - brick.right):
                    change_y = True
                else:
                    change_x = True
            elif self.ball_sprite.center_y < brick.bottom and self.ball_sprite.center_x < brick.left:
                if abs(self.ball_sprite.center_y - brick.bottom) >= abs(self.ball_sprite.center_x - brick.left):
                    change_y = True
                else:
                    change_x = True
            elif self.ball_sprite.center_y < brick.bottom and self.ball_sprite.center_x > brick.right:
                if abs(self.ball_sprite.center_y - brick.bottom) >= abs(self.ball_sprite.center_x - brick.right):
                    change_y = True
                else:
                    change_x = True
            elif self.ball_sprite.center_y > brick.top or self.ball_sprite.center_y < brick.bottom:
                change_y = True
            else:
                change_x = True
            brick.remove_from_sprite_lists()
            self.score += BRICK_SCORE
        if change_y:
            self.ball_sprite.change_y *= -1
        if change_x:
            self.ball_sprite.change_x *= -1
def brick_collisions ( self ) : brick_collisions = arcade . check_for_collision_with_list ( self . ball_sprite , self . brick_list ) change_y = False change_x = False for brick in brick_collisions : if self . ball_sprite . center_y > brick . top and self . ball_sprite . center_x < brick . left : if abs ( self . ball_sprite . center_y - brick . top ) >= abs ( self . ball_sprite . center_x - brick . left ) : change_y = True else : change_x = True elif self . ball_sprite . center_y > brick . top and self . ball_sprite . center_x > brick . right : if abs ( self . ball_sprite . center_y - brick . top ) >= abs ( self . ball_sprite . center_x - brick . right ) : change_y = True else : change_x = True elif self . ball_sprite . center_y < brick . bottom and self . ball_sprite . center_x < brick . left : if abs ( self . ball_sprite . center_y - brick . bottom ) >= abs ( self . ball_sprite . center_x - brick . left ) : change_y = True else : change_x = True elif self . ball_sprite . center_y < brick . bottom and self . ball_sprite . center_x > brick . right : if abs ( self . ball_sprite . center_y - brick . bottom ) >= abs ( self . ball_sprite . center_x - brick . right ) : change_y = True else : change_x = True elif self . ball_sprite . center_y > brick . top or self . ball_sprite . center_y < brick . bottom : change_y = True else : change_x = True brick . remove_from_sprite_lists ( ) self . score += BRICK_SCORE if change_y : self . ball_sprite . change_y *= - 1 if change_x : self . ball_sprite . change_x *= - 1
This function identifies bricks that the ball has collided with and determines the
side the ball impacted first.
This function identifies bricks that the ball has collided with and determines the side the ball impacted first .
"""
        This function identifies bricks that the ball has collided with and determines the
        side the ball impacted first. Based on the side first impacted, the ball's direction
        is updated.
        """ # get list of collisions between ball and bricks # variables to track whether ball should change its x,y direction based on a collision # determine what direction ball should rebound from brick collisions. # there are 12 ways the ball could impact the brick, which are accounted for in this if statement # if contacting the brick from top left # if ball impacted top of brick before the left side (center of ball is further from top  # than the side), reverse y-speed # if ball impacted the left side before the top, reverse x-speed # if colliding from top right side # if ball impacted top of brick before the right side, reverse y-speed # if ball impacted the left side before the top, reverse x-speed # if contacting the brick from bottom left # if ball impacted bottom of brick before the left side (center of ball is further from bottom  # than the side), reverse y-speed # if ball impacted the left side before the bottom, reverse x-speed # if colliding from bottom right side # if ball impacted bottom of brick before the right side, reverse y-speed # if ball impacted the right side before the bottom, reverse x-speed # if colliding with top or bottom in-between the sides, reverse y-speed # if contacting the brick from the left or right, reverse x-speed # remove all bricks the ball collided with # gain points for each brick removed # change the ball's direction based on the collisions
self