Gravity
Our bird is floating in mid-air. That is not how the real world works. Time to add gravity, the force that pulls everything down. This is what makes Flappy Bird feel real.
Gravity = Adding to Y
Remember: bigger Y means further down. So to make something fall, we keep adding to its Y position.
Newton would be proud
In the real world, gravity makes things fall faster over time. We simulate this with two variables: velocity (how fast the bird is moving) and gravity (how much velocity increases each frame).
The Two-Step Fall
Each frame, two things happen in order:
Gravity pulls on velocity
velocity += gravity (the bird speeds up)
Velocity moves the bird
bird_y += velocity (the bird’s position changes)
gravity = 0.5bird_velocity = 0 # Each frame:bird_velocity += gravity # speed upbird_y += bird_velocity # move downQuick Check
Think it through
Frame 1: velocity = 0 + 0.5 = 0.5
Frame 2: velocity = 0.5 + 0.5 = 1.0
Frame 3: velocity = 1.0 + 0.5 = ?
After 3 frames with gravity = 0.5, what is the bird’s velocity?
Your Turn: Make It Fall
Use the right operators to wire up gravity.
Velocity: 0.0
Level Goal
Make the bird fall by adding gravity to velocity, then velocity to bird_y.