import pygame
import random

pygame.init()

# DISPLAY
length = 1280
width = 720
screen = pygame.display.set_mode((1280, 720))
pygame.display.set_caption('Elli Run')

# COLORS
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)

# GAME VARIABLES
clock = pygame.time.Clock()
FPS = 60
font = pygame.font.SysFont(None, 48)
floor_y = 500
score = 0
obstacle_speed = 5
start = False

# BACKGROUND
background_image = pygame.image.load("background.png")
background_image = pygame.transform.scale(background_image, (length, width))
background_rect = background_image.get_rect()
background_x = (length - background_rect.width) // 2
background_y = (width - background_rect.height) // 2


# DEFINE DRAW
def draw_text(text, color, x, y):
    screen.blit(font.render(text, True, color), (x, y))


# PLAYER CLASS
class Player(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.image.load("player.png")
        self.image = pygame.transform.scale(self.image, (50, 50))
        self.rect = self.image.get_rect()
        self.rect.x = 50
        self.rect.bottom = floor_y
        self.y_speed = 0
        self.jump_speed = 15
        self.gravity = .8

    def jump(self):
        if self.y_speed == 0:
            self.y_speed = self.jump_speed

    def update(self):
        if self.y_speed > 0 or self.rect.bottom < floor_y:
            self.rect.bottom -= self.y_speed
            self.y_speed -= self.gravity
        if self.rect.bottom >= floor_y and self.y_speed < 0:
            self.y_speed = 0


# OBJECT CLASS
class Obstacle(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.image.load("obstacle.png")
        self.image = pygame.transform.scale(self.image, (50, 50))
        self.rect = self.image.get_rect()
        self.rect.left = length
        self.rect.bottom = floor_y
        self.speed = obstacle_speed

    def update(self):
        self.rect.left -= self.speed


# GROUPS
all_sprites = pygame.sprite.Group()
obstacles = pygame.sprite.Group()

# ADD PLAYER TO GROUP
player = Player()
all_sprites.add(player)

# SPAWN OBJECTS
object_spawn_interval = 1500
last_object_spawn_time = 0


def spawn_object():
    obstacle = Obstacle()
    all_sprites.add(obstacle)
    obstacles.add(obstacle)
    global object_spawn_interval
    object_spawn_interval = random.randint(1000, 2000)


# GAME LOOP
while True:
    print(obstacle_speed)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
            player.jump()

    # DRAW GROUND
    screen.blit(background_image, (background_x, background_y))
    pygame.draw.rect(screen, (72, 111, 56), (0, floor_y, length, 300))

    # UPDATE SPRITES
    all_sprites.update()
    current_time = pygame.time.get_ticks()

    # SPAWN OBJECTS
    if current_time - last_object_spawn_time >= object_spawn_interval:
        spawn_object()
        last_object_spawn_time = current_time

    # CHECK COLLISIONS
    if pygame.sprite.spritecollide(player, obstacles, False):
        draw_text(f"Game Over", WHITE, length/2, 50)
        pygame.display.flip()
        pygame.time.wait(2000)
        all_sprites.empty()
        obstacles.empty()
        player = Player()
        all_sprites.add(player)
        score = -10
        obstacle_speed = 5

    # DRAW SPRITES AND SCORE
    all_sprites.draw(screen)
    draw_text(f'Score: {int(score)}', WHITE, length/2, 50)

    pygame.display.flip()
    obstacle_speed += 0.001
    score += clock.tick(FPS) / 1000 * obstacle_speed
    
    pygame.display.flip()



shorten this code