Something to Lose
You have a hero who jumps and a world that scrolls. That is not yet a game, because nothing can go wrong.
A game needs three more things, and none of them are hard:
- a way to lose — collision
- a way for the game to stop — a flag in the state
- a reason to care — a score
Collision is just comparing numbers
There is no physics engine here. A crash is an if:
"Is a rock in the hero's column, and is the hero on the ground?" If yes, they touched. If the hero is in the air, the rock passes underneath.
That's it. Every collision in every game is some version of "are these two things in the same place?"
A flag that stops the world
Return early and nothing else in update runs — rocks stop, gravity stops, the
picture freezes. One if at the top of the function turns the whole game off.
is_playing is an ordinary True/False in the state, exactly like the
booleans you met in Milestone 1.
The HUD
hud(state) is a fourth function you can write. Whatever string it returns gets
printed under the game:
str() matters. "Score: " + 5 is the crash you met back in Variables —
Python will not glue a number onto text for you.
Order inside update
The order these happen in changes the game:
Check collisions after everything has moved, or you're testing where things used to be. That is the single most common source of "it hit me but it clearly missed!" — and players notice immediately.