Skip to content

delee03/flappyBirdGamesWithAmazonQ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆ Flappy Bird Game

A modern implementation of the classic Flappy Bird game built with Phaser 3, TypeScript, and Rollup. Features include physics-based gameplay, score tracking, high score persistence, and responsive controls.

Flappy Bird Game TypeScript Phaser Build

๐ŸŽฎ Game Features

  • ๐ŸŽฏ Physics-based gameplay with realistic bird movement and gravity
  • ๐Ÿ† Score system with manual position tracking for accurate scoring
  • ๐Ÿ’พ High score persistence using localStorage
  • ๐ŸŽต Sound effects for flap, score, and collision events
  • ๐Ÿ“ฑ Responsive controls supporting both mouse clicks and keyboard input
  • ๐ŸŽจ Smooth animations with bird sprite animations and background scrolling
  • ๐Ÿ”„ Scene management with Menu, Game, and Game Over screens
  • โšก Optimized performance with efficient collision detection

๐Ÿ—๏ธ Project Architecture

Play game Game Logs

Directory Structure

flappy-bird-game/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ assets/
โ”‚   โ”‚   โ”œโ”€โ”€ images/          # Game sprites and textures
โ”‚   โ”‚   โ””โ”€โ”€ audio/           # Sound effects
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ gameConfig.ts    # Game configuration constants
โ”‚   โ”œโ”€โ”€ objects/
โ”‚   โ”‚   โ”œโ”€โ”€ Bird.ts          # Bird class with physics and animations
โ”‚   โ”‚   โ”œโ”€โ”€ PipeManager.ts   # Pipe generation and scoring logic
โ”‚   โ”‚   โ””โ”€โ”€ Background.ts    # Background and ground management
โ”‚   โ”œโ”€โ”€ scenes/
โ”‚   โ”‚   โ”œโ”€โ”€ BootScene.ts     # Asset loading scene
โ”‚   โ”‚   โ”œโ”€โ”€ MenuScene.ts     # Main menu scene
โ”‚   โ”‚   โ”œโ”€โ”€ GameScene.ts     # Main gameplay scene
โ”‚   โ”‚   โ””โ”€โ”€ GameOverScene.ts # Game over and restart scene
โ”‚   โ””โ”€โ”€ game.ts              # Main game entry point
โ”œโ”€โ”€ dist/                    # Built game files
โ”œโ”€โ”€ rollup.config.js         # Build configuration
โ”œโ”€โ”€ copy-assets.js           # Asset copying script
โ””โ”€โ”€ package.json             # Dependencies and scripts

Class Architecture Diagram

graph TB
    subgraph "Game Engine"
        A[Phaser.Game] --> B[Scene Manager]
    end

    subgraph "Scenes"
        B --> C[BootScene]
        B --> D[MenuScene]
        B --> E[GameScene]
        B --> F[GameOverScene]
    end

    subgraph "Game Objects"
        E --> G[Bird]
        E --> H[PipeManager]
        E --> I[Background]
    end

    subgraph "Configuration"
        J[GameConfig] --> G
        J --> H
        J --> I
    end

    subgraph "Asset Management"
        C --> K[Images]
        C --> L[Audio]
        K --> M[Bird Sprites]
        K --> N[Pipe Textures]
        K --> O[Background Images]
    end

    subgraph "Game Logic"
        H --> P[Manual Score Detection]
        G --> Q[Physics & Animation]
        E --> R[Collision Detection]
        F --> S[High Score Storage]
    end

    subgraph "Storage"
        S --> T[localStorage]
    end

    classDef sceneClass fill:#e1f5fe
    classDef objectClass fill:#f3e5f5
    classDef configClass fill:#fff3e0
    classDef storageClass fill:#e8f5e8

    class C,D,E,F sceneClass
    class G,H,I objectClass
    class J configClass
    class T storageClass
Loading

Core Components

๐ŸŽฎ GameScene - Main Game Controller

  • Orchestrates all game objects and systems
  • Handles input events and collision detection
  • Manages game state (playing, paused, game over)
  • Coordinates between Bird, PipeManager, and Background

๐Ÿฆ Bird Class - Player Character

  • Physics-based movement with gravity and flap mechanics
  • Sprite animation system with multiple bird states
  • Collision body management and rotation effects
  • Sound effect integration for flap actions

๐Ÿ—๏ธ PipeManager - Obstacle System

  • Manual Score Detection Algorithm: Custom position tracking system
  • Dynamic pipe generation with randomized gap positions
  • Efficient cleanup of off-screen pipes
  • Score trigger management without physics overlap

๐ŸŽฏ Manual Scoring Algorithm

// Core scoring logic
private checkScoreManually(): void {
    const birdX = 50; // Fixed bird position

    this.scoreTriggers.forEach(trigger => {
        // Update trigger position (pipes move left)
        trigger.x += GameConfig.pipes.speed * deltaTime;

        // Score when pipe passes bird
        if (!trigger.scored && trigger.x <= birdX && trigger.x > birdX - 50) {
            trigger.scored = true;
            this.passedPipes++;
            this.scene.events.emit('score-updated', this.passedPipes);
        }
    });
}

๐Ÿ› ๏ธ Technologies Used

Technology Version Purpose
Phaser 3 3.60.0 Game engine and physics
TypeScript 5.0.0 Type-safe JavaScript development
Rollup 3.20.0 Module bundler and build tool
Node.js 20.x Development environment
HTML5 Canvas - Rendering and graphics
Web Audio API - Sound effects
localStorage - High score persistence

Build Tools & Plugins

  • @rollup/plugin-typescript - TypeScript compilation
  • @rollup/plugin-node-resolve - Module resolution
  • @rollup/plugin-commonjs - CommonJS support
  • rollup-plugin-serve - Development server
  • rollup-plugin-livereload - Hot reload

๐Ÿš€ Setup & Installation

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • Modern web browser with HTML5 support

Installation Steps

  1. Clone the repository

    git clone <repository-url>
    cd flappy-bird-game
  2. Install dependencies

    npm install
  3. Build the project

    npm run build
  4. Start development server

    # Option 1: Using built-in serve script
    npm run serve
    
    # Option 2: Using Python HTTP server
    cd dist && python3 -m http.server 8080
    
    # Option 3: Using Node.js http-server
    npx http-server dist -p 8080
  5. Open in browser

    http://localhost:8080
    

Development Workflow

# Development with hot reload
npm run dev

# Production build
npm run build

# Serve built files
npm run serve

๐ŸŽฏ Game Mechanics

Physics System

  • Gravity: 700 pixels/secondยฒ
  • Flap Strength: -350 pixels/second (upward velocity)
  • Pipe Speed: -200 pixels/second (leftward movement)
  • Bird Position: Fixed at X=50, dynamic Y position

Scoring Algorithm

The game uses a manual position tracking system instead of Phaser's built-in collision detection for more reliable scoring:

  1. Score triggers are created at each pipe's X position
  2. Triggers move with the same velocity as pipes (-200 px/s)
  3. Score increments when trigger.x โ‰ค bird.x (pipe passes bird)
  4. Duplicate prevention using scored boolean flags

Collision Detection

  • Pipe Collision: Phaser physics collision between bird and pipe sprites
  • Ground Collision: Static collision with ground boundary
  • Boundary Collision: World bounds to prevent bird from leaving screen

๐Ÿ“Š Performance Optimizations

  • Object Pooling: Efficient pipe creation and destruction
  • Manual Score Detection: Eliminates physics overhead for scoring
  • Asset Preloading: All assets loaded in BootScene
  • Cleanup System: Automatic removal of off-screen objects
  • Optimized Animations: Lightweight sprite animations

๐ŸŽจ Assets

Images

  • Bird Sprites: 3-frame animation (up, mid, down flap)
  • Pipe Texture: Scalable pipe segments
  • Background: Scrolling sky and ground textures
  • UI Elements: Game over screen and buttons

Audio

  • Flap Sound: Bird wing flap effect
  • Score Sound: Point scoring notification
  • Hit Sound: Collision impact effect

๐Ÿ† High Score System

The game implements persistent high score storage using browser's localStorage:

// Save high score
localStorage.setItem("flappyHighScore", String(highScore));

// Load high score
const storedScore = localStorage.getItem("flappyHighScore");
const highScore = storedScore ? parseInt(storedScore) : 0;

Features:

  • Persistent storage across browser sessions
  • New record detection with visual feedback
  • Cross-session continuity - scores survive browser restarts

๐ŸŽฎ Controls

Input Action
Mouse Click Flap bird wings
Spacebar Flap bird wings
ESC Return to main menu (Game Over screen)

๐Ÿ› Troubleshooting

Common Issues

  1. Assets not loading

    # Ensure assets are copied after build
    npm run build
  2. Score not incrementing

    • Check browser console for manual score detection logs
    • Verify bird and pipe positions in debug output
  3. Sound not playing

    • Ensure browser allows audio autoplay
    • Check audio file paths in BootScene
  4. Build errors

    # Clean install
    rm -rf node_modules package-lock.json
    npm install
    npm run build

๐Ÿ”ง Configuration

Game settings can be modified in src/config/gameConfig.ts:

export const GameConfig = {
  width: 288, // Game canvas width
  height: 512, // Game canvas height
  physics: { gravity: 700 }, // Gravity strength
  bird: {
    initialPosition: { x: 50, y: 250 },
    flapStrength: -350, // Upward velocity on flap
    rotation: { up: -0.5, down: 0.5 },
  },
  pipes: {
    speed: -200, // Horizontal movement speed
    spacing: {
      horizontal: 200, // Distance between pipe pairs
      vertical: 150, // Gap size between top/bottom pipes
    },
  },
};

๐Ÿ“ˆ Future Enhancements

  • Mobile touch controls with responsive design
  • Multiple bird skins and customization options
  • Power-ups system (shield, slow motion, double points)
  • Particle effects for enhanced visual feedback
  • Background music and enhanced audio
  • Online leaderboard with backend integration
  • Progressive difficulty with increasing pipe speed
  • Achievement system with unlockable content

๐Ÿ“„ License

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

๐Ÿค Contributing

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

๐Ÿ™ Acknowledgments

  • Phaser.js community for excellent documentation
  • Original Flappy Bird by Dong Nguyen for game inspiration
  • TypeScript team for robust typing system
  • Rollup for efficient bundling solution

Built with โค๏ธ using Phaser 3 + TypeScript

Happy Gaming! ๐ŸŽฎ

About

Building a Flappy Bird Games with Amazon Q CLI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors