Update
Last chapter you drew one frame. The computer drew it twenty times a second — but it was the same picture every time, so nothing appeared to move.
Movement needs a second function:
Now the loop is a real loop:
- call
update— the numbers change - call
draw— a picture is made from those numbers - put it on screen
- do it again, twenty times a second
update changes numbers. draw turns numbers into a picture. Keeping
those two jobs apart is the single most useful habit in this milestone.
What is state?
state is a dictionary that survives between frames. Everything the animation
needs to remember lives in it.
You already have some keys for free:
draw reads them. update changes them. That is the whole conversation.
The rule that will catch you
update must return state. Just like draw returns the grid:
Miss it and you'll see "update() didn't return anything."
Ignore keys for now. It's how the keyboard gets in, and you'll use it in
Chapter 9 when you build something you can actually play.
Rows count downward
Worth burning in now, because it feels backwards at first:
state["y"]bigger → further down the screenstate["y"]smaller → further up
That is just how grid[row][col] works — row 0 is the top. A dot that
"falls" has a y that grows.