Lesson plan

Game dev on microcontrollers lesson plan

Write a space platformer in C++ on an ESP32-C3 with a tiny OLED, three buttons and a piezo: game loop, sprites, input, collision, gravity and sound, one idea at a time.

4 chapters, 7 lessons, about 5 hours, on the ESP32-C3-DevKitM-1. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • A steady frame rate and sprites stored as bytes.
  • Buttons read like a game reads them, and boxes that touch.
  • Fixed-point gravity and sound effects that never freeze the game.
  • Everything in one platformer, then a level of your own.

Materials for the whole unit

  • ESP32-C3-DevKitM-1
  • Full-size breadboard
  • OLED display, 128x64
  • Piezo speaker
  • Pushbutton x 3

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 40 min

Loop and pictures

A steady frame rate and sprites stored as bytes.

LessonTimeWhat students do
The game loopRead, update, draw, wait: a parallax starfield at a fixed 25 frames a second, a frame budget you can measure, and what happens when the work outgrows it.50 min
  1. One loop, forever
  2. A steady beat
  3. Where the time goes
  4. Ask for 50
  5. Fit the budget
Sprites and framesAn 8x8 astronaut stored as eight bytes, a two-frame walk cycle, a mirrored turn that costs no memory, and erasing exactly what you drew.50 min
  1. A picture in eight bytes
  2. Two frames make a walk
  3. Turn around for free
  4. Redraw the helmet
  5. Walk faster

Materials

  • ESP32-C3-DevKitM-1
  • Full-size breadboard
  • OLED display, 128x64
  • Piezo speaker
  • Pushbutton x 3

Check for understanding

Each student finishes "Sprites and frames" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Walk faster".

Chapter 2. About 1 h 20 min

Make it playable

Buttons read like a game reads them, and boxes that touch.

LessonTimeWhat students do
InputThree buttons read once a frame into a snapshot: held for walking, pressed for jumping, and why reading once a frame also tames contact bounce.40 min
  1. Hold right
  2. Held versus pressed
  3. Bouncing contacts
  4. Walk speed
CollisionAxis-aligned boxes and four comparisons: collect crystals, stop at a boulder by undoing the move, and tune a hitbox until the game feels fair.40 min
  1. Four comparisons
  2. Collect a crystal
  3. A solid boulder
  4. Tune the hitbox

Materials

  • ESP32-C3-DevKitM-1
  • Full-size breadboard
  • OLED display, 128x64
  • Piezo speaker
  • Pushbutton x 3

Check for understanding

Each student finishes "Collision" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Tune the hitbox".

Chapter 3. About 1 h 20 min

Physics and sound

Fixed-point gravity and sound effects that never freeze the game.

LessonTimeWhat students do
GravityVelocity, acceleration and sixteenths of a pixel: a jump that is a true parabola, moon gravity in one constant, and landing on a ledge from above.40 min
  1. Speed changes place, gravity changes speed
  2. Why fixed point
  3. Moon gravity
  4. Land on the ledge
Sound effectsA piezo, tone() and note tables: a start jingle, a rising jump and a crystal chime, played from the game loop by priority without ever freezing the game.40 min
  1. A jingle from a table
  2. A player that never waits
  3. Priorities
  4. Design your jump

Materials

  • ESP32-C3-DevKitM-1
  • Full-size breadboard
  • OLED display, 128x64
  • Piezo speaker
  • Pushbutton x 3

Check for understanding

Each student finishes "Sound effects" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Design your jump".

Chapter 4. About 50 min

Boss

Everything in one platformer, then a level of your own.

LessonTimeWhat students do
Boss: a platformerEverything in one game: three crystals on the moon, floating rocks, a crater that costs a life and a portal that opens when you have them all. Then make it yours.50 min
  1. The whole course in one loop
  2. Mind the crater
  3. Clear the level
  4. More lives
  5. Make it yours

Materials

  • ESP32-C3-DevKitM-1
  • Full-size breadboard
  • OLED display, 128x64
  • Piezo speaker
  • Pushbutton x 3

Check for understanding

Each student finishes "Boss: a platformer" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".

Your class

Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.