samworld.py
def draw_sam(screen, idle_graphic, run_graphics, jump_graphic, fall_graphic, offset, position, velocity, landed, 
        tile_size):
    """draw the appopriate graphic of Sam to the screen surface at the given offset from the centre.
       screen is the screen surface
       idle_graphic is the graphic to use when sam is stationary
       run_graphics is a sequence of animation frames used when sam is running
       jump_graphic is used when sam is jumping upwards
       fall_graphic is used when sam is falling downwards
       offset is the x,y offset from the screen centre at which to draw sam, as a 2-item sequence
       position is the x,y position of the player in the level as a 2-item sequence
       velocity is the current x and y speed of the player as a 2-item sequence
       landed is a boolean indicating whether sam is on a platform or not
       tile_size is the size of each tile, as an integer"""
       
    # if sam is in mid-air and moving upwards, show jumping graphic
    if not landed and velocity[1] <= 0:
        graphic = jump_graphic
        
    # if sam is in mid-air and moving downwards, show falling graphic
    elif not landed and velocity[1] > 0:
        graphic = fall_graphic
        
    # if sam is on the ground and not moving left or right, show idle graphic
    elif velocity[0] == 0.0:
        graphic = idle_graphic
        
    # if sam is on the ground and moving left or right, show a running graphic. The graphic shown is based on sam's x
    # coordinate so that as she moves faster, the graphics animate faster.
    else:
        num = len(run_graphics)
        graphic = run_graphics[int(position[0]//((tile_size*4)/num)) % num]
        
    # if sam is moving left, flip the graphic so that she is facing left instead of right
    if velocity[0] < 0.0:
        graphic = pygame.transform.flip(graphic, True, False)
        
    # draw the selected graphic to the screen. It's always drawn to the same place on the screen, just below the centre.
    screen.blit(graphic, (screen.get_width()/2-graphic.get_width()/2+offset[0], 
                          screen.get_height()/2-graphic.get_height()/2+offset[1]))
draw the appopriate graphic of Sam to the screen surface at the given offset from the centre.
       screen is the screen surface
       idle_graphic is the graphic to use when sam is stationary
       run_graphics is a sequence of animation frames used when sam is running
       jump_graphic is used when sam is jumping upwards
       fall_graphic is used when sam is falling downwards
       offset is the x,y offset from the screen centre at which to draw sam, as a 2-item sequence
       position is the x,y position of the player in the level as a 2-item sequence
       velocity is the current x and y speed of the player as a 2-item sequence
       landed is a boolean indicating whether sam is on a platform or not
       tile_size is the size of each tile, as an integer
draw the appopriate graphic of Sam to the screen surface at the given offset from the centre.
screen is the screen surface
idle_graphic is the graphic to use when sam is stationary
run_graphics is a sequence of animation frames used when sam is running
jump_graphic is used when sam is jumping upwards
fall_graphic is used when sam is falling downwards
offset is the x,y offset from the screen centre at which to draw sam, as a 2-item sequence
position is the x,y position of the player in the level as a 2-item sequence
velocity is the current x and y speed of the player as a 2-item sequence
landed is a boolean indicating whether sam is on a platform or not
tile_size is the size of each tile, as an integer
draw the appopriate graphic of Sam to the screen surface at the given offset from the centre . screen is the screen surface idle_graphic is the graphic to use when sam is stationary run_graphics is a sequence of animation frames used when sam is running jump_graphic is used when sam is jumping upwards fall_graphic is used when sam is falling downwards offset is the x y offset from the screen centre at which to draw sam as a 2 - item sequence position is the x y position of the player in the level as a 2 - item sequence velocity is the current x and y speed of the player as a 2 - item sequence landed is a boolean indicating whether sam is on a platform or not tile_size is the size of each tile as an integer
def draw_sam(screen, idle_graphic, run_graphics, jump_graphic, fall_graphic, offset, position, velocity, landed, 
        tile_size):
    if not landed and velocity[1] <= 0:
        graphic = jump_graphic
    elif not landed and velocity[1] > 0:
        graphic = fall_graphic
    elif velocity[0] == 0.0:
        graphic = idle_graphic
    else:
        num = len(run_graphics)
        graphic = run_graphics[int(position[0]//((tile_size*4)/num)) % num]
    if velocity[0] < 0.0:
        graphic = pygame.transform.flip(graphic, True, False)
    screen.blit(graphic, (screen.get_width()/2-graphic.get_width()/2+offset[0], 
                          screen.get_height()/2-graphic.get_height()/2+offset[1]))
def draw_sam ( screen , idle_graphic , run_graphics , jump_graphic , fall_graphic , offset , position , velocity , landed , tile_size ) : if not landed and velocity [ 1 ] <= 0 : graphic = jump_graphic elif not landed and velocity [ 1 ] > 0 : graphic = fall_graphic elif velocity [ 0 ] == 0.0 : graphic = idle_graphic else : num = len ( run_graphics ) graphic = run_graphics [ int ( position [ 0 ] // ( ( tile_size * 4 ) / num ) ) % num ] if velocity [ 0 ] < 0.0 : graphic = pygame . transform . flip ( graphic , True , False ) screen . blit ( graphic , ( screen . get_width ( ) / 2 - graphic . get_width ( ) / 2 + offset [ 0 ] , screen . get_height ( ) / 2 - graphic . get_height ( ) / 2 + offset [ 1 ] ) )
draw the appopriate graphic of Sam to the screen surface at the given offset from the centre.
draw the appopriate graphic of Sam to the screen surface at the given offset from the centre .
"""draw the appopriate graphic of Sam to the screen surface at the given offset from the centre.
       screen is the screen surface
       idle_graphic is the graphic to use when sam is stationary
       run_graphics is a sequence of animation frames used when sam is running
       jump_graphic is used when sam is jumping upwards
       fall_graphic is used when sam is falling downwards
       offset is the x,y offset from the screen centre at which to draw sam, as a 2-item sequence
       position is the x,y position of the player in the level as a 2-item sequence
       velocity is the current x and y speed of the player as a 2-item sequence
       landed is a boolean indicating whether sam is on a platform or not
       tile_size is the size of each tile, as an integer""" # if sam is in mid-air and moving upwards, show jumping graphic # if sam is in mid-air and moving downwards, show falling graphic # if sam is on the ground and not moving left or right, show idle graphic # if sam is on the ground and moving left or right, show a running graphic. The graphic shown is based on sam's x # coordinate so that as she moves faster, the graphics animate faster. # if sam is moving left, flip the graphic so that she is facing left instead of right # draw the selected graphic to the screen. It's always drawn to the same place on the screen, just below the centre.
screen
idle_graphic
run_graphics
jump_graphic
fall_graphic
offset
position
velocity
landed
tile_size