Get your API key

Lesson 1 of 6

What a game is made of: five parts

Screen, loop, input, rules and a way to win or lose. Why the loop runs sixty times every second, and why that number changes your code.

7 min Free
One step at a time, like flipping pages.

By the end of this lesson you will be able to name the five parts that every game has, and you will know why the speed of a moving object depends on one of them.

You need: a coding agent connected to AllModelAPI, and a browser · Time: 7 minutes

  1. A game can look complicated, but underneath, every game that runs in a browser is made of the same five parts. Once you can see them, you stop feeling lost in someone else's code and you can ask for exactly the part you want.

    1. The screen. This is the drawing area inside the web page. The player sees nothing except what is drawn here.
    2. The loop. This is one small block of code that the browser runs again and again, many times every second. Each round of that block is called a frame. A frame is one complete drawing of the game.
    3. The input. This is what the player does: presses an arrow key, clicks the mouse, or taps the screen with a finger.
    4. The rules. These are the checks that decide what happens when two things on the screen touch each other. In a game where a basket catches falling mangoes, the rule is: when the basket and a mango overlap, the mango disappears and the score goes up by one.
    5. The result. This is how the player wins, loses, or starts again. Without it, the player is only watching things move.
    Why?

    When a beginner asks an agent for "a game", the agent has to invent all five parts. When you name the five parts yourself, you are not asking for a game any more. You are asking for five small things that you can check one at a time.