π₯ Collisions & Hitboxes

Your hero can move and jump β but right now it would float straight through everything like a ghost. π» A real game needs to know the exact moment two things touch: when you land on a platform, grab a coin, or bump an enemy.
The trick behind ALL of that is one simple idea: invisible boxes.
The big idea: everything has an invisible box
The game wraps an invisible rectangle β a hitboxβ around every single thing: your hero, each platform, every coin. It doesn't really βseeβ the pictures; it just keeps track of these boxes.
Then, every time around the loop, it asks one tiny question over and over: do these two boxes overlap? If yes β touch!β and it runs a rule: land on the platform, collect the coin, take a hit. That's it. That one overlap check is behind almost everything that βhappensβ in a game.
Your turn: see the boxes touch
Here's your hero again β now in a world with platforms and coins. Turn on Show the boxes and watch the hitboxes light up the instant they overlap. Land on the platforms and grab all the coins.
Click the game, then β β to move and β / Space to jump. Land on the platforms and grab every coin!
π¦ Hitboxes
Every object has an invisible box. When two boxes overlap, that's a βtouchβ.
βΈπ§ Peek inside: the coins are a βlist,β checked by a βloopβ
How does the game check all four coins at once? The coins live together in a list (a row of boxes), and every single loop the game runs one rule down the whole list: βfor each coin, did the hero touch it?βFour coins or four hundred, it's the same one rule. Lists and loops are a huge part of how games handle lots of things at once.
π§° Play with it in the Toolkit βDiscovery missions
Try each one, tick it off, then peek at the secret.
π«Jump up onto a floating platform. How does the hero know to STOP there instead of falling through?
πͺWalk into a coin. What happens the exact instant you touch it?
ποΈToggle βShow the boxesβ on and off. Are the boxes exactly the same as the pictures?
π©Stand still on a platform with the boxes shown. What colour does that platform's box turn?
πCollect all 4 coins.
π You leveled up! You now know:
- π¦ Every object has an invisible box around it called a hitbox.
- β Each loop, the game asks: do two boxes overlap?
- β¨ Overlap = βtouchβ β run a rule (land, collect, or bonk).
- π« Landing on a platform IS a collision β the box check holds you up.
- π A whole game is thousands of box-overlap checks, every second.
π¬ Behind the scenes β what's next?
Your game now has platforms, coins, and real collisions. But the hero is still just a plain red square! π₯ Next, we turn that square into an actual character that's drawn β and bring it to life so it walks and jumps with real animation. π