← Games with microStudio

Games with microStudio: recap

For after the lessons: one card per lesson, to check what you remember. Answer each question in your head or on paper first, then check it. Nothing here is marked.

The game loop

1. A game loop

Try firstWhy does draw() start with screen.clear(...)?

Check your answer

draw() runs 60 times a second; without clearing, every old picture of the dot would stay, making a smear.

  1. init() runs once at the start: set up your variables there.
  2. update() runs 60 times a second: change the variables (with global).
  3. draw() runs after each update: clear the screen and draw everything where it is now.
init once, then update and draw 60 times a second · Sound on for the voiceover
Open the lesson →

2. Keys and movement

Try firstWhy does the paddle stop when you let go of the key?

Check your answer

Each frame update() asks whether the key is down; when it is not, px is not changed, so the paddle stays where it is.

  1. Every frame, update() asks if pressed("LEFT") and moves a little if the key is down.
  2. Hold the key and it moves 60 times a second; let go and it stops.
  3. An if after the move keeps it on the screen.
Open the lesson →

A whole game

3. Stars as objects

Try firstWhy does each star have self.x and self.y?

Check your answer

So that each star remembers where it is; draw() paints it there and move() changes it, for that star only.

  1. Each Star keeps its own self.x, self.y and self.speed.
  2. move() changes them; draw() paints the star where it is now.
  3. update() and draw() loop over the list and ask each star to do its part.
Each star moves itself and draws itself · Sound on for the voiceover
Open the lesson →

4. Catch and score

Try firstWhy does a caught star call restart()?

Check your answer

Otherwise it is still touching the paddle next frame and scores again, 60 times a second.

  1. Every frame, each star asks touches(px, -80): close enough across and up and down.
  2. A caught star adds to the score (score += 1) and starts again at the top.
  3. Lives count misses; at 0, update() stops and draw() shows GAME OVER.
A star that touches the paddle scores · Sound on for the voiceover
Open the lesson →

5. Make it yours

Try firstWhy does a catch sound go in update() and not in draw()?

Check your answer

It should play once, when the catch happens; draw() runs every frame, so a sound there would repeat 60 times a second.

  1. audio.beep("C E G") plays notes; put it in update(), where the thing happens.
  2. Draw sprites in microStudio's Sprites tab, then screen.drawSprite("star", x, y, w, h) replaces a shape.
  3. Before publishing: a nickname only, no name, school or photos, and ask your teacher.
Open the lesson →