Skip to content

A modern Flappy Bird clone featuring HTML5 Canvas rendering, delta-time physics, and Zustand state management. Navigate through procedurally generated pipes with smooth 60fps gameplay on desktop and mobile. Built with React 19, TypeScript, Vite, and Tailwind CSS with AI assistance.

License

Notifications You must be signed in to change notification settings

Serkanbyx/flappy-bird

๐Ÿค Flappy Bird

A modern Flappy Bird clone built with React, TypeScript, and HTML5 Canvas. Navigate through pipes by tapping or pressing space, compete with yourself, and beat your best score!

Created by Serkanby GitHub

Features

  • Canvas-Based Rendering: Smooth 60fps gameplay using HTML5 Canvas with custom-drawn bird, pipes, and environment
  • Frame-Rate Independent Physics: Delta-time based game loop ensures consistent gameplay on 60Hz, 144Hz, or any refresh rate
  • Zustand State Management: Lightweight and performant centralized game state with zero boilerplate
  • Score Persistence: Best score automatically saved and loaded from localStorage
  • Retro Pixel Art Style: Custom canvas-drawn bird with animated wing flaps, gradient pipes, and scrolling ground
  • Touch & Keyboard Support: Play with Space, ArrowUp, Enter, click, or tap โ€” works on desktop and mobile
  • Responsive Design: Fullscreen centered layout that adapts to any screen size
  • Accessible UI: ARIA labels, keyboard navigation, and semantic HTML for screen readers

Live Demo

๐ŸŽฎ View Live Demo

Technologies

  • React 19: UI components, overlays, and game lifecycle management
  • TypeScript 5: Full type safety across game state, physics, and rendering
  • Vite 6: Lightning-fast dev server and optimized production builds
  • Zustand 5: Minimal state management for game state (bird, pipes, score)
  • React Router 7: Client-side routing with catch-all redirect
  • Tailwind CSS 3: Utility-first styling for UI overlays and animations
  • HTML5 Canvas: Core game rendering engine with gradient effects and sprite drawing

Installation

Local Development

  1. Clone the repository:
git clone https://github.com/Serkanbyx/flappy-bird.git
cd flappy-bird
  1. Install dependencies:
npm install
  1. Start the development server:
npm run dev
  1. Open your browser and navigate to http://localhost:5173

Build for Production

npm run build
npm run preview

Usage

  1. Open the game in your browser
  2. Press Space, ArrowUp, Enter, or click/tap anywhere to start the game
  3. Press Space, ArrowUp, or click/tap to make the bird flap its wings
  4. Navigate through the gaps between pipes without hitting them or the ground
  5. Each pipe pair passed earns 1 point
  6. When game is over, press Space, Enter, or click/tap to restart
  7. Your best score is automatically saved and displayed on the start screen

How It Works?

Game Loop

The game uses requestAnimationFrame for a smooth game loop. A custom useGameLoop hook manages the animation cycle and provides delta-time values for frame-rate independent updates:

const dt = Math.min(deltaTime, 33.33) / TARGET_FRAME_MS;

This normalization ensures all physics constants (tuned for 60fps) work consistently on any monitor โ€” from 60Hz to 144Hz and beyond.

Bird Physics

The bird is affected by gravity each frame. Flapping applies an upward velocity, and the bird rotates smoothly based on its current velocity:

const BIRD = {
  gravity: 0.45,
  flapPower: -7.5,
  maxVelocity: 10,
  maxUpRotation: -25,
  maxDownRotation: 70,
};

Rotation uses linear interpolation (lerp) for smooth transitions between upward and downward angles.

Collision Detection

AABB (Axis-Aligned Bounding Box) collision detection checks the bird against:

  • Top boundary (ceiling)
  • Bottom boundary (ground)
  • Pipe pairs (both top and bottom segments)

Canvas Rendering

All game visuals are drawn procedurally on an HTML5 Canvas (400ร—600px):

  • Sky: Linear gradient from light blue to sky blue
  • Pipes: Multi-stop gradients with cap overhangs and border strokes
  • Bird: Ellipse body, animated wing, eye with pupil, and triangular beak
  • Ground: Gradient fill with scrolling dash pattern
  • Score: Retro pixel font with shadow effect

Customization

Change Bird Physics

Modify src/constants/game.ts to adjust the bird's behavior:

export const BIRD = {
  gravity: 0.45,      // Increase for faster falling
  flapPower: -7.5,    // More negative = stronger flap
  maxVelocity: 10,    // Maximum falling speed
};

Change Pipe Difficulty

Adjust pipe gap, speed, and spacing for different difficulty levels:

export const PIPE = {
  gap: 150,           // Vertical gap between pipes (smaller = harder)
  speed: 2.5,         // Horizontal scroll speed (higher = harder)
  spacing: 220,       // Distance between pipe pairs
};

Change Colors

All game colors are centralized in the COLORS constant:

export const COLORS = {
  skyTop: "#4dc9f6",
  skyBottom: "#87ceeb",
  birdBody: "#f7dc6f",
  pipeBody: "#73bf2e",
  // ... more colors
};

Features in Detail

Completed Features

  • โœ… Canvas-based 60fps game rendering
  • โœ… Frame-rate independent physics (deltaTime)
  • โœ… Gravity, flap mechanics, and smooth rotation
  • โœ… Procedural pipe generation with random heights
  • โœ… AABB collision detection (pipes, ground, ceiling)
  • โœ… Score tracking with localStorage persistence
  • โœ… Start screen with floating bird animation
  • โœ… Game over screen with score panel and "NEW!" badge
  • โœ… Keyboard support (Space, ArrowUp, Enter)
  • โœ… Touch and click support for mobile
  • โœ… Responsive fullscreen layout
  • โœ… Accessible UI with ARIA labels
  • โœ… Netlify deployment ready

Future Features

  • Sound effects (flap, score, crash)
  • Difficulty progression (increasing speed over time)
  • Multiple bird skins / themes
  • Global leaderboard
  • Night mode / day-night cycle

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feat/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feat/amazing-feature)
  5. Open a Pull Request

Commit Message Format

  • feat: โ€” New feature
  • fix: โ€” Bug fix
  • refactor: โ€” Code refactoring
  • docs: โ€” Documentation changes
  • chore: โ€” Maintenance tasks

License

This project is licensed under the MIT License. See the LICENSE file for details.

Developer

Serkan Bayraktar

Acknowledgments

Contact


โญ If you like this project, don't forget to give it a star!

About

A modern Flappy Bird clone featuring HTML5 Canvas rendering, delta-time physics, and Zustand state management. Navigate through procedurally generated pipes with smooth 60fps gameplay on desktop and mobile. Built with React 19, TypeScript, Vite, and Tailwind CSS with AI assistance.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published