A fully functional Flappy Bird clone built with Python & Pygame
featuring collision detection, score tracking, sound effects, and randomized pipes.
🚀 Getting Started • 🎮 Gameplay • 📁 Structure • ⚙️ Features • 👤 Author
- 🔍 Overview
- 🎮 Gameplay
- 📁 Project Structure
- ⚙️ Features
- 🚀 Getting Started
- 🕹️ Controls
- 🔬 How It Works
- 📦 Assets Required
⚠️ Known Issues & Notes- 🔮 Future Improvements
- 👤 Author
|
This is a fully functional Flappy Bird clone built from scratch using Python and the Pygame library. The player controls a bird navigating through randomly generated pipes, with real-time collision detection, live score display, and full sound effects. The game runs at 32 FPS with smooth sprite rendering and physics-based bird movement. |
| 🏆 Feature | 📋 Detail |
|---|---|
| 🎮 Engine | Pygame |
| 🖥️ Resolution | 289 × 511 pixels |
| 🎯 FPS | 32 |
| 🔊 Sound Effects | Wing, Hit, Point, Die, Swoosh |
| 🌀 Pipes | Randomly generated each run |
┌──────────────────────────────┐
│ 🐦 → Navigate the bird │
│ 🟩 → Avoid the pipes │
│ ⭐ → Score per pipe pass │
│ 💥 → Game over on hit │
└──────────────────────────────┘
- Tap SPACE or ↑ UP to flap and gain altitude
- Gravity pulls the bird down continuously
- Pass through pipe gaps to score points
- Hit a pipe or the ground — Game Over!
📦 flappy-bird/
│
├── 🐍 flappy_bird.py ← Main game script
│
├── 🖼️ Images/
│ ├── bird.png ← Player sprite
│ ├── background.png ← Background image
│ ├── pipe.png ← Pipe sprite
│ ├── base.png ← Ground sprite
│ ├── message.jpg ← Cover/welcome screen
│ ├── message1.png ← Welcome message overlay
│ └── 0.png - 9.png ← Score digit sprites
│
├── 🔊 Sounds/
│ ├── wing.wav ← Flap sound
│ ├── hit.wav ← Collision sound
│ ├── point.wav ← Score sound
│ ├── die.wav ← Death sound
│ └── swoosh.wav ← Swoosh sound
│
└── 📝 README.md ← Project documentation
- ✅ Welcome Screen — Cover page shown before the game starts
- ✅ Physics Engine — Gravity, flap velocity, and acceleration
- ✅ Randomized Pipes — Different gap positions every game
- ✅ Collision Detection — Ground, upper and lower pipe checks
- ✅ Live Score Display — Digit sprites rendered in real time
- ✅ Sound Effects — Wing, point, hit, die, and swoosh
- ✅ Smooth Animation — 32 FPS game loop with Pygame clock
pip install pygamegit clone https://github.com/Hasnain006-nain/flappy-bird.git
cd flappy-birdPlace all image and sound files in the same directory as flappy_bird.py
python flappy_bird.py| Key | Action |
|---|---|
SPACE |
Flap / Jump |
↑ UP Arrow |
Flap / Jump |
ESC |
Quit Game |
✕ Close Button |
Exit |
┌──────────────────────────────────────────────────────────────────┐
│ GAME LOOP OVERVIEW │
├──────────────────────────────────────────────────────────────────┤
│ │
│ 1. 🟢 Initialize → Pygame init, load sprites & sounds │
│ │
│ 2. 🖼️ Welcome Screen → Show cover until SPACE is pressed │
│ │
│ 3. 🎮 Main Game Loop → Handle events every frame │
│ │
│ 4. 🌀 Generate Pipes → Random gap positions via getRandomPipe│
│ │
│ 5. 🐦 Bird Physics → Gravity + flap velocity applied │
│ │
│ 6. 💥 Collision Check → Ground, upper pipe, lower pipe │
│ │
│ 7. ⭐ Score Update → Increment when pipe midpoint passed │
│ │
│ 8. 🖥️ Render Frame → Blit background, pipes, bird, score │
│ │
│ 9. 🔁 Repeat / Reset → Return to welcome on crash │
│ │
└──────────────────────────────────────────────────────────────────┘
offset = SCREENHEIGHT / 3
y2 = offset + random.randrange(0, int(SCREENHEIGHT - base_height - 1.2 * offset))
y1 = pipeHeight - y2 + offset
# Returns upper pipe (inverted) + lower pipe positionsplayerVelY += playerAccY # Gravity pulls bird down
playerVelY = playerFlapAccv # Flap gives upward velocity
playery += min(playerVelY, GROUNDY - playery - playerHeight)| File | Type | Description |
|---|---|---|
bird.png |
Image | Bird player sprite |
background.png |
Image | Game background |
pipe.png |
Image | Pipe obstacle sprite |
base.png |
Image | Ground/floor sprite |
message.jpg |
Image | Welcome cover screen |
message1.png |
Image | Welcome overlay text |
0.png – 9.png |
Images | Score digit sprites |
wing.wav |
Sound | Flap sound effect |
hit.wav |
Sound | Collision sound effect |
point.wav |
Sound | Score sound effect |
die.wav |
Sound | Death sound effect |
swoosh.wav |
Sound | Swoosh sound effect |
💡 All assets must be in the same folder as the main Python script.
if playerFlapped:
playerFlapped = False # ← Missing indentationFix:
if playerFlapped:
playerFlapped = FalseIf any .png, .jpg, or .wav file is missing, Pygame will raise a FileNotFoundError. Ensure all assets are present before running.
- 🏆 Add High Score saving system
- 🎨 Add multiple bird skin options
- 🌙 Add day/night background switching
- 📱 Port to mobile using Kivy or similar
- 🤖 Add an AI agent to play automatically using NEAT or Q-Learning
- 🔊 Add background music loop
╔════════════════════════════════════╗
║ ║
║ Hasnain Haider ║
║ ║
║ Python Developer & ML Engineer ║
║ Games | Data Science | AI ║
║ ║
╚════════════════════════════════════╝
© 2024 Hasnain Haider — Built for educational purposes in Python Game Development
⭐ If you found this project helpful, please give it a star! ⭐