import pygame

# Initialize pygame
pygame.init()
clock = pygame.time.Clock()


def zastavka():
    # 1. Added quotes around the file path
    # 2. Moved set_mode OUTSIDE the loop for better performance
    sc = pygame.display.set_mode([800, 800])
    pygame.display.set_caption("MyGame")

    # Try/Except block in case the image file is missing
    try:
        images = pygame.image.load("png/rocket2.png")
    except:
        # Fallback if image doesn't exist
        images = pygame.Surface((50, 50))
        images.fill((255, 0, 0))

    myfont2 = pygame.font.Font(None, 80)
    # 3. Added quotes around the string
    text = myfont2.render("Космический корабль", True, (255, 255, 255))

    running = True
    while running:
        sc.fill((50, 50, 50))
        sc.blit(images, (20, 50))
        sc.blit(text, (15, 14))

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            # 4. Fixed incorrect event constant
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:  # Example: Close on Escape
                    running = False

        pygame.display.flip()
        clock.tick(60)  # Standard 60 FPS

    pygame.quit()


zastavka()

