Lessons and the learning game

Build a handheld RPG

An original role playing game on an Uno with a color screen, a thumb stick and a piezo: tile maps, a hero, dialogue, battles, saves and music.

This course is about the game. For the console itself on an ESP32-C3 (the screen, the pad and a menu), see Build a handheld game console.

The handheld

Every lesson opens on the same wiring:

  • The screen: a 2.4 inch ILI9341 color TFT, 240 by 320, on CS 10, DC 9, SCK 13 and MOSI 11.
  • The controls: a thumb stick on A0 and A1, with its press on pin 2.
  • The sound: a piezo on pin 6.
  • The saves: the Uno's own 1 KB of EEPROM. No card needed.

The game

Emberfold is a village by a river. Fog rolls out of a cave east of the meadow, and Wren, the lamplighter's apprentice, has to find out why.

The tile map. The world is ten lines of ten characters in flash: T for a tree, ~ water, , tall grass, = the bridge, E the elder, S the ember stone, C the cave. Each tile is drawn as a few rectangles, the whole map once, and after that only the tiles that change. Collision is one question: is the tile ahead walkable?

Dialogue. Lines live in flash, are drawn into a panel under the map a word at a time with word wrap, and wait for a press. Talking to the elder sets a flag, the lantern, and the flag opens the cave.

Battles. Every third step on tall grass brings a Mossling or a Glimmerbat. Battles are turn based: FIGHT, GUARD or RUN on the stick. Damage is attack less half the defense, plus a roll of 0 to 2, never less than 1. Ten experience points take Wren to level 2, and the Fog Warden (24 HP, attack 6, defense 3) is balanced so a level 2 Wren always wins in four hits.

Saves. The ember stone heals Wren and saves an 18 byte struct to EEPROM: a magic number, a version, the whole hero and a checksum. After a reset, she is back at the stone.

Music. A world theme, a battle loop and a victory jingle, as notes in flash played with tone() a note at a time, so the game never waits for the music.

The course

Build a handheld RPG gets there in seven lessons, each a sketch on the same wiring:

  1. Tile maps: a world from characters, and a frame to inspect it.
  2. A hero: walking, collisions and facing.
  3. Dialogue: words in flash, word wrap and a story flag.
  4. Battles: encounters, a menu, damage, level ups and a boss.
  5. Save games: EEPROM, a magic number and a checksum.
  6. Music: tunes that play while the game runs.
  7. Project: a short quest: the whole game, an ending and a score, then your own world.

Every step but two is checked against the running game.