Example #1
0
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    keys = pygame.key.get_pressed()
    if keys[pygame.K_a]:
        if user.x > screen_width // 2 + 3:
            user.move_left(user.speed)
        elif bg.x + user.speed < 0:
            bg.x += user.speed
        elif not bg.x + user.speed < 0 and user.x - user.speed > 0:
            user.move_left(user.speed)
        user.left = True
        user.right = False
        user.up = False
        user.down = False
        user.standing = False

    elif keys[pygame.K_d]:
        if user.x < screen_width // 2 - 3:
            user.move_right(user.speed)
        elif bg.x - user.speed > screen_width - bg.width:
            bg.x -= user.speed
        elif not bg.x - user.speed > screen_width - bg.width and user.x + user.width + user.speed < screen_width:
            user.move_right(user.speed)
        user.left = True
        user.right = False
        user.up = False
        user.down = False
        user.standing = False