Lesson goal: Flappy Bird: Flight Timing & Kinematics

Previous: LEGO 3D Studio: Solid Geometry & Discrete Coordinates | Home | Next: Sherlock Holmes and The Adventure of the Dancing Men

In 2013, Vietnamese developer Dong Nguyen captivated the world with Flappy Bird, a notoriously challenging arcade game that highlights classical gravity and kinematic flight timing.

Guiding a bird through narrow pipe gaps requires balancing continuous downward gravity against upward flapping impulses.

Rather than relying on frantic button presses, we can program our bird's flight by sequencing flapping and waiting!

1. The Physics of Flapping vs. Gravity

At any moment, two fundamental forces govern the bird's vertical motion:
  • Gravity ($g = 780\text{ px/s}^2$): Continuously pulls the bird downward: $v_y(t + \Delta t) = v_y(t) + g \cdot \Delta t$.
  • Altitude: $y(t + \Delta t) = y(t) + v_y \cdot \Delta t$.
  • Flapping: When flapping, the bird repeatedly beats its wings upward ($\Delta v_y = -250\text{ px/s}$), overcoming gravity to climb or hold its altitude.
  • Gliding / Waiting: When waiting, the bird glides forward without flapping, allowing gravity to pull it downward toward lower pipe gaps.


2. Controlling Flight with Lua

  • flappy_game(n): Starts Stage #$n$ (1: Gentle Openings, 2: Oscillating Gaps, 3: Narrow Pipes, 4: Endless Marathon).
  • flap(n): Flaps wings continuously for $n$ seconds to climb upward against gravity (defaults to 0.3 seconds if $n$ is omitted).
  • wait(n): Waits for $n$ seconds without flapping, gliding forward while gravity pulls downward (defaults to 0.5 seconds if $n$ is omitted).


By combining flap(t) and wait(t)—or using a for loop—you can craft the exact flight path needed to pass safely through every pipe!
flappy_game(1)
flap(0.5)
wait(0.6)
flap(0.4)
wait(0.5)
Move the mouse over a dotted box for more information.

  • Live Flight Telemetry HUD: Real-time readout of Score, current flight Action with remaining time, Altitude $y$, and Velocity $v_y$.
  • Manual Intervention: Press the Spacebar, click the canvas, or press Flap to manually test flight dynamics at any time!
  • Loops for Repetition: Use Lua loops like for i = 1, 4 do flap(0.4) wait(0.5) end to create steady, rhythmic flight patterns!
  • Procedural Retro Audio: Zero-dependency Web Audio wing swooshes, golden point chimes, and crash impacts.

Now you try. Can you clear all pipes by adjusting the flap and wait durations, or by using a for loop?

Type your code here:


See your results here: