import pygame from sprites import Player, Platform, End def level_3(screen_height, screen_width, screen): # Initialize Pygame pygame.init() # Create sprites player = Player() platform = Platform(0, screen_height - 50, screen_width, 50) end = End(screen_height - 100, screen_width - 100) # Create sprite group for player and platforms all_sprites = pygame.sprite.Group() all_sprites.add(player, platform, end) platforms = pygame.sprite.Group() platforms.add(platform) # Main game loop running = True clock = pygame.time.Clock() while running: for event in pygame.event.get(): if event.type == pygame.QUIT: return "quit" elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return "display_menu" # Display menu when Escape key is pressed # Get pressed keys keys = pygame.key.get_pressed() # Update player position and animation based on pressed keys player.update(keys, platforms) # Check for collision between player and end sprite if pygame.sprite.collide_rect(player, end): return "level_selector" # Background screen.fill((0, 0, 0)) # Draw all sprites all_sprites.draw(screen) # Update the display pygame.display.flip() # Cap the frame rate clock.tick(60) # Quit Pygame pygame.quit()