samworld.py
def draw_background(screen, background, position, level_size, tile_size):
    """draws the given background graphic to to the screen surface. The background is scrolled according to the player's
       screen is the screen surface to draw onto
       background is the background surface to draw
       position in the level to give a parallax effect as they move around.
       position is a 2-item sequence representing x and y coordinate of the player
       level_size is a 2-item sequence representing tile number of columns and rows in the level
       tile_size is the size of each tile as an int"""
       
    # establish range of coordinates that the top left of the screen can be at within the background image
    min_x = 0.0
    max_x = background.get_width()-screen.get_width()
    min_y = 0.0
    max_y = background.get_height()-screen.get_height()
    
    # calculate how far across the level the player is, horizontally and vertically, each as a value from 0 to 1
    x_amount = position[0] / (level_size[0]*tile_size)
    y_amount = position[1] / (level_size[1]*tile_size)
    
    # apply these amounts to the coordinate ranges to get the top left corner of the section of background graphic to
    # use
    source_x = int(min_x + (max_x-min_x) * x_amount)
    source_y = int(min_y + (max_y-min_y) * y_amount)
    
    # take a screen-sized section of the background graphic, starting at the calculated position, and draw it onto the
    # screen surface
    screen.blit(background, (0,0), (source_x, source_y, screen.get_width(), screen.get_height()))
draws the given background graphic to to the screen surface. The background is scrolled according to the player's
       screen is the screen surface to draw onto
       background is the background surface to draw
       position in the level to give a parallax effect as they move around.
       position is a 2-item sequence representing x and y coordinate of the player
       level_size is a 2-item sequence representing tile number of columns and rows in the level
       tile_size is the size of each tile as an int
draws the given background graphic to to the screen surface. The background is scrolled according to the player's
screen is the screen surface to draw onto
background is the background surface to draw
position in the level to give a parallax effect as they move around.
position is a 2-item sequence representing x and y coordinate of the player
level_size is a 2-item sequence representing tile number of columns and rows in the level
tile_size is the size of each tile as an int
draws the given background graphic to to the screen surface . The background is scrolled according to the player ' s screen is the screen surface to draw onto background is the background surface to draw position in the level to give a parallax effect as they move around . position is a 2 - item sequence representing x and y coordinate of the player level_size is a 2 - item sequence representing tile number of columns and rows in the level tile_size is the size of each tile as an int
def draw_background(screen, background, position, level_size, tile_size):
    min_x = 0.0
    max_x = background.get_width()-screen.get_width()
    min_y = 0.0
    max_y = background.get_height()-screen.get_height()
    x_amount = position[0] / (level_size[0]*tile_size)
    y_amount = position[1] / (level_size[1]*tile_size)
    source_x = int(min_x + (max_x-min_x) * x_amount)
    source_y = int(min_y + (max_y-min_y) * y_amount)
    screen.blit(background, (0,0), (source_x, source_y, screen.get_width(), screen.get_height()))
def draw_background ( screen , background , position , level_size , tile_size ) : min_x = 0.0 max_x = background . get_width ( ) - screen . get_width ( ) min_y = 0.0 max_y = background . get_height ( ) - screen . get_height ( ) x_amount = position [ 0 ] / ( level_size [ 0 ] * tile_size ) y_amount = position [ 1 ] / ( level_size [ 1 ] * tile_size ) source_x = int ( min_x + ( max_x - min_x ) * x_amount ) source_y = int ( min_y + ( max_y - min_y ) * y_amount ) screen . blit ( background , ( 0 , 0 ) , ( source_x , source_y , screen . get_width ( ) , screen . get_height ( ) ) )
draws the given background graphic to to the screen surface.
draws the given background graphic to to the screen surface .
"""draws the given background graphic to to the screen surface. The background is scrolled according to the player's
       screen is the screen surface to draw onto
       background is the background surface to draw
       position in the level to give a parallax effect as they move around.
       position is a 2-item sequence representing x and y coordinate of the player
       level_size is a 2-item sequence representing tile number of columns and rows in the level
       tile_size is the size of each tile as an int""" # establish range of coordinates that the top left of the screen can be at within the background image # calculate how far across the level the player is, horizontally and vertically, each as a value from 0 to 1 # apply these amounts to the coordinate ranges to get the top left corner of the section of background graphic to # use # take a screen-sized section of the background graphic, starting at the calculated position, and draw it onto the # screen surface
screen
background
position
level_size
tile_size