A simple, well-documented implementation of the classic Flappy Bird game using HTML5 Canvas and vanilla JavaScript. This project is designed for learning game development concepts and JavaScript programming.
- Objective: Navigate the yellow bird through gaps between green pipes
- Controls:
- Press SPACEBAR or CLICK anywhere on the game area to make the bird flap
- Same controls work for starting the game and restarting after game over
- Scoring: Gain 1 point for each pair of pipes you successfully pass through
- Game Over: Touching pipes, ground, or ceiling ends the game
- Download the files: Get all three files (
index.html
,app.js
,style.css
) - Open the game: Simply open
index.html
in any modern web browser - Start playing: Press spacebar or click to begin!
No installation, setup, or external dependencies required - just open and play!
flappy-bird/
├── index.html # Main HTML file with game canvas and UI
├── app.js # Game logic and JavaScript code
├── style.css # Styling and visual design
└── README.md # This documentation file
- Physics: Realistic gravity simulation with customizable jump strength
- Collision Detection: Precise boundary checking for bird-pipe interactions
- Procedural Generation: Infinite pipe generation with random gap positions
- Game States: Menu, playing, and game over states with smooth transitions
- Score System: Real-time score tracking and display
- Heavily Commented: Every function and concept explained for learning
- Modular Design: Clean separation of game logic, rendering, and input handling
- Constants: Easy-to-modify game parameters for customization
- Best Practices: Modern JavaScript with clear variable naming and structure
- Canvas Graphics: All graphics drawn programmatically - no external images needed
- Smooth Animation: 60 FPS game loop using
requestAnimationFrame
- Responsive Design: Centered layout that works on different screen sizes
- Visual Polish: Gradients, shadows, and clean typography
The game is designed to be easily customizable. Here are some parameters you can modify in app.js
:
// Physics Constants
const GRAVITY = 0.6; // Bird falling speed
const JUMP_STRENGTH = -10; // Bird flapping power
const PIPE_SPEED = 2; // Pipe movement speed
const PIPE_GAP = 180; // Gap size between pipes
const PIPE_WIDTH = 50; // Width of pipes
- Difficulty: Increase gravity or decrease pipe gap
- Speed: Adjust pipe speed for faster/slower gameplay
- Colors: Change colors in the drawing functions
- Bird Size: Modify the bird radius
- Game Area: Adjust canvas dimensions in HTML
This project demonstrates several important programming concepts:
- Object-Oriented Programming: Game objects with properties and methods
- Event Handling: Keyboard and mouse input processing
- Animation Loops: Game loop architecture with
requestAnimationFrame
- Array Manipulation: Dynamic pipe management
- Collision Detection: Mathematical boundary checking
- State Management: Game state transitions
- Game Loop: Update → Check Collisions → Render cycle
- Entity Management: Creating, updating, and destroying game objects
- Input Handling: Responsive controls for gameplay
- Scoring Systems: Point tracking and display
- Physics Simulation: Gravity and movement calculations
- HTML5 Canvas: 2D graphics rendering
- CSS Layout: Responsive design and styling
- DOM Manipulation: Updating UI elements
- File Organization: Proper project structure
Works in all modern browsers including:
- Chrome 50+
- Firefox 45+
- Safari 10+
- Edge 12+
Every function in the code includes detailed comments explaining:
- Purpose: What the function does
- Parameters: Input values and their meanings
- Logic: Step-by-step explanation of the algorithm
- Game Development Concepts: Why certain approaches are used
Want to extend the project? Here are some ideas:
- Add sound effects and background music
- Implement different bird characters or power-ups
- Create multiple difficulty levels
- Add particle effects for flapping or collisions
- Implement local high score storage
- Add mobile touch controls
- Create animated pipe textures
- Add day/night cycle backgrounds
This is a learning project! Feel free to:
- Fork and modify for your own learning
- Add new features and improvements
- Share with other learners
- Use as a starting point for more complex games
This project is created for educational purposes. Feel free to use, modify, and share!
Happy Coding! 🚀
This project demonstrates that you can create engaging games with just vanilla JavaScript - no frameworks required!