How arsalanyavari/flappy-bird works
Project type and purpose
• This is a single-page, front-end web game (Flappy Bird clone) built with pure JavaScript, HTML, and CSS.
• The purpose is to practice DOM manipulation, game loops, asset loading, and browser APIs without any back-end or build toolchain.
File structure
• Top-level files:
– index.html: the game’s entry point
– script.js: main game logic & loop
– style.css: presentation rules
– assets/: static resources (pics & sounds)
– examples/: demo snapshots or variations
• No backend or server-side code → all execution happens in the browser.
• Asset directory separation (pics vs. sounds) suggests an asset loader module in script.js.
README for additional insights
• Confirms it’s a pure-JS implementation for practice.
• No extra libraries or frameworks (e.g., React, WebGL) are used.
• Hosted as a static site (GitHub Pages).
a. Main components to represent:
• Browser Environment (host)
• index.html (DOM scaffold + canvas or container)
• CSS Engine (style.css)
• JavaScript Layer (script.js) broken into sub-modules:
– Asset Loader (images & audio)
– Input Handler (mouse/tap/keyboard)
– Game Loop / Scheduler
– Game State Manager (bird, pipes, score)
– Renderer (draws frames on canvas or DOM)
– Audio Manager (plays sounds)
– UI Overlay (scoreboard, “Game Over” screen)
• Static Assets (assets/pics, assets/sounds)
b. Relationships and interactions:
• index.html → loads style.css & script.js
• On load, script.js initializes:
– Asset Loader fetches images & audio from assets/
– Once ready, Game Loop starts
• Game Loop invokes in each tick:
– Input Handler → updates intended actions (flap)
– Game State Manager → computes new positions, collision
– Renderer → draws bird, pipes, background
– Audio Manager → triggers sounds on events (hit, score)
• UI Overlay listens to state for score updates & game-over
c. Architectural patterns & design principles:
• Modular separation of concerns (loader, logic, rendering, I/O)
• Single responsibility modules (each has one well-defined role)
• Event-driven updates via the game loop
• Resource abstraction (Asset Loader encapsulates raw fetch logic)
• HTML5 (canvas or div elements)
• CSS3 for layout and styling
• Vanilla JavaScript (ES6+)
• Browser APIs (requestAnimationFrame, Audio API, event listeners)