Exercise 1 · Chapter: GravityRequired+50 XP
It Falls
Make a dot accelerate downward.
Start with y at 0 and vy at 0. Each frame:
- add
1tovy— that's gravity - add
vytoy— that's moving
The test prints y and vy together. You should see 1/1, 3/2, 6/3 — the
speed climbing by one, and the position jumping by more each time.
Only run it for a few frames. Nothing stops this dot yet, and past row 13 it will fall right out of the picture.
Expected output
1/1 3/2 6/3 10/4
Need a hint?
3 available · costs 5 XP each
python
def new_game():
return {"y": 0, "vy": 0}
def update(state, keys):
# Gravity first: add 1 to vy. Then move: add vy to y.
return state
def draw(state):
grid = blank_grid()
grid[state["y"]][20] = "white"
return grid