run = True
while run:
    for event in pygame.event.get():  # Loop through a list of events
        if event.type == pygame.QUIT:  # See if the user clicks the red x 
            run = False    # End the loop
            pygame.quit()  # Quit the game
            quit()


run = True
speed = 30  # NEW

while run:
    clock.tick(speed)  # NEW
    bgX -= 1.4  # Move both background images back
    bgX2 -= 1.4

    if bgX < bg.get_width() * -1:  # If our bg is at the -width then reset its position
        bgX = bg.get_width()
    
    if bgX2 < bg.get_width() * -1:
        bgX2 = bg.get_width()

    for event in pygame.event.get():  
        if event.type == pygame.QUIT: 
            run = False    
            pygame.quit() 
            quit()

def redrawWindow():
    win.blit(bg, (bgX, 0))  # draws our first bg image
    win.blit(bg, (bgX2, 0))  # draws the seconf bg image
    pygame.display.update()  # updates the screen

# Call this from the game loop!




pygame.time.set_timer(USEREVENT+1, 500) # Sets the timer for 0.5 seconds
# This should go above the game loop



while run:
    redrawWindow() 
    bgX -= 1.4  
    bgX2 -= 1.4

    if bgX < bg.get_width() * -1:  
        bgX = bg.get_width()
    
    if bgX2 < bg.get_width() * -1:
        bgX2 = bg.get_width()

    for event in pygame.event.get():  
        if event.type == pygame.QUIT: 
            run = False    
            pygame.quit() 
            quit()
    
        if event.type == USEREVENT+1: # Checks if timer goes off
            speed += 1 # Increases speed

    clock.tick(speed) 


runner = player(200, 313, 64, 64)
# This should go above our game loop


def redrawWindow():
    win.blit(bg, (bgX, 0))  
    win.blit(bg, (bgX2, 0))
    runner.draw(win) # NEW
    pygame.display.update() 



# Should go inside the game loop
keys = pygame.key.get_pressed()

if keys[pygame.K_SPACE] or keys[pygame.K_UP]: # If user hits space or up arrow key
    if not(runner.jumping):  # If we are not already jumping
        runner.jumping = True

if keys[pygame.K_DOWN]:  # If user hits down arrow key
    if not(runner.sliding):  # If we are not already sliding
        runner.sliding = True

# Because we have a starter file this is all we have to do to move our character. 
# The physics and math behind the movement has been coded for you.