โ† Back to the map
Lesson 1

๐Ÿ” The Game Loop

The Game Loop illustration

Press a key โ€” your hero moves. Let go โ€” it stops. Jump โ€” it comes back down. It feels alive. ๐Ÿค” But the computer is just a machine that does what it's toldโ€ฆ so how does it know what to do?

The answer is one of the biggest secrets behind every game ever made. Let's uncover it.

1

The big idea: a game is a loop

A video game is really just a list of rules the computer follows super fast โ€” about 60 times every second. Each time around, it does the same three things:

  • ๐Ÿ‘‚ Listen โ€” which keys are you pressing?
  • ๐Ÿƒ Move โ€” move everyone by the rules (gravity, speedโ€ฆ).
  • ๐ŸŽจ Draw โ€” paint the new picture on the screen.

Then it loops back to the start and does it all over again. That cycle is called the game loop. Watch it spin:

๐Ÿ‘‚LISTEN
โ†’
๐ŸƒMOVE
โ†’
๐ŸŽจDRAW
โ†ป
โ€ฆand repeat!

LISTEN: Which keys are pressed right now?

loops finished: 0

Donkey Kong, Minecraft, every game you've ever played runs a loop like this. ๐ŸŽฎ

2

Your turn: become the rule-maker

Here's a real game loop, running live. The little red hero is you. The barrel rolls like in Donkey Kong.

On the right are the game's rulesโ€” gravity, jump power, speed. They're just numbers, and youget to change them. That's the whole secret: code is rules you can change.

Click the game, then use โ† โ†’ to move and โ†‘ / Space to jump. Try Slo-mo or Step once to watch the loop tick.

๐ŸŽ›๏ธ The Rules

These are the game's rules. Drag them and watch what happens!

๐ŸŒ Gravity0.8

How hard the ground pulls you down

๐Ÿฆ˜ Jump Power14

How hard you push off the ground

๐Ÿƒ Move Speed5

How fast you run left and right

live readout:tick!
x: 60
y: 292
vy: 0 (โ†“ gravity adds each tick)
on ground: yes
loop #0
โ–ธ๐Ÿ”ง Peek inside: those sliders are โ€œvariablesโ€

Gravity, jump, and speed are variables โ€” think of each one as a little named boxthat holds a number. The game doesn't know โ€œ0.8โ€; it knows โ€œlook in the box called gravity.โ€ When you drag a slider, you're just putting a new number in the box, and the loop reads it on the very next tick. Almost everything a game remembers โ€” your score, your health, where you're standing โ€” lives in a named box like this.

3

Discovery missions

Real scientists learn by experimenting. Try each mission in the lab above, tick it off, then peek at the secret to find out why it happened.

0/5
  • ๐ŸŒ™Drag Gravity down to 0, then jump. Where do you come back down?

  • ๐ŸชจNow crank Gravity all the way UP and try to jump.

  • ๐Ÿฆ˜Make Gravity tiny and Jump Power huge โ€” then sail over the barrel.

  • ๐Ÿ‘€Jump and watch the vy number in the readout as you go up and come down.

  • ๐Ÿ‘ฃPress Pause, then tap โ€œStep onceโ€ a bunch of times. Watch loop #.

๐ŸŒŸ You leveled up! You now know:

๐ŸŽฌ Behind the scenes โ€” what's next?

Did you notice the x and y numbers in the lab? Those tell the game whereyour hero is. But what ARE they, really? And how does Minecraft keep track of where millions of blocks sit? That's our next adventure. ๐Ÿ‘‡

๐ŸงญNext stop ยท Lesson 2Coordinates & the World โ†’X, Y, Z โ€” how Minecraft knows where every block is, and how your hero knows where to stand.
โ† Back to the map