Do the boxes touch?
To know if the player grabbed a coin, the game checks whether their two boxes overlap. That simple 'do the rectangles touch?' test drives coins, hits, and game-overs.
Overlap and state
Collision detection tests if two hitboxes overlap. On a hit, the game updates state — add score, lose a life, or end the game.