Generate Python code for an enhanced Flappy Bird clone using the Pygame library, featuring increased complexity and polish.
Core Constraint: The game must be entirely self-contained, using no external asset files (no images, sounds, or custom fonts). All visual elements, including backgrounds and effects, must be generated programmatically using Pygame's drawing functions (pygame.draw.*) and standard system fonts (pygame.font.SysFont).
Key Features to Implement:
Game Structure & States:
Title Screen: A simple starting screen displaying the game title (drawn text) and instructions (e.g., "Press Space to Start").
Gameplay State: The main interactive game loop.
Pause State: Ability to pause/unpause the game (e.g., using the 'P' key), overlaying a "Paused" message.
Game Over Screen: Displayed upon collision, showing the final score, the high score, and instructions to restart (e.g., "Press Space to Retry").
Visuals & Presentation (Programmatic):
Enhanced Bird: Represent the bird using multiple combined primitive shapes (e.g., a circle body, a triangle beak) to give it more character than a single shape. Implement a simple flapping animation (e.g., slightly changing the shape, position, or color of a 'wing' element upon flapping).
Procedural Background: Create a multi-layered background using solid colors and drawn shapes (e.g., simple rectangles for distant buildings, circles for clouds or stars).
Parallax Scrolling: Implement parallax scrolling for the background layers. Elements further 'away' should move slower than elements closer to the foreground (like pipes).
Visual Feedback: Add simple visual cues, like a screen flash (briefly change background color) on collision or a subtle particle effect (small drawn squares/circles) when flapping or scoring (optional, if feasible without impacting performance).
Gameplay Mechanics:
Physics: Implement smoother gravity and flap mechanics (e.g., variable jump height based on press duration, or diminishing returns on rapid flaps).
Dynamic Pipes:
Pipes should still move right-to-left.
Introduce vertical movement to some pipes (pipes slowly oscillating up and down as they approach).
Vary the gap size between pipe pairs randomly within a defined range.
Collision Detection: Accurate collision detection between the bird (consider its multi-shape form if applicable) and pipes/screen boundaries.
Difficulty Scaling:
The game difficulty should increase progressively over time or based on score. This could involve:
Increasing pipe scrolling speed.
Decreasing the gap size between pipes (down to a minimum).
Increasing the frequency or amplitude of vertical pipe movement.
Increasing the rate at which pipes are generated.
Scoring & Progression:
Score: Increment score for passing pipes. Display prominently using pygame.font.SysFont.
High Score: Implement a persistent high score saved locally to a simple text file (e.g., highscore.txt). Load it on startup and save it when a new high score is achieved. Display the high score on the Title and Game Over screens.
Medal System (Optional): Based on the final score, display a simple text-based medal (e.g., "Bronze", "Silver", "Gold") on the Game Over screen using different colors drawn with SysFont.
Code Quality:
Employ Object-Oriented Programming (OOP): Use classes for Bird, Pipe, and potentially a GameManager or state handler to structure the code logically.
Include clear comments and use descriptive variable names.
Ensure the code is reasonably efficient to maintain smooth gameplay.