import pygame from sprites import Player, Platform, End, Kill def level_1(screen_height, screen_width, screen): # Initialize Pygame pygame.init() # Create sprites player = Player() platform = Platform(0, screen_height - 50, 3600, 50) end = End(platform.rect.right - 100, 700) kill = Kill(screen_height - 800, screen_width - 800) # Create sprite group for player and platforms all_sprites = pygame.sprite.Group() all_sprites.add(player, platform, end, kill) platforms = pygame.sprite.Group() platforms.add(platform) # Set initial camera position camera_x = 0 # 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) if pygame.sprite.collide_rect(player, kill): return "quit" # Check for collision between player and end sprite if pygame.sprite.collide_rect(player, end): level_end = 1 print("Level end:", level_end) return "level_selector" # Return to level selector # Move the 'kill' sprite slowly to the right kill.rect.x += 4 # Adjust camera position based on player's movement camera_x = max(player.rect.centerx - screen_width // 2, 0) # Draw background screen.fill((0, 0, 0)) # Draw all sprites with adjusted positions for sprite in all_sprites: screen.blit(sprite.image, (sprite.rect.x - camera_x, sprite.rect.y)) # Update the display pygame.display.flip() # Cap the frame rate clock.tick(60) # Quit Pygame pygame.quit()