35. Top-Down RPG Part 3: NPCs, Dialogue and Items

After chapter 34 the RPG has a world: three maps, doors with fades, chests that stay open, and a World that remembers what has to survive a map change.
But nobody lives in it.
This chapter adds the people and the reason to walk around: villagers who stroll and turn to face you, a dialogue box with typewriter text, items and an inventory, and a small quest that changes the map when you solve it.

Most of the work is text.
The game is bilingual, so every sentence exists in Japanese and English and is laid out at display time, with line breaking that follows the rules of each language.
The conversations aren't C++ but a small script file that the game reads, checks and runs.
And the game needs kanji that the shared font from chapter 26 doesn't have, so it gets its own atlas.
There are no new OpenGL functions in this chapter: the text is ordinary sprites in the SpriteBatch, and the hard parts are layout, data and game state.

35.1 What we're building

The game now starts on a title screen, where you choose the language:

Two title screens side by side. Left: the Japanese title 薬草と古い鍵 at double size with the English subtitle below it, and 日本語 selected. Right: The Herb and the Old Key on two lines with the Japanese subtitle, and English selected. Both show a row of trees, grass and the five characters walking on the spot

The first clip goes from the title into the village and talks to the elder, who asks for a healing herb and offers a yes/no choice:

The second one plays the whole quest: accept, open the chest with the apple, walk to the field, pick up the herb, bring it back, get the old key, unlock the garden gate, take the sword from the chest behind it, and look at the inventory in Japanese and then, after L, in English:

The controls:

  • Title: ← and → (or L) choose the language, Space or Enter starts, Esc quits
  • Map: arrow keys or W, A, S, D walk, Shift runs, Space or Enter talks, checks or opens what is in front of you, I opens the inventory, L switches between Japanese and English, the debug keys 1 2 3 B Z H R work as before, Esc quits
  • Dialogue: Space or Enter shows the rest of a page that is still typing, or goes to the next page; ↑ and ↓ choose an answer; L switches the language
  • Inventory: ↑ and ↓ select, L switches the language, I or Esc closes it

Starting from chapter 34, the changes are all inside games/rpg/:

  • src/text.hh, src/text.cc (new): Language, the bilingual Text, splitPair, word wrapping with kinsoku, and two UTF-8 helpers for the typewriter
  • src/dialogue.hh, src/dialogue.cc (new): the dialogue script (DialogueScript, loaded and checked at start-up) and its interpreter (DialogueRunner)
  • src/dialogue_scene.cc (new): DialogueScene, the dialogue box overlay
  • src/items.hh, src/items.cc (new): ItemKind and ItemTable, read from items.txt
  • src/npc.hh, src/npc.cc (new): Npc, the villagers
  • src/inventory_scene.cc, src/title_scene.cc (new): the inventory overlay and the title
  • src/world.hh, src/world.cc: the inventory, clearFlag and the current language
  • src/game.hh, src/map_scene.cc, src/main.cc: NPCs, pickups, conditional objects, the new scenes, the game font
  • assets/dialogue.txt, assets/items.txt (new, written by hand), assets/items.png and .atlas (new), assets/fonts/pixel12.png and .fnt (new), the three maps, LICENSE.txt and README.md (the finished files are in the chapter's ZIP and in ch35/ of the assets ZIP)

The seven new sources go into the game's CMakeLists.txt:

# 見下ろし型RPG(第33〜35章) / the top-down RPG (chapters 33-35)
add_executable(rpg
  src/main.cc
  src/tilemap.cc
  src/tile_renderer.cc
  src/character.cc
  src/map_scene.cc
  src/world.cc
  src/text.cc
  src/dialogue.cc
  src/items.cc
  src/npc.cc
  src/dialogue_scene.cc
  src/inventory_scene.cc
  src/title_scene.cc)
target_include_directories(rpg PRIVATE src)
target_link_libraries(rpg PRIVATE engine)
enable_warnings(rpg)
set_working_directory(rpg)

As always, the program is rpg and runs from the project root: ./build/games/rpg/rpg on Linux and FreeBSD, or the rpg startup project in Visual Studio.

35.2 Two languages everywhere

Text

Every piece of text the player reads comes from data: a page of dialogue, a speaker's name, an answer, an item's name and description, a map's title.
All of them have the same type:

enum class Language { Ja, En };

// 同じ文の日本語と英語。ゲームのデータ(会話・持ち物の名前)はみなこの形 / the same text in Japanese and English;
// all game data (dialogue, item names) has this form
struct Text {
  std::string ja, en;
  const std::string &get(Language l) const { return l == Language::Ja || en.empty() ? ja : en; }
};

// "日本語 | English" を分ける(| がなければ両方同じ) / splits "日本語 | English" (both the same without a |)
Text splitPair(std::string_view s);

A Text holds both translations at once, and the language is chosen only when something is drawn.
That's the key decision of this chapter.
The alternative, loading only the current language, would mean reloading every file and rebuilding every open screen when the player presses L.
With both strings in memory, switching is one assignment: the next frame simply picks the other string.
The cost is a few kilobytes of text that is never shown.

The language itself is game state, so it lives in World next to the flags and the gold, where chapter 34 put everything that must survive a scene change: Language language = Language::Ja;.
Scenes ask Game for the right string:

  // 今の言語で / in the current language
  const std::string &tr(const Text &t) const { return t.get(world.language); }

tr is the traditional name for "translate" in many UI toolkits.
It returns a reference into the Text it is given, which costs nothing but lives only as long as that Text.
The map's title banner makes its Text on the spot, splitPair(map->title()), a temporary that is destroyed at the end of the statement, so the banner keeps a copy: std::string title = g.tr(splitPair(map->title()));.
Binding that result to a const std::string & compiles without a warning and then reads a dead object; AddressSanitizer reports it as a stack-use-after-scope.
Short pairs are written on one line in the data files as 日本語 | English and split by splitPair: map titles (title 村 | Village), speaker names, answers, item names.
Long sentences get one line per language, which is easier to read and to compare in a diff (we'll see that in 35.6).

The title, the map, the dialogue box and the inventory each react to L by flipping g.world.language.
The map banner, the HUD's language indicator and the item names change in the same frame; the dialogue box also has to wrap its page again, because a Japanese and an English sentence break into lines in completely different places.

The title scene

TitleScene is drawn from what the game already has: a sky made of two drawRects, a row of trees and grass from the village tileset, and the five characters of characters.png walking on the spot.
The title is pixel12 at scale 2, which is still crisp because 2 is an integer; the English title needs two lines at that size, because "The Herb and the Old Key" is 24 characters × 7 px × 2 = 336 px, wider than the 320 px canvas.
← → (or L) flips the language, and Space replaces the title with the village map scene, with a 1 s fade.

35.3 The game's own font

Chapter 26 gave the engine two atlases with 554 glyphs each: ASCII, kana, punctuation and 252 kanji picked for game UI.
It also set a rule: a game that needs more kanji generates its own atlas in its own folder and leaves assets/fonts/ alone.
The RPG's dialogue is the first text in this series that is real prose rather than labels, and its sentences need words like 腰 (back), 痛 (pain), 野原 (field), 池 (pond), 庭 (garden) and 柵 (fence).

So the game has games/rpg/assets/fonts/pixel12.png and .fnt, the shared pixel12 plus what the game's text uses:

The game&

The atlas is made by a new generator script of mine, which, like every asset script in this series, isn't part of the download; here is what it does.
It collects every character the game can display: the non-comment lines of dialogue.txt and items.txt, the title lines of the maps, and the string literals of games/rpg/src/*.cc (string literals only, so the kanji in the comments don't count).
It removes the characters the shared atlas already has and hands the rest as extra characters to the same generator as chapter 26's atlases, which renders the standard set plus those characters at 12 px, 1-bit, with the same metrics as the shared pixel12.
The result has 603 glyphs: the shared 554 plus 49 extra, 47 of them kanji and two the arrows ← and → that the title's help line uses.
They still fit into 512 × 256, the size of the shared atlas.

Because the script scans the sources, a few characters that only appear in error messages on stderr (幅, 直 and 印, for example) end up in the atlas too.
That's harmless: a few spare cells.
The opposite mistake is the one that matters: if you write a kanji into dialogue.txt that isn't in the atlas, the engine draws ? and prints character not in the font: U+XXXX once, as chapter 26 designed it, so the problem shows up in the first test run.
To use new kanji in your own lines, take the big version in extras/jis-level1-fonts/ of the assets ZIP: a pixel12 with all 2 965 JIS level-1 kanji plus kana, punctuation and full-width letters and digits, 3 443 glyphs.
It's made with the same generator from the same fonts, so today's 603 glyphs are identical pixel for pixel and the metrics (line height 16, baseline 12) are the same.
Replace games/rpg/assets/fonts/pixel12.png and .fnt with it, and you can write any common Japanese.
The atlas grows to 1024 × 1024 (4 MiB), which doesn't matter for this game.
The game's README says the same.

main loads the game's font in place of the shared one, with TextureFilter::Nearest because it's 1-bit pixel art:

  std::optional<Font> pixel = Font::load("games/rpg/assets/fonts/pixel12.fnt", TextureFilter::Nearest);

Everything drawn inside the 320 × 180 canvas uses it at scale 1 (scale 2 for the title): the dialogue, the menus, the banners.
The debug HUD on the 1280 × 720 UI layer keeps the shared mono16, whose strings stay inside the shared character set.
The license notices of DejaVu Sans Mono and Noto Sans CJK JP come along with the glyphs, so games/rpg/assets/LICENSE.txt repeats them, as assets/LICENSE.txt does.

35.4 Wrapping English and Japanese

Two different rules

The dialogue box has room for 292 px of text per line.
In pixel12 every Latin character, including the space, is 7 px wide, and every Japanese character is 12 px wide, so a line holds at most 41 Latin characters (41 × 7 = 287) or 24 Japanese ones (24 × 12 = 288).
The pages are much longer than one line, so the game has to decide where lines break.

English is written with spaces between words, and a line may break only at a space.
The space at the break disappears; nobody wants a line that starts with a blank.

Japanese has no spaces.
A sentence such as 「お礼にこの古い鍵をやろう。」 is one unbroken run of characters, and a line may break between almost any two of them.
"Almost", because Japanese typesetting has a set of rules called kinsoku shori (禁則処理, roughly "prohibition processing"):

  • 行頭禁則, characters that must not start a line: closing punctuation such as 。 (full stop), 、 (comma), !?, closing brackets 」』), the long vowel mark ー, the ellipsis …, and the small kana ぁぃぅぇぉっゃゅょ (and their katakana forms), which belong to the character before them in pronunciation.
  • 行末禁則, characters that must not end a line: opening brackets such as 「『(.

For English readers the closest thing is the rule that a comma or a full stop never begins a line, and a quotation mark never dangles alone at the end of one; in Japanese, where any character boundary is a possible break, the rule has to be explicit.
When the natural break would put a forbidden character at the start of a line, there are three classic fixes:

  • Push-out (追い出し, oidashi): move the character before the forbidden one to the next line too, so the pair starts the new line together. The first line becomes a little shorter.
  • Push-in (追い込み, oikomi): squeeze the forbidden character into the current line by tightening the spacing a little. Needs variable spacing.
  • Hanging punctuation (ぶら下げ, burasage): let the punctuation mark stick out past the right margin. Common in Japanese newspapers and books.

Here is the real line from the elder's dialogue that triggers it:

Three versions of the same Japanese line, each character in a 12 px cell, with the 292 px margin dashed. No rule: 24 characters fit, and the full stop would start line 2, crossed out as not allowed. Push-out, what wrapText does: the line stops after 23 characters, 276 px, and よ moves down together with the full stop. Hanging, challenge 3: all 25 characters stay on one line and the full stop hangs 8 px past the margin

「お礼にこの古い鍵をやろう。野原の庭の門の鍵じゃよ。」 is 25 characters, 300 px.
After 23 characters (276 px) there is room for one more 12 px character (288 px), so a naive wrapper would put よ on the first line and start the second line with 。.
Our wrapper uses push-out: よ and 。 move to the second line together.
Push-in isn't possible with a monospaced pixel font, and hanging is a one-line change that challenge 3 tries.
The game implements the line-start rule; the line-end rule for opening brackets is left to challenge 4, because none of the game's sentences has a bracket in the middle of a line.

The same idea is standardized for software as the Unicode line breaking algorithm (UAX #14), which classifies every character by what may come before and after it; browsers and word processors use it.
Our version is a small subset, which is all a game with hand-written text needs.

Units

wrapText first cuts the string into units, pieces that are never split:

// 折り返しの単位:英語の一語、空白一つ、日本語の一文字、改行。行頭禁則の文字は前の単位にくっつける
// Units of wrapping: an English word, one space, one CJK character, a newline. Kinsoku characters stick to the unit
// before them
struct Unit {
  std::string bytes;
  float width = 0.0f;
  enum Kind { Word, Space, Newline } kind = Word;
};

static std::vector<Unit> units(const Font &font, std::string_view text) {
  std::vector<Unit> out;
  bool inWord = false; // 英語の語の途中 / inside an English word
  size_t i = 0;
  while (i < text.size()) {
    size_t start = i;
    char32_t c = decodeUtf8(text, i);
    std::string_view bytes = text.substr(start, i - start);
    float w = advanceOf(font, c);
    if (c == U'\n') {
      out.push_back({"", 0.0f, Unit::Newline});
      inWord = false;
    } else if (c == U' ') {
      out.push_back({" ", w, Unit::Space});
      inWord = false;
    } else if (noLineStart(c) && !out.empty() && out.back().kind == Unit::Word) {
      out.back().bytes += bytes; // 「。」は前の文字と一緒に動く(追い出し) / 。 moves with the character before it
      out.back().width += w;
    } else if (isCjkOrFullWidth(c)) {
      out.push_back({std::string(bytes), w, Unit::Word});
      inWord = false;
    } else if (inWord) {
      out.back().bytes += bytes;
      out.back().width += w;
    } else {
      out.push_back({std::string(bytes), w, Unit::Word});
      inWord = true;
    }
  }
  return out;
}

A Latin character joins the current word; a space or a CJK character ends it.
Every CJK character is a unit of its own, which is exactly "a break is allowed between any two characters".
The kinsoku rule is the third branch: a character that must not start a line is appended to the unit before it, so the two can only move together, and push-out falls out of the data structure without any special case in the line filling.
"CJK" here means U+3000 to U+9FFF (CJK punctuation, hiragana, katakana, the unified kanji) and U+FF00 to U+FFEF (full-width forms such as ! and ?).
The width of each unit comes from the font, Font::glyph(c)->advance, so the wrapper works with any atlas.

The list of forbidden line starts is a switch, which also covers English punctuation, so that "the east," never leaves its comma behind:

// 行の頭に来てはいけない文字(行頭禁則) / characters that must not start a line (kinsoku)
static bool noLineStart(char32_t c) {
  switch (c) {
  case U'。': case U'、': case U'!': case U'?': case U'」': case U'』': case U')': case U'ー': case U'…':
  case U'ぁ': case U'ぃ': case U'ぅ': case U'ぇ': case U'ぉ': case U'っ': case U'ゃ': case U'ゅ': case U'ょ':
  case U'ァ': case U'ィ': case U'ゥ': case U'ェ': case U'ォ': case U'ッ': case U'ャ': case U'ュ': case U'ョ':
  case U'.': case U',': case U'!': case U'?': case U')': case U':': case U';':
    return true;
  default:
    return false;
  }
}

These are char32_t literals (U'。'), so the comparison is against decoded code points, not bytes.
That's also why the sources have to reach the compiler as UTF-8 (35.11).

Filling lines

With units, the line filling is greedy: put units on the line until the next one doesn't fit.

std::vector<std::string> wrapText(const Font &font, std::string_view text, float maxWidth) {
  std::vector<std::string> lines(1);
  float width = 0.0f;
  bool pendingSpace = false; // 行の途中の空白は、次の語が同じ行に入るときだけ書く / a space is written only if the
                             // next word stays on the same line
  float spaceWidth = advanceOf(font, U' ');
  for (const Unit &u : units(font, text)) {
    if (u.kind == Unit::Newline) {
      lines.emplace_back();
      width = 0.0f;
      pendingSpace = false;
      continue;
    }
    if (u.kind == Unit::Space) {
      pendingSpace = !lines.back().empty();
      continue;
    }
    float needed = u.width + (pendingSpace ? spaceWidth : 0.0f);
    if (width + needed > maxWidth && !lines.back().empty()) {
      lines.emplace_back(); // 次の行へ(空白は捨てる) / to the next line (the space is dropped)
      width = 0.0f;
      pendingSpace = false;
    }
    if (pendingSpace) {
      lines.back() += ' ';
      width += spaceWidth;
      pendingSpace = false;
    }
    if (u.width <= maxWidth || !lines.back().empty()) {
      lines.back() += u.bytes;
      width += u.width;
      continue;
    }
    // 一語だけで行より長い:文字ごとに切る / one word longer than a line: cut it character by character
    size_t i = 0;
    while (i < u.bytes.size()) {
      size_t start = i;
      char32_t c = decodeUtf8(u.bytes, i);
      float w = advanceOf(font, c);
      if (width + w > maxWidth && !lines.back().empty()) {
        lines.emplace_back();
        width = 0.0f;
      }
      lines.back() += u.bytes.substr(start, i - start);
      width += w;
    }
  }
  return lines;
}

The only subtle part is the space.
A space isn't written when it's read; it's remembered (pendingSpace) and written in front of the next word only if that word stays on the same line.
So a line never ends or starts with a space, and several spaces in a row collapse into one.
In the Japanese pages the full-width style puts a half-width space after ! (「ありがたい! 薬草は…」), which gets the same treatment.
A single word wider than the line (a long URL, say) can't be broken at a space, so as a last resort it is cut between characters.

The wrapping is greedy, which is what nearly every game and terminal does.
Typesetting programs such as TeX instead choose the breaks of the whole paragraph at once, to make the lines' lengths as even as possible (the Knuth–Plass algorithm); for three lines of game dialogue that's not worth the trouble.

Here is the dialogue box with the push-out and an English page:

Two crops of the dialogue box. Left, labeled kinsoku: the first line ends with 門の鍵じゃ and the second line is よ。. Right, labeled English breaks at spaces: You see, I have hurt my back. With a / healing herb from the field to the east, / I could make a good medicine...

The English lines are 252, 280 and 217 px wide.
"healing" would make the first one 252 + 7 + 49 = 308 px, so it goes down; the comma after "east" is part of that word anyway.

Counting characters, not bytes

The typewriter shows a page character by character, so it needs "the first n characters" of a string.
In UTF-8 that's not substr(0, n): an ASCII letter is 1 byte, a kana or kanji 3 bytes, and cutting in the middle of a character produces broken bytes that the font decodes as U+FFFD (chapter 26).
Two small helpers walk the string with the engine's decodeUtf8:

size_t charCount(std::string_view utf8) {
  size_t i = 0, n = 0;
  while (i < utf8.size()) {
    decodeUtf8(utf8, i);
    ++n;
  }
  return n;
}

std::string firstChars(std::string_view utf8, size_t n) {
  size_t i = 0;
  while (i < utf8.size() && n > 0) {
    decodeUtf8(utf8, i);
    --n;
  }
  return std::string(utf8.substr(0, i));
}

The elder's second page, 「実は腰を痛めてしまってな。東の野原に生える薬草があれば、よく効く薬が作れるんじゃが……。」, is 44 characters and 132 bytes.
Strictly speaking these count code points, which is what a person would call a character in both of our languages; scripts with combining marks or emoji sequences need grapheme clusters instead, a topic for a text-shaping library.

35.5 The dialogue box

An overlay scene

Talking pushes a DialogueScene on top of the map, without a fade:

void MapScene::talk(const std::string &label) {
  printf("%s: 会話 / talk @%s\n", mapName.c_str(), label.c_str());
  scenes().push(std::make_unique<DialogueScene>(g, label)); // フェードなし、上に重ねる / no fade, an overlay
}

This is chapter 26's overlay mechanism, the same one the demo used for its pause menu.
isOverlay() returns true, so the map below is still drawn, but only the top scene is updated: while a conversation is open the villagers freeze, the hero can't walk, and the typewriter gets every key press.
That's what a modal dialogue should do, and we get it from the scene stack for free.
The map's pause() sets every previous position to the current one, as chapter 26 taught, so the frozen picture doesn't shake with the interpolation, and it sets a covered flag that hides the 1280 × 720 HUD bars, which would otherwise be drawn over the bottom of the box (the UI pass comes after the canvas).
When the conversation ends, the dialogue scene pops itself and the map's resume() runs; we'll see in 35.9 why that matters for the quest.

The dialogue box is drawn inside the 320 × 180 canvas with pixel12 at scale 1, so its text sits on the same pixel grid as the art and is scaled ×4 with it:

The 320 by 180 canvas at twice its size. At the bottom the box kBox, 308 by 56 at x 6 and y 120, holds three dashed text lines of 16 px at y 124, 140 and 156; the text is 292 px wide, from x 14 to 306. Above the box&

The box is 308 × 56 at (6, 120), the text starts 8 px inside it, and 3 lines of pixel12's 16 px line height fit with 4 px of margin above and below.
The speaker's name sits in a small tag that overlaps the top edge, the "next" marker blinks in the lower right corner, and a question's answers appear in a second box above the right end.
All of them are drawRect, drawRectOutline and Font::draw calls on the SpriteBatch: one begin/end for the whole dialogue.

Layout: wrap once, show in chunks

When a page arrives (or the language changes), the scene wraps it and cuts the lines into chunks of three:

void DialogueScene::layout() {
  // ページを今の言語で折り返し、3行ずつのかたまりにする。長いページは自動で何回かに分かれる
  // Wrap the page in the current language and cut it into chunks of 3 lines: a long page is split automatically
  std::vector<std::string> lines = wrapText(g.pixel, g.tr(runner.page().text), kTextWidth);
  chunks.clear();
  for (size_t i = 0; i < lines.size(); i += kLines)
    chunks.emplace_back(lines.begin() + static_cast<std::ptrdiff_t>(i),
                        lines.begin() + static_cast<std::ptrdiff_t>(std::min(lines.size(), i + kLines)));
  chunk = 0;
  shown = 0.0f;
  choice = 0;
  total = 0;
  for (const std::string &l : chunks[0]) total += charCount(l);
}

A writer doesn't have to count lines: a page that wraps to more than three is shown in several steps automatically.
In the shipped script that never happens, as it turns out: the longest pages are the elder's two English sentences of 109 and 90 characters, which fill exactly three lines.
The other benefit of wrapping at display time is that the data stays free of layout.
A translator writes one sentence per page and never inserts line breaks by hand, and a bigger font or a wider box changes nothing in dialogue.txt.

The typewriter

shown is the number of characters on screen, as a float, because it grows by speed × dt every update:

void DialogueScene::update(float dt) {
  time += dt;
  if (done) {
    scenes().pop();
    return;
  }
  Input &in = g.input;
  if (in.pressed(GLFW_KEY_L)) {
    // 言語を変えたら折り返し直す(今のページを最初から全部見せる) / a language change re-wraps the page (shown in full
    // from its first chunk)
    g.world.language = g.world.language == Language::Ja ? Language::En : Language::Ja;
    layout();
    shown = static_cast<float>(total);
    return;
  }
  // 文字の速さ:日本語は1文字に情報が多いのでゆっくり / typing speed: slower for Japanese (more per character)
  float speed = g.world.language == Language::Ja ? 30.0f : 60.0f;
  shown = std::min(static_cast<float>(total), shown + speed * dt);

  if (showingChoices()) {
    int n = static_cast<int>(runner.page().choices.size());
    if (in.actionPressed("up")) choice = (choice + n - 1) % n;
    if (in.actionPressed("down")) choice = (choice + 1) % n;
  }
  if (!in.actionPressed("confirm")) return;
  if (shown < static_cast<float>(total)) {
    shown = static_cast<float>(total); // 途中なら全部出す / still typing: show everything
    return;
  }
  if (!lastChunk()) {
    ++chunk; // 同じページの次の3行 / the next 3 lines of the same page
    shown = 0.0f;
    total = 0;
    for (const std::string &l : chunks[chunk]) total += charCount(l);
    return;
  }
  // 次のページへ(選択肢があれば、選んだ会話へ飛んで) / to the next page (jumping to the chosen conversation, if
  // there are options)
  bool more = runner.page().choices.empty() ? runner.next() : runner.choose(static_cast<size_t>(choice));
  if (!more) {
    done = true;
    scenes().pop();
    return;
  }
  layout();
}

The speeds are a design choice: 30 characters per second for Japanese and 60 for English.
A Japanese character carries much more than a Latin letter (古い鍵 is "old key"), so at the same rate Japanese would feel rushed and English sluggish.
In time, the two languages end up close: the elder's second page takes 44 / 30 ≈ 1.47 s in Japanese and 109 / 60 ≈ 1.82 s in English.
Because GameLoop runs updates at a fixed 60 Hz, the typewriter advances exactly half a character per update in Japanese and one in English, on every machine.

Confirm does one of three things, in this order: reveal the rest of a page that is still typing (impatient players are the majority), show the next chunk of the same page, or ask the script for the next page.
That order is also why a scripted run has to wait for the typewriter: a press that comes too early only reveals the page.
L switches the language, wraps the page again and shows it in full, from its first chunk; after a language change the reader wants to read the page, not watch it type again.

Drawing uses the same count: each line gets as many characters as are left of shown:

  // 出した文字の数だけ、行ごとに描く / draw line by line, only as many characters as have been shown
  size_t left = static_cast<size_t>(shown);
  float y = kBox.y + 4.0f;
  for (const std::string &line : chunks[chunk]) {
    size_t n = std::min(left, charCount(line));
    g.pixel.draw(b, firstChars(line, n), {kBox.x + 8.0f, y}, {.color = hexColor(0xfff4d6ff)});
    left -= n;
    y += kLineHeight;
  }

Because the page was wrapped before typing starts, a word never jumps to the next line halfway through being typed, which is a classic bug of typewriters that wrap as they go.

When everything is shown, a small triangle blinks in the corner: three drawRects of 5, 3 and 1 px, bobbing by a pixel with sin.
On the last chunk of a question it's replaced by the answers, with > in front of the selected one:

Four frames of the dialogue in the village square. The elder&

35.6 Dialogue as data: a tiny script language

Why not C++

The obvious first version of "the elder says something" is code: if (talkingTo == "elder" && world.flag("quest_done")) ….
It works for one character and gets unreadable at three, and it puts the story in the place where neither a writer nor a translator can touch it without a compiler.
So the conversations are a text file, games/rpg/assets/dialogue.txt, and the game contains a small interpreter for it.
The format is described at the top of dialogue.hh:

// 書式(games/rpg/assets/dialogue.txt) / format:
//   @<label>                      ここから一つの会話(次の@で終わる) / a conversation starts here (ends at the next @)
//   name <日本語> | <English>      話し手の名前(- = なし) / the speaker's name (- = none)
//   ja <文>                        1ページ。すぐ次の行に en <text> / one page; the next line must be en <text>
//   choice <日本語> | <English> -> <label>   直前のページの選択肢(続けて何行でも) / an option of the page before
//                                            (as many lines as you like)
//   if [!]flag <name> <label>     印があれば(!: なければ)labelへ / jump to label if the flag is set (!: not set)
//   if [!]item <id> <label>       持ち物にあれば(!: なければ) / if the item is in the inventory (!: is not)
//   set <flag> / clear <flag>     印を付ける・消す / set / clear a flag
//   give <item> / take <item>     持ち物を足す・減らす / add / remove an item
//   goto <label> / end            ほかの会話へ / おしまい / jump / the end

Here is the elder's first conversation and the two answers:

@elder
if flag quest_done elder_after
if item herb elder_thanks
if flag quest_started elder_waiting
name 村長 | Elder
ja おお、よく来たのう。わしはこの村の村長じゃ。
en Ah, welcome, welcome. I am the elder of this village.
ja 実は腰を痛めてしまってな。東の野原に生える薬草があれば、よく効く薬が作れるんじゃが……。
en You see, I have hurt my back. With a healing herb from the field to the east, I could make a good medicine...
ja 薬草をとってきてくれんかのう?
en Would you fetch me a healing herb?
choice はい | Yes -> elder_yes
choice いいえ | No -> elder_no

@elder_yes
set quest_started
name 村長 | Elder
ja ありがたい! 薬草は野原の池のそばに生えておる。村の東の出口から行けるぞ。
en Thank you! The herb grows beside the pond in the field. Take the east exit of the village.

@elder_no
name 村長 | Elder
ja そうか……。気が変わったら、また声をかけておくれ。
en I see... If you change your mind, come and talk to me again.

A map object names its conversation with say=, for example object npc elder 18 14 look=1 say=elder mode=idle face=down.
Signs and locked doors are objects with a say= too, so 「鍵がかかっている。」 for the village's two locked doors is two lines of data.

This is the same design as the map format from chapter 33: one command per line, a keyword first, # comments.
It's deliberately tiny: no expressions, no variables beyond flags and items, no nesting.
Branching is done with labels and jumps, like assembly language or BASIC, and for conversations of a few pages that is perfectly readable.

Compiling to a list of commands

DialogueScript::load reads the file once at start-up and turns it into one vector of commands plus a map from label to index:

  enum class Op { Name, Page, Choice, IfFlag, IfItem, Set, Clear, Give, Take, Goto, End };
  struct Command {
    Op op;
    Text text{};          // Name, Page, Choice
    std::string a{}, b{}; // flag/item名、飛び先 / flag or item name, jump target
    bool negate = false;
    int line = 0;
  };
  std::vector<Command> commands;
  std::unordered_map<std::string, size_t> labels;

Each command remembers its line in the file, for error messages.
A label isn't a command; it's just the index where its conversation starts, and the parser adds an End before every new label, so a conversation can never run into the next one:

    if (command[0] == '@') {
      // 新しい会話:前の会話はここで終わる / a new conversation: the one before ends here
      if (inBlock) add({.op = Op::End});
      std::string label = command.substr(1);
      if (label.empty() || s.labels.contains(label)) return fail("空か二度目のラベル / empty or repeated label: " + label);
      s.labels[label] = s.commands.size();
      inBlock = true;
      continue;
    }

A page is a ja line immediately followed by an en line, which fills in the English half of the same command:

    } else if (command == "ja") {
      add({.op = Op::Page, .text = {restOf(in), ""}});
    } else if (command == "en") {
      if (s.commands.empty() || s.commands.back().op != Op::Page || !s.commands.back().text.en.empty())
        return fail("enはjaのすぐ後に / en must directly follow ja");
      s.commands.back().text.en = restOf(in);

A choice belongs to the page right before it, so it may only follow a page or another choice.
Anywhere else it would never be picked up (the Page case of next() below shows why), and the question would appear without its answers, so that's a load error too:

    } else if (command == "choice") {
      // 選択肢はページ(ja/en)かほかのchoiceのすぐ後だけ:ほかの場所のchoiceは実行のときに無視されてしまう
      // A choice may only directly follow a page (ja/en) or another choice: anywhere else it would be ignored when
      // the script runs
      if (s.commands.empty() || (s.commands.back().op != Op::Page && s.commands.back().op != Op::Choice))
        return fail("choiceはページかchoiceのすぐ後に / choice must directly follow a page or another choice");

The whole dialogue.txt becomes 81 commands under 20 labels.
Here are the first 21, the elder's conversations, with their jumps:

The commands 0 to 20 as rows. @elder starts at 0 with IfFlag quest_done to elder_after at index 29, IfItem herb to elder_thanks at 20 and IfFlag quest_started to elder_waiting at 17, then Name, three Pages, two Choices to elder_yes at 10 and elder_no at 14, and End at 9. @elder_yes is Set quest_started, Name, Page, End; @elder_no Name, Page, End; @elder_waiting Name, Page, End; @elder_thanks starts with Take herb. Pages are yellow, jumps blue, changes to World pink, End red

Checking everything at start-up

A typo in a script that is only found when a player reaches that conversation is the worst kind of bug: it ships.
So load checks the file completely before the game starts.
Syntax errors are found while parsing (an unknown command, en without ja, a choice that doesn't follow a page, an if that is neither flag nor item, a repeated label), and after the last line one more pass checks what can only be known at the end, that every jump target exists and every page has its English:

  // 飛び先がみなあるか、ページにenがあるかを今確かめる(遊んでいる途中で見つかるより良い)
  // Check now that every jump target exists and every page has its English (better than finding out while playing)
  for (const Command &c : s.commands) {
    number = c.line;
    if ((c.op == Op::Choice && !s.labels.contains(c.a)) ||
        ((c.op == Op::IfFlag || c.op == Op::IfItem || c.op == Op::Goto) && !s.labels.contains(c.b)))
      return fail("ないラベルへ飛ぶ / jump to a label that does not exist: " + (c.op == Op::Choice ? c.a : c.b));
    if (c.op == Op::Page && c.text.en.empty()) return fail("英語の行がない / the en line is missing");
  }

Errors come out as file:line: message, the format compilers use, so editors and IDEs can jump to them.
These are the three typical mistakes, each made on a copy of the file (a typo in a label on line 21, a missing en after line 14, tak for take on line 40); the game prints the message and exits instead of starting:

games/rpg/assets/dialogue.txt:21: ないラベルへ飛ぶ / jump to a label that does not exist: elder_nope
games/rpg/assets/dialogue.txt:14: 英語の行がない / the en line is missing
games/rpg/assets/dialogue.txt:40: 知らない命令 / unknown command: tak

A set quest_started slipped in between the elder's question and its first choice is caught as well; the misplaced choice has moved down to line 21:

games/rpg/assets/dialogue.txt:21: choiceはページかchoiceのすぐ後に / choice must directly follow a page or another choice

The checks are only as good as their list, though.
References from other files aren't checked: a map's say= label is only looked up when you talk to that person, and then a missing one prints no such conversation and the box closes at once.
Nor is an item id: a give of an item that items.txt doesn't define simply puts that id into the inventory, which then lists the bare id without an icon (challenge 5 checks the ids at start-up).

Running it

DialogueRunner executes one conversation.
It's a classic interpreter loop with a program counter, pc, that runs commands until it reaches something to show:

bool DialogueRunner::next() {
  using Op = DialogueScript::Op;
  // ページのないgotoの輪で止まらないように、命令の数に上限 / a limit on commands, so a goto loop without pages cannot
  // hang the game
  for (int guard = 0; running && guard < 10000 && pc < script.commands.size(); ++guard) {
    const DialogueScript::Command &c = script.commands[pc++];
    switch (c.op) {
    case Op::Name: speaker = c.text; break;
    case Op::Page:
      current = {.speaker = speaker, .text = c.text, .choices = {}};
      // すぐ後のchoiceはこのページの選択肢 / choices right after belong to this page
      while (pc < script.commands.size() && script.commands[pc].op == Op::Choice) {
        current.choices.push_back({script.commands[pc].text, script.commands[pc].a});
        ++pc;
      }
      return true;
    case Op::Choice: break; // ページの後でしか意味がない(読み込みで並びは保証) / only meaningful after a page
    case Op::IfFlag:
      if (world.flag(c.a) != c.negate) jump(c.b);
      break;
    case Op::IfItem:
      if ((world.itemCount(c.a) > 0) != c.negate) jump(c.b);
      break;
    // 筋書きを変える命令は標準出力にも出す(スクリプトで動かしたときの確認用) / commands that change the story are also
    // printed to stdout (to check scripted runs)
    case Op::Set:
      world.setFlag(c.a);
      printf("  set %s\n", c.a.c_str());
      break;
    case Op::Clear:
      world.clearFlag(c.a);
      printf("  clear %s\n", c.a.c_str());
      break;
    case Op::Give:
      world.addItem(c.a);
      printf("  give %s\n", c.a.c_str());
      break;
    case Op::Take:
      if (!world.removeItem(c.a)) fprintf(stderr, "take %s: 持っていない / not in the inventory\n", c.a.c_str());
      else printf("  take %s\n", c.a.c_str());
      break;
    case Op::Goto: jump(c.b); break;
    case Op::End: running = false; break;
    }
  }
  running = false;
  return false;
}

next() returns true with a new page() when it stops at a Page, and false when it reaches an End.
Everything between two pages runs instantly: the ifs decide which branch to take, set, give and take change the World, name changes the speaker for the following pages.
The choice lines right after a page are collected into that page, and choose(i) jumps to the answer's label and calls next() again.
That is also why case Op::Choice does nothing: the loader guarantees that every choice follows a page or another choice, and Page takes them all, so the interpreter never stops on one.
! in front of flag or item turns a condition around (c.negate), which is why the test compares with !=.

Two details make it robust.
The guard caps a call at 10 000 commands, so a goto loop that never reaches a page ends the conversation instead of hanging the game.
And every command that changes the story is printed on stdout.
That trace is how the scripted walkthrough for this chapter's clips was checked; it reads like a summary of the quest:

village: 会話 / talk @elder
  set quest_started
village/village_chest: 開けた / opened (apple)
games/rpg/assets/maps/field.map: 読んだ / loaded (40×24)
village → field (west)
field/herb: 拾った / picked up herb
field → village (east)
village: 会話 / talk @elder
  take herb
  give key
  set quest_done
village → field (west)
field: 会話 / talk @gate
  take key
  set gate_open
field/garden_chest: 開けた / opened (sword)

The interpreter knows nothing about boxes or typewriters, and the dialogue scene knows nothing about flags: the runner hands out pages, the scene shows them.
The same runner could drive a voice-acted cutscene or a test that plays every branch of the script without a window.

35.7 Items and the inventory

items.txt

Items are data too:

item herb herb 薬草 | Healing herb
info ja 野原の池のそばに生える草。よく効く薬になる。
info en A herb from beside the pond in the field. It makes a good medicine.
item key key 古い鍵 | Old key
info ja 村長にもらった鍵。野原の庭の門が開く。
info en A gift from the elder. It opens the garden gate in the field.

item <id> <icon> <name> defines a kind, and the info lines below it give its description in each language.
The id is what the script and the maps use (give key, item=sword); the icon is a sprite name in items.atlas, the sheet made by the same script as the tiles, with seven 16 × 16 icons and a four-frame sparkle clip.
ItemTable::load keeps the kinds in a vector:

struct ItemKind {
  std::string id;
  std::string icon;
  int sprite = -1; // items.atlasの番号(mainで引く) / index in items.atlas (looked up in main)
  Text name, info;
};

The icon name is resolved to a sprite index in main, once, and an icon that doesn't exist stops the game at start-up, the same policy as the script:

  for (ItemKind &k : itemTable->kinds()) {
    k.sprite = items->find(k.icon);
    if (k.sprite < 0) {
      fprintf(stderr, "items.txt: %s のアイコン %s がない / icon %s not in items.atlas\n", k.id.c_str(), k.icon.c_str(),
              k.icon.c_str());
      return 1;
    }
  }

The inventory is World state

What the player carries must survive doors, so it's in World, in the order things were found:

  // 持ち物:手に入れた順(持ち物の画面の並び) / the inventory, in the order things were found (the menu's order)
  int itemCount(const std::string &id) const;
  void addItem(const std::string &id, int count = 1);
  bool removeItem(const std::string &id, int count = 1); // 足りなければ何もしないでfalse / false (and nothing
                                                          // changes) if there are not enough
  const std::vector<std::pair<std::string, int>> &items() const { return inventory; }

A vector of (id, count) pairs rather than a map, because a menu wants a stable order, and five items don't need a hash table.
removeItem refuses to go below zero, so a take of something the player doesn't have changes nothing and reports it on stderr.

Where items come from

Chests from chapter 34 can now hold an item instead of gold (chest village_chest 21 8 item=apple).
Opening one sets its flag as before, adds the item and pushes a dialogue box with a message:

    if (std::string item(c.object->get("item")); !item.empty()) {
      g.world.addItem(item);
      printf("%s: 開けた / opened (%s)\n", c.flag.c_str(), item.c_str());
      scenes().push(std::make_unique<DialogueScene>(g, g.gotItem(item)));

The message isn't in dialogue.txt, because it's built from the item's name:

Text Game::gotItem(const std::string &id) const {
  const ItemKind *kind = itemTable.find(id);
  Text name = kind ? kind->name : Text{id, id};
  return {name.ja + "を手に入れた!", "You found: " + name.en + "!"};
}

DialogueScene has a second constructor for such one-off texts, which makes a one-page script with DialogueScript::single and owns it, so messages from code and conversations from the file use the same box, typewriter and wrapping.
Note that the English isn't "You found " + name: Japanese puts the verb after the object (薬草を手に入れた!), and building sentences by gluing words in one language's order is the classic translation bug.
The colon form "You found: Healing herb!" works for every item name without articles.

The herb lies on the ground: object item herb 22 17 item=herb in the field.
It's drawn bobbing up and down with the sparkle clip next to it, in the same y-sorted batch as the characters, and it's picked up by walking over it, with a flag field/herb so it never comes back:

void MapScene::checkPickups() {
  for (const Pickup &p : pickups) {
    if (g.world.flag(p.flag) || !present(*p.object)) continue;
    Rect box = Rect::fromCentre(p.object->rect.centre(), {10.0f, 10.0f});
    if (!overlaps(hero.box, box)) continue;
    g.world.setFlag(p.flag);
    g.world.addItem(p.item);
    printf("%s: 拾った / picked up %s\n", p.flag.c_str(), p.item.c_str());
    scenes().push(std::make_unique<DialogueScene>(g, g.gotItem(p.item)));
    return;
  }
}

The inventory screen

I pushes InventoryScene, another overlay: it darkens the map, lists icon, name and count of every item, and shows the selected item's description, wrapped with the same wrapText to 240 px.
The list is drawn from World every frame, so it's always current, and L works here too:

The inventory overlay in two languages. Left, 持ち物 with りんご ×1 selected and 古い剣 ×1, and below the description 赤くておいしそうなりんご。. Right, the same after L: Items, Apple ×1 and Old sword ×1, and A shiny red apple.

35.8 Villagers

Four people, two behaviors

The village has the elder by the well and Mina east of the bridge, the house has Mom, and the field has a farmer.
Each is a map object such as object npc girl 30 13 look=2 say=girl mode=wander radius=2: the row in characters.png, the conversation, the behavior and how far from home they stroll (in tiles).
Npc wraps chapter 33's Character, so a villager has the same foot box, walk animation and collision as the hero:

struct Npc {
  enum class Mode { Idle, Wander };

  Character body;
  const MapObject *object = nullptr;
  std::string say;      // 話しかけたときの会話(dialogue.txtの@label) / the conversation when talked to (an @label)
  Mode mode = Mode::Idle;
  Vec2 home;            // 出発点(足元の箱の左上) / the starting point (top left of the foot box)
  float radius = 0.0f;  // 家からどこまで歩くか(ピクセル) / how far from home it strolls (pixels)
  float timer = 0.0f;   // 次に決めるまでの秒数 / seconds until the next decision
  Vec2 direction;       // 歩く向き(0 = 立ち止まっている) / walking direction (0 = standing)

The behavior is a tiny state machine driven by one timer:

Two state machines. Idle, for the elder: a look state that loops onto itself; it faces down with probability 3/6 and left, right or up with 1/6 each, every 1.5 to 3.5 s. Wander, for Mina, Mom and the farmer: stand goes to walk when the timer runs out, picking a direction toward home when farther than the radius and otherwise one of four at random, walking 0.4 to 1.1 s; walk goes back to stand when the timer runs out or it bumps into something, standing 1 to 2.5 s; 36 px/s, colliding like the hero. Below: when talked to, the villager faces the hero, stops, and its timer is set to 1.5 s

void Npc::update(float dt, Rng &rng, const Tilemap &map, std::span<const Rect> others, std::vector<Rect> &scratch,
                 const CharacterSheet &sheet) {
  body.beginStep();
  timer -= dt;
  if (timer <= 0.0f) {
    if (mode == Mode::Idle) {
      // ときどき向きを変える(下向きが多め) / turn now and then (mostly facing down)
      static const Facing kLook[] = {Facing::Down, Facing::Down, Facing::Left, Facing::Right, Facing::Down, Facing::Up};
      body.facing = rng.pick(std::span<const Facing>(kLook));
      timer = rng.range(1.5f, 3.5f);
    } else if (direction.x != 0.0f || direction.y != 0.0f) {
      direction = {}; // 歩いた:しばらく立ち止まる / walked: stand still for a while
      timer = rng.range(1.0f, 2.5f);
    } else {
      // 次の向き:家から離れすぎていれば家の方、でなければ4方向から乱数 / next direction: toward home when too far,
      // otherwise one of the 4 directions at random
      Vec2 toHome = home - body.box.position();
      if (length(toHome) > radius) {
        direction = std::abs(toHome.x) > std::abs(toHome.y) ? Vec2{toHome.x > 0.0f ? 1.0f : -1.0f, 0.0f}
                                                            : Vec2{0.0f, toHome.y > 0.0f ? 1.0f : -1.0f};
      } else {
        static const Vec2 kDirs[] = {{1.0f, 0.0f}, {-1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, -1.0f}};
        direction = rng.pick(std::span<const Vec2>(kDirs));
      }
      body.facing = facingOf(direction);
      timer = rng.range(0.4f, 1.1f);
    }
  }
  body.moving = direction.x != 0.0f || direction.y != 0.0f;
  if (body.moving) {
    MoveResult hit = moveOnMap(body.box, direction * (kNpcSpeed * dt), map, others, scratch);
    if (hit.hitX || hit.hitY) timer = 0.0f; // ぶつかったら立ち止まって考え直す / bumped: stop and decide again
  }
  body.animate(sheet, dt);
}

The idle elder just looks around; repeating Facing::Down three times in the table makes him face the player's side of the screen half of the time, a cheap way to weight a random choice.
The wanderers walk at 36 px/s, half the hero's 72, for 0.4 to 1.1 s, so one stroll is 14.4 to 39.6 px, about one to two and a half tiles.
The only "AI" is the leash: when a villager is farther than radius from home (32 px for Mina and the farmer, 16 px for Mom in the small house), the next walk goes toward home along the longer axis.
A villager that bumps into a wall, a chest or another person stops at once (timer = 0 makes the next update choose "stand"), so nobody keeps walking into a fence.

Villagers move with moveOnMap, like the hero, against the solid tiles plus blockers: chests, closed gates and every other person.
In MapScene::update the hero moves first against the villagers' boxes, then each villager moves against everything except itself, plus the hero:

  // 人:主人公・ほかの人・固い物にぶつかる / people collide with the hero, each other and solid things
  for (Npc &n : npcs) {
    collectBlockers(&n);
    blockers.push_back(hero.box);
    n.update(dt, rng, *map, blockers, scratch, g.characters);
  }

Rebuilding the list per villager is O(n²), which for four people on a map is nothing; a town with hundreds would use the broad phase from chapter 26's "How real engines do it".
People are drawn in the same y-sorted batch as the hero, chests and items, so walking behind Mina puts the hero behind her.

Talking

Space checks the 8 px probe in front of the hero from chapter 34, and people come first, before chests and signs:

  // 人:こちらを向かせてから話す / people: make them face the hero, then talk
  for (Npc &n : npcs)
    if (overlaps(probe, n.body.box)) {
      n.faceTowards(hero.facing);
      // 会話の間はマップが更新されないので、新しい向きの絵を今選ぶ / the map is not updated during the dialogue, so
      // pick the picture for the new facing now
      n.body.animate(g.characters, 0.0f);
      talk(n.say);
      return;
    }

Turning to face the speaker is the small touch that makes a sprite feel like a person.
It's simple on a 4-direction grid: the villager faces the opposite of the hero's facing, stops walking and waits 1.5 s:

void Npc::faceTowards(Facing hero) {
  body.facing = hero == Facing::Up ? Facing::Down : hero == Facing::Down ? Facing::Up : hero == Facing::Left ? Facing::Right
                                                                                                             : Facing::Left;
  direction = {};
  body.moving = false;
  timer = 1.5f;
}

Since the map isn't updated while the box is open, those 1.5 s start when the conversation ends, so the villager doesn't walk off the moment you close the box.
For the same reason interact calls animate with a zero step right after faceTowards: the facing is only turned into a picture by animate, and without that call the villager would go on showing the old direction for the whole conversation and turn only when the box closes.

NPCs belong to the scene, not to World: they're created from the map file in setUp, so when you come back to the village everybody is at their starting spot.
That's chapter 34's kept/reset rule; flags are kept, positions are reset.
Challenge 6 moves the villagers to the "kept" side.

A seed that is the same everywhere

The strolling is random, but it must be reproducible, for the same reasons chapter 26 gave for Rng: replays, bug reports, and this tutorial's screenshots and clips, which are made by scripted runs that must look the same every time.
Each map scene has its own Rng, so the villagers of one map don't change their walks when something happens on another, and its seed comes from the map's name:

  // 人の動きの乱数はマップの名前から種を作る(FNV-1a):同じ入力なら毎回、どの環境でも同じ動き。
  // std::hashは標準ライブラリごとに値が違うので使わない(Rngの<random>の分布と同じ理由)
  // The villagers' random numbers are seeded from the map's name (FNV-1a): the same input gives the same movement
  // every time, on every platform. std::hash differs between standard libraries, so it is not used (the same reason
  // as for <random>'s distributions and Rng)
  std::uint32_t seed = 2166136261u;
  for (char c : mapName) seed = (seed ^ static_cast<unsigned char>(c)) * 16777619u;
  rng.seed(seed);

The first version used std::hash<std::string>, which looks like the natural tool, and the builder replaced it.
It's the same trap as std::uniform_int_distribution in chapter 26: the standard says what std::hash must do (equal inputs give equal results, within one run of the program) but not how, and every standard library has its own algorithm.
GCC's libstdc++ uses a MurmurHash variant, Clang's libc++ (FreeBSD's default) uses its own MurmurHash2 and CityHash code, and Microsoft's STL uses 64-bit FNV-1a.
So the villagers would walk one way on Linux, another on FreeBSD and a third on Windows, and a screenshot taken on one machine couldn't be reproduced on another.
An implementation is even allowed to salt the hash per run, which some languages' hash tables do on purpose to defend against attacks.

FNV-1a (Fowler–Noll–Vo) is a hash simple enough to write in two lines and defined exactly: start with the offset basis 2 166 136 261, and for every byte XOR it in and multiply by the prime 16 777 619, keeping 32 bits.
Unsigned overflow in C++ is defined as wrapping modulo 232, so the result is the same with every compiler.
Casting the char to unsigned char matters: char is signed on x86 but unsigned on most ARM Linux systems, and a byte above 127 would otherwise be sign-extended differently.

Map FNV-1a, 32 bit (our seed) std::hash, GCC 13 (libstdc++, 64 bit) std::hash, MSVC x64 (64-bit FNV-1a)
village 1 192 893 027 2 044 099 867 275 323 672 9 500 612 482 239 330 275
home 3 536 372 366 10 995 859 295 675 299 483 4 624 382 957 487 889 774
field 1 736 598 119 295 559 816 372 023 331 3 196 716 258 119 057 351

Hashing a name instead of numbering the maps by hand has a nice property: a new map gets its own stable seed without anybody having to assign one.

35.9 The quest: flags that change the world

Objects with conditions

The quest needs the world to change: the garden gate must disappear once it's unlocked.
Chapter 34's objects get two optional properties, if=<flag> (the object exists only while the flag is set) and unless=<flag> (only while it isn't):

// if=<印> なら印があるときだけ、unless=<印> なら印がないときだけ、その物はある
// With if=<flag> the object exists only while the flag is set, with unless=<flag> only while it is not
bool MapScene::present(const MapObject &o) const {
  std::string_view need = o.get("if"), avoid = o.get("unless");
  if (!need.empty() && !g.world.flag(std::string(need))) return false;
  if (!avoid.empty() && g.world.flag(std::string(avoid))) return false;
  return true;
}

Every kind of object respects it: chests, items, doors, signs, gates and villagers.
The field's new objects show how the quest is wired, entirely in data:

object chest garden_chest 30 5 item=sword
object npc farmer 8 15 look=4 say=farmer mode=wander radius=2
object item herb 22 17 item=herb
object gate garden_gate 30 9 w=2 unless=gate_open say=gate
object sign field_sign 13 13 say=sign_field

The gate is two tiles wide in the garden fence, solid and drawn with the gate tile while it's present.
Checking it runs @gate:

@gate
if item key gate_unlock
ja 門には鍵がかかっている。
en The gate is locked.

@gate_unlock
take key
set gate_open
ja 古い鍵で門を開けた!
en You unlocked the gate with the old key!

present() is evaluated every frame for chests, items, gates and doors, both for collision and drawing, so the moment set gate_open runs, the gate is gone.
Since set runs before the page appears, the gate already vanishes while 「古い鍵で門を開けた!」 is on screen, behind the box.
For a gate that's fine; if the order matters (a door that should open after the message), put the message first and the set in a second block reached with goto.
Villagers are created once per visit, so they are re-checked in resume(), when an overlay closes, in case the conversation changed a flag that makes someone appear or leave.
A villager who appears here is drawn before its first update, like the hero in chapter 33, so the last loop picks a clip for everyone with a zero step (setUp does the same for the people it creates); for those who were already there, play keeps the clip they have and nothing moves:

void MapScene::resume() {
  covered = false;
  // 会話で印が変わったかもしれない(門が開いた…):印で出たり消えたりする人を置き直す。門・宝箱・落ちている物は
  // present()を毎回見るので、そのままで変わる
  // The dialogue may have changed flags (the gate opened...): re-check people that depend on flags. Gates, chests and
  // items on the ground check present() every time, so they change by themselves
  std::erase_if(npcs, [&](const Npc &n) { return !present(*n.object); });
  for (const MapObject &o : map->objects())
    if (o.kind == "npc" && present(o) &&
        std::none_of(npcs.begin(), npcs.end(), [&](const Npc &n) { return n.object == &o; }))
      npcs.push_back(Npc::fromObject(o));
  // 新しく出た人は更新の前に描かれる:クリップを選んでおく(今いる人はそのまま) / people who just appeared are drawn
  // before their first update: pick their clip (the others keep theirs)
  for (Npc &n : npcs) n.body.animate(g.characters, 0.0f);
}

The quest is three flags

There is no quest system.
The whole quest is three flags and the inventory, documented in a comment at the top of dialogue.txt: quest_started (you accepted), quest_done (you brought the herb and got the key), gate_open.

The quest in five steps. 1, the elder: choose Yes, set quest_started, inventory empty. 2, the herb by the pond: walk over it, flag field/herb, inventory herb. 3, the elder: if item herb, take herb, give key, set quest_done, inventory key. 4, the garden gate: if item key, take key, set gate_open, inventory empty. 5, the chest: the gate is gone, flag field/garden_chest, inventory sword. Below: the elder checks quest_done, then the herb, then quest_started, then the first talk; choosing No goes to elder_no without a flag; the gate object has unless=gate_open

The elder's conversation starts with the three ifs, and their order is the quest logic: the most advanced state is checked first.
After the quest he talks about his back; with the herb in your pocket he takes it; after accepting he reminds you where the herb grows; otherwise he asks.
The herb isn't hidden until you accept, so a player who explores first can bring it before being asked, and the elder simply thanks them: the if item herb comes before the if flag quest_started.
Mom, Mina and the farmer check the same flags and say something different before and after, which makes the village feel aware of what you did, for the price of a few lines of text.

Here are the key moments of the walkthrough:

Six frames of the quest. 1, the herb by the pond: 薬草を手に入れた!. 2, the elder gives the key, with the push-out line break. 3, the locked gate in the garden fence. 4, 古い鍵で門を開けた! with the gate already gone behind the box. 5, flag gate_open: the gate is gone and the hero walks in. 6, the old sword: 古い剣を手に入れた! in front of the chest

This is how most RPGs are built, from the 8-bit era to today: a global set of story flags (switches in RPG Maker, event flags in many Japanese RPGs) and scripts that test them.
Its weakness is that nothing describes the quest as a whole; with dozens of flags, writers keep a separate document listing them, which is what the comment block at the top of dialogue.txt is in miniature.

35.10 Running it

Build as before and run ./build/games/rpg/rpg from the project root (in Visual Studio, start the rpg project; the working directory is already the root).
Choose a language, walk up to the elder (he stands at the well in the square, south of the main road) and press Space.
The terminal shows the trace from 35.6 as you play, which is a convenient way to see what the script did.

The script and the items are read once at start-up, so after editing dialogue.txt you restart the game; no rebuild is needed (if you use a kanji that isn't in the atlas, switch to the big font of section 35.3 first).
The maps are reloaded with R, as in chapter 34, which also re-creates the villagers.

35.11 Platform notes

  • Windows (Visual Studio): the RPG has far more Japanese in its string literals than any earlier program (the messages, the inventory title, the title screen), and the char32_t literals in noLineStart are Japanese characters. MSVC reads source files without a byte order mark in the system code page unless it's given /utf-8; with the Japanese code page (932) it would misread the UTF-8 bytes, and the kinsoku table and the messages would be wrong. The project's top-level CMakeLists.txt passes /utf-8 to every target for MSVC, so nothing needs to be done here; if you set up your own project, add it.
  • All: the data files are read as bytes and are UTF-8 without a BOM. Most editors save that by default; Windows Notepad does too in current versions. A BOM at the start of dialogue.txt would glue three bytes to the first line, so it would no longer be a comment and the loader would refuse it as a command before the first @label.
  • All: std::hash differs between libstdc++ (GCC, most Linux), libc++ (Clang, FreeBSD) and MSVC's STL; FNV-1a gives the same villagers' walks on all three. The same goes for anything you derive from a hash and want to reproduce: write the hash yourself.
  • Linux, FreeBSD, Windows: the game's font is a finished PNG and .fnt, the same files on every platform, and no font needs to be installed; the same goes for the big version of section 35.3.

35.12 How real engines do it

  • Dialogue: dedicated narrative languages. Ink (by inkle, used in 80 Days and Heaven's Vault) and Yarn Spinner (used in Night in the Woods and A Short Hike) are scripting languages for branching dialogue with variables, conditions and choices, compiled to a small bytecode and run by a runtime in the game, which is our design grown up. Twine is a visual editor for the same kind of story. Many engines simply embed Lua for both dialogue and game logic. Big studios use database tools such as articy:draft, where writers edit conversations as graphs.
  • Localization: real games keep text out of the scripts altogether: the script says line elder_greeting_01, and a string table per language holds the text, so translators work in spreadsheets or tools such as gettext's .po files, Unity's Localization package or Unreal's String Tables. Messages built from pieces use format strings with numbered placeholders ({0}を手に入れた! / You found: {0}!), because languages order the pieces differently.
  • Line breaking: the Unicode line breaking algorithm (UAX #14) and, for Japanese typesetting, the W3C's "Requirements for Japanese Text Layout" (JLReq) define kinsoku and much more; ICU's BreakIterator implements UAX #14, and text engines such as HarfBuzz with a layout library on top handle the rest. Hand-written rules like ours are still common in games with pixel fonts.
  • NPCs: behavior trees (Unreal), state machines (most 2D engines) and utility AI; for strolling villagers a timer and a leash like ours is the standard trick. Big open-world games give NPCs schedules (sleep, work, the tavern) on top.
  • Quests: a flag set plus scripts in most RPGs; larger games add a quest system with explicit stages and objectives, so the journal, the map markers and the dialogue all read the same state.

35.13 The RPG in review, and what comes next

Three chapters turned a tile renderer into a small adventure:

  • Chapter 33: tilemaps with layers in a static vertex buffer, row culling, a tileset atlas with extruded tiles, free movement with collision against solid cells, corner assist, and a camera that follows the hero and stops at the map's edges.
  • Chapter 34: several maps loaded from files and cached, doors and edge exits as objects, scene replacement with fades, and the central design question of what is kept in World and what is reset with the scene.
  • This chapter: bilingual text with a language switch at any time, a game-specific font atlas, word wrapping for English and Japanese with kinsoku, a typewriter dialogue box as an overlay, a validated dialogue script with a tiny interpreter, items and an inventory, villagers with a portable random seed, and a quest made of flags and conditional objects.

Notice how little of it is OpenGL.
The GPU work was done in chapter 33 (a static tile buffer and a sprite batch); everything since is data, state and text.
That's typical for this kind of game, and it's also the reason we built the engine first: the RPG never had to think about buffers again.

With the RPG, the three 2D games of Part 6 are complete.
Chapter 36 goes back to 3D for the last game, a third-person shooter.
It uses everything from Part 4 that the 2D games didn't need: a level built from GLB pieces, the PBR renderer with shadow mapping and post-processing, a character model, and an orbit camera that follows the player, with movement relative to where the camera looks.
The fixed-step loop, input, scenes and Rng from chapter 26 come along unchanged.

35.14 Summary

  • Bilingual text: every displayed string is a Text {ja, en}; the language is World state and Game::tr picks the string when drawing, so L switches everything at once, also inside an open dialogue, which wraps its page again. Short pairs are ja | en on one line, long ones separate ja/en lines.
  • The game's font: my generator script scans the dialogue, items, map titles and string literals and adds the missing characters to chapter 26's set: 603 glyphs (554 + 49, of which 47 kanji), still 512 × 256, 1-bit, in games/rpg/assets/fonts/; the shared fonts stay untouched. For new kanji, swap in the assets ZIP's JIS level-1 version (3 443 glyphs, 1024 × 1024, the same metrics).
  • Word wrapping: the text is cut into units (an English word, a space, one CJK character, a newline) and filled greedily into 292 px lines. English breaks at spaces; Japanese between any characters, except that kinsoku characters that must not start a line (。、!?」ー small kana) are glued to the unit before them, which gives push-out (追い出し). Hanging (ぶら下げ) and the line-end rule for opening brackets are left to the challenges.
  • UTF-8: the typewriter counts code points with charCount and firstChars, never bytes.
  • Dialogue box: an overlay scene, so the map is drawn but frozen; the page is wrapped once and shown in chunks of 3 lines; typing at 30 characters/s for Japanese and 60 for English; confirm reveals the rest, then the next chunk, then the next page; a ▼ marker and a choice box.
  • Dialogue script: dialogue.txt with @label, name, ja/en pages, choice, if [!]flag/item, set, clear, give, take, goto, end, compiled to one command vector with a label map and checked completely at start-up (file:line: message). DialogueRunner::next() runs commands until a page, with a 10 000-command guard, and prints every change to the story.
  • Items: items.txt defines kinds with icons and bilingual names and descriptions; the inventory is an ordered list in World; items come from chests and from the ground, announced by one-page messages from code; InventoryScene lists them.
  • Villagers: Npc is a Character with an idle or wander behavior driven by one timer, a leash to its home, collision with everything, and it turns to face you when you talk. NPCs are scene state (reset on re-entry). Each map's Rng is seeded with the FNV-1a hash of the map's name, because std::hash differs between standard libraries.
  • Quest: three flags and the inventory, tested by the script's ifs (most advanced state first); objects with if=/unless= appear and disappear with flags, so set gate_open removes the gate.

35.15 Challenges

  1. ★ Give Mom a line for after the gate is open: add if flag gate_open mother_gate as the first line of @mother and a new @mother_gate block with a name and a page. Without recompiling (just restart the game), Mom should say the new line once the gate is open and her old lines before. If you use a kanji that isn't in the atlas, the console should print one character not in the font warning and the box should show ?; with section 35.3's JIS level-1 pixel12 swapped in, the kanji should appear too.
  2. ★ Add a typing-speed setting toggled with T in DialogueScene (slow: half the speeds, normal, instant). At "instant" every page should appear complete in the first frame, so every Space press goes to the next page; at "slow" the elder's 44-character page should take about 2.9 s to type in Japanese.
  3. ★★ Implement hanging punctuation (ぶら下げ): in wrapText, let a unit that doesn't fit stay on the current line if it ends with a kinsoku character and overflows by at most one character width. The elder's line 「お礼にこの古い鍵をやろう。野原の庭の門の鍵じゃよ。」 should then fit on one line of 300 px, with the 。 8 px past the 292 px margin and its cell ending at x = 314, exactly on the box's right edge, and the second line should disappear.
  4. ★★ Add the line-end rule (行末禁則): an opening bracket 「『( must not end a line, so glue it to the unit after it. Test it with 23 × あ followed by 「村長の家」: today the first line ends with 「 (24 characters, 288 px); afterward it should end after the 23 あ (276 px) and the second line should start with 「村長の家」.
  5. ★★ Check item ids at start-up: add bool DialogueScript::checkItems(const std::string &path, const ItemTable &items) const that walks the commands and reports every give, take and if item whose id items.find doesn't know as file:line: message, and call it in main after both files are loaded. The real script should pass; on a copy where line 41 says give keyy, the game should refuse to start with games/rpg/assets/dialogue.txt:41: … keyy. As a bonus, check the item= of the maps' chests and items the same way when World loads a map.
  6. ★★ Let villagers keep their place: store each NPC's foot box in World (keyed by map/name) in MapScene::exit() and use it in setUp() instead of the map file's position. Mina should then stand where you left her when you come back from the field, and her strolling should still stay within 32 px of her home spot.
  7. ★★★ Use items from the inventory: Space on the selected item runs the conversation @use_<id> if the script has it (DialogueScript::has), as an overlay on top of the inventory. Add @use_apple with take apple and a page 「おいしい!」 / "Delicious!". Using the apple should show the message, the trace should print take apple, and the apple should be gone from the list when the box closes; items without a @use_ block should do nothing.

Download the diff

Download the project (ZIP)

ファイル: a/games/rpg/CMakeLists.txt | b/games/rpg/CMakeLists.txt

前新
@@ -5,7 +5,14 @@ add_executable(rpg
5 src/tile_renderer.cc 5 src/tile_renderer.cc
6 src/character.cc 6 src/character.cc
7 src/map_scene.cc 7 src/map_scene.cc
8 src/world.cc) 8 src/world.cc
    9 src/text.cc
    10 src/dialogue.cc
    11 src/items.cc
    12 src/npc.cc
    13 src/dialogue_scene.cc
    14 src/inventory_scene.cc
    15 src/title_scene.cc)
9 target_include_directories(rpg PRIVATE src) 16 target_include_directories(rpg PRIVATE src)
10 target_link_libraries(rpg PRIVATE engine) 17 target_link_libraries(rpg PRIVATE engine)
11 enable_warnings(rpg) 18 enable_warnings(rpg)

ファイル: a/games/rpg/README.md | b/games/rpg/README.md

前新
@@ -10,7 +10,10 @@
10 |---|---| 10 |---|---|
11 | 矢印 / WASD | 移動 / move | 11 | 矢印 / WASD | 移動 / move |
12 | Shift | 走る / run | 12 | Shift | 走る / run |
13 | Space / Enter | 調べる(宝箱) / check (chests) | 13 | Space / Enter | 話す・調べる(人・宝箱・看板・門)、会話を進める / talk, check (people, chests, signs, the gate), advance dialogue |
    14 | ↑ ↓ | 会話の選択肢 / dialogue options |
    15 | I | 持ち物 / inventory |
    16 | L | 日本語 ⇔ English(タイトルでは ← →) / Japanese ⇔ English (← → on the title) |
14 | 1 2 3 | 層の表示(地面・飾り・上の層) / toggle the layers (ground, decor, overlay) | 17 | 1 2 3 | 層の表示(地面・飾り・上の層) / toggle the layers (ground, decor, overlay) |
15 | B | 当たり判定の箱 / collision boxes | 18 | B | 当たり判定の箱 / collision boxes |
16 | Z | 引いて見る(行のカリングが見える) / zoom out (shows the row culling) | 19 | Z | 引いて見る(行のカリングが見える) / zoom out (shows the row culling) |
@@ -23,3 +26,12 @@
23 Maps are `assets/maps/*.map` (text). The format is described in `src/tilemap.hh`, the tile characters in 26 Maps are `assets/maps/*.map` (text). The format is described in `src/tilemap.hh`, the tile characters in
24 `assets/tiles.tileset`. Doors are `object door <name> <col> <row> map=<map> spawn=<spawn point>`, exits at the edge of 27 `assets/tiles.tileset`. Doors are `object door <name> <col> <row> map=<map> spawn=<spawn point>`, exits at the edge of
25 a map `object warp ... h=2 ...`. 28 a map `object warp ... h=2 ...`.
    29  
    30 会話は `assets/dialogue.txt`(書式は `src/dialogue.hh`)、持ち物は `assets/items.txt`。フォントにない文字は `?` で
    31 描かれる。会話に新しい漢字を使うなら、アセットのZIP(https://ass.technicalsuwako.moe/tutorial/opengl/opengl-assets.zip)の
    32 `extras/jis-level1-fonts/games/rpg/assets/fonts/` にある pixel12(JIS第1水準の漢字をすべて含む、寸法は同じ)で
    33 `assets/fonts/pixel12.png` と `.fnt` を置き換える。
    34 Dialogue is in `assets/dialogue.txt` (format in `src/dialogue.hh`), items in `assets/items.txt`. A character missing
    35 from the font is drawn as `?`. To use new kanji in the dialogue, replace `assets/fonts/pixel12.png` and `.fnt` with
    36 the pixel12 in `extras/jis-level1-fonts/games/rpg/assets/fonts/` of the assets ZIP
    37 (https://ass.technicalsuwako.moe/tutorial/opengl/opengl-assets.zip): every JIS level-1 kanji, the same metrics.

ファイル: a/games/rpg/assets/LICENSE.txt | b/games/rpg/assets/LICENSE.txt

前新
@@ -6,6 +6,21 @@ tiles.png/.atlas 16×16のタイル(草・道・水・木・家・家具
6 characters.png 人物5人 × 4方向の歩き(16×16、9コマずつ) / five characters × 4-direction walk (16×16, 9 frames 6 characters.png 人物5人 × 4方向の歩き(16×16、9コマずつ) / five characters × 4-direction walk (16×16, 9 frames
7 each) (chapter 33) 7 each) (chapter 33)
8 tiles.tileset タイルの文字・固さ・動き(手書き) / tile characters, solidity, animation (hand-written, chapter 33) 8 tiles.tileset タイルの文字・固さ・動き(手書き) / tile characters, solidity, animation (hand-written, chapter 33)
9 maps/village.map 村のマップ / the village map (chapters 33-34; edit by hand freely) 9 maps/village.map 村のマップ / the village map (chapters 33-35; edit by hand freely)
10 maps/home.map 家の中 / the house interior (chapter 34) 10 maps/home.map 家の中 / the house interior (chapters 34-35)
11 maps/field.map 野原 / the field (chapter 34) 11 maps/field.map 野原 / the field (chapters 34-35)
    12 items.png/.atlas 持ち物のアイコン(16×16)ときらめき / item icons (16×16) and a sparkle (chapter 35)
    13 items.txt 持ち物の名前と説明(日本語・英語、手書き) / item names and descriptions (Japanese, English;
    14 hand-written, chapter 35)
    15 dialogue.txt 会話の台本とクエスト(手書き) / the dialogue script and the quest (hand-written, chapter 35)
    16 fonts/pixel12.png/.fnt
    17 ゲームのピクセルフォント(共有のpixel12+会話の漢字47字と矢印←→) / the game's pixel font (the
    18 shared pixel12 + 47 kanji for the dialogue and the arrows ← →)
    19 (chapter 35)
    20  
    21 fonts/pixel12 の文字の画像は DejaVu Sans Mono(Bitstream Vera License、DejaVuの変更はパブリックドメイン)と
    22 Noto Sans CJK JP(Copyright 2014-2021 Adobe; Noto is a trademark of Google Inc.; SIL Open Font License 1.1)から
    23 ラスタライズしたもの。フォントのファイルそのものは含まない(assets/LICENSE.txt と同じ)。
    24 The glyph images in fonts/pixel12 were rasterized from DejaVu Sans Mono (Bitstream Vera License, DejaVu changes in
    25 the public domain) and Noto Sans CJK JP (Copyright 2014-2021 Adobe; Noto is a trademark of Google Inc.; SIL Open Font
    26 License 1.1). The font files themselves are not included (as in assets/LICENSE.txt).

ファイル: /dev/null | b/games/rpg/assets/dialogue.txt

前新
@@ -0,0 +1,141 @@
    1 # 会話の台本 / the dialogue script (format: games/rpg/src/dialogue.hh)
    2 # 人や看板は、マップの物の say=<label> でここの @label を指す / people and signs point to an @label here with say=<label>
    3 # 筋書き(クエスト)の印 / the quest's flags:
    4 # quest_started 村長の頼みを引き受けた / accepted the elder's request
    5 # quest_done 薬草を渡して鍵をもらった / gave the herb, got the key
    6 # gate_open 庭の門を開けた(野原のマップで門が消える) / opened the garden gate (the gate disappears from the field)
    7  
    8 # ---------------------------------------------------------------- 村長 / the elder (village square)
    9 @elder
    10 if flag quest_done elder_after
    11 if item herb elder_thanks
    12 if flag quest_started elder_waiting
    13 name 村長 | Elder
    14 ja おお、よく来たのう。わしはこの村の村長じゃ。
    15 en Ah, welcome, welcome. I am the elder of this village.
    16 ja 実は腰を痛めてしまってな。東の野原に生える薬草があれば、よく効く薬が作れるんじゃが……。
    17 en You see, I have hurt my back. With a healing herb from the field to the east, I could make a good medicine...
    18 ja 薬草をとってきてくれんかのう?
    19 en Would you fetch me a healing herb?
    20 choice はい | Yes -> elder_yes
    21 choice いいえ | No -> elder_no
    22  
    23 @elder_yes
    24 set quest_started
    25 name 村長 | Elder
    26 ja ありがたい! 薬草は野原の池のそばに生えておる。村の東の出口から行けるぞ。
    27 en Thank you! The herb grows beside the pond in the field. Take the east exit of the village.
    28  
    29 @elder_no
    30 name 村長 | Elder
    31 ja そうか……。気が変わったら、また声をかけておくれ。
    32 en I see... If you change your mind, come and talk to me again.
    33  
    34 @elder_waiting
    35 name 村長 | Elder
    36 ja 薬草は野原の池のそばじゃ。東の出口から行けるぞ。
    37 en The herb grows beside the pond in the field. The east exit leads there.
    38  
    39 @elder_thanks
    40 take herb
    41 give key
    42 set quest_done
    43 name 村長 | Elder
    44 ja おお、これじゃこれじゃ! ありがとう、助かったわい。
    45 en Oh, that is the one! Thank you, you have saved me.
    46 ja お礼にこの古い鍵をやろう。野原の庭の門の鍵じゃよ。
    47 en Take this old key as thanks. It opens the garden gate in the field.
    48 name -
    49 ja 古い鍵を手に入れた!
    50 en You found: Old key!
    51  
    52 @elder_after
    53 name 村長 | Elder
    54 ja 薬のおかげで、腰がずいぶん楽になったわい。
    55 en Thanks to the medicine, my back feels much better.
    56 if flag gate_open elder_end
    57 ja 庭の門は、もう開けてみたかの?
    58 en Have you tried the garden gate yet?
    59  
    60 @elder_end
    61 name 村長 | Elder
    62 ja その剣は昔の村長のものじゃ。大事に使うのじゃぞ。
    63 en That sword belonged to the old elder. Use it well.
    64  
    65 # ---------------------------------------------------------------- ミナ / Mina (village, east of the bridge)
    66 @girl
    67 if flag quest_done girl_after
    68 name ミナ | Mina
    69 ja ねえねえ、野原には大きな池があるんだよ。
    70 en Hey, hey! There is a big pond in the field.
    71 ja 池のまわりには、いろんな草が生えてるの。
    72 en All kinds of plants grow around it.
    73  
    74 @girl_after
    75 name ミナ | Mina
    76 ja 村長さん、元気になったんだって! よかったね!
    77 en I heard the elder feels better! Hooray!
    78  
    79 # ---------------------------------------------------------------- お母さん / Mom (home)
    80 @mother
    81 if flag quest_done mother_after
    82 if flag quest_started mother_started
    83 name お母さん | Mom
    84 ja おはよう。今日もいい天気ね。
    85 en Good morning. Another lovely day.
    86 ja 村長さんが何か困っているみたいよ。広場の井戸のそばにいるわ。
    87 en The elder seems to be in some trouble. He is by the well in the square.
    88  
    89 @mother_started
    90 name お母さん | Mom
    91 ja 薬草を探しに行くの? 気をつけてね。
    92 en Off to find a herb? Be careful.
    93 ja 宝箱のパンを持っていきなさい。
    94 en Take the bread from the chest with you.
    95  
    96 @mother_after
    97 name お母さん | Mom
    98 ja えらいわね! 村長さんもとても喜んでいたわ。
    99 en Well done! The elder was so happy.
    100  
    101 # ---------------------------------------------------------------- 農夫 / the farmer (field)
    102 @farmer
    103 if flag gate_open farmer_after
    104 name 農夫 | Farmer
    105 ja あの柵の庭は、昔の村長さんの庭でね。門には鍵がかかってるんだ。
    106 en That fenced garden belonged to the old elder. The gate is locked.
    107 ja 鍵は今の村長さんが持ってるはずだよ。
    108 en The elder should have the key.
    109  
    110 @farmer_after
    111 name 農夫 | Farmer
    112 ja おや、門を開けたのかい。中の宝箱には何が入ってた?
    113 en Oh, you opened the gate? What was in the chest?
    114  
    115 # ---------------------------------------------------------------- 門・看板・扉 / the gate, signs, doors
    116 @gate
    117 if item key gate_unlock
    118 ja 門には鍵がかかっている。
    119 en The gate is locked.
    120  
    121 @gate_unlock
    122 take key
    123 set gate_open
    124 ja 古い鍵で門を開けた!
    125 en You unlocked the gate with the old key!
    126  
    127 @sign_elder
    128 ja 「村長の家」
    129 en "The Elder's House"
    130  
    131 @sign_pond
    132 ja 「池で泳がないこと」
    133 en "No swimming in the pond."
    134  
    135 @sign_field
    136 ja 「この先、昔の村長の庭」
    137 en "Ahead: the old elder's garden"
    138  
    139 @locked_door
    140 ja 鍵がかかっている。
    141 en It is locked.

ファイル: /dev/null | b/games/rpg/assets/fonts/pixel12.fnt

前新
@@ -0,0 +1,607 @@
    1 info face="DejaVu Sans Mono + Noto Sans CJK JP" size=12 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,1,1,1 spacing=2,2
    2 common lineHeight=16 base=12 scaleW=512 scaleH=256 pages=1 packed=0
    3 page id=0 file="pixel12.png"
    4 chars count=603
    5 char id=32 x=1 y=1 width=0 height=0 xoffset=0 yoffset=12 xadvance=7 page=0 chnl=15
    6 char id=33 x=3 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    7 char id=34 x=12 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    8 char id=35 x=21 y=1 width=7 height=8 xoffset=0 yoffset=4 xadvance=7 page=0 chnl=15
    9 char id=36 x=30 y=1 width=7 height=11 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    10 char id=37 x=39 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    11 char id=38 x=48 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    12 char id=39 x=57 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    13 char id=40 x=66 y=1 width=7 height=11 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    14 char id=41 x=75 y=1 width=7 height=11 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    15 char id=42 x=84 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    16 char id=43 x=93 y=1 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    17 char id=44 x=102 y=1 width=7 height=3 xoffset=0 yoffset=10 xadvance=7 page=0 chnl=15
    18 char id=45 x=111 y=1 width=7 height=4 xoffset=0 yoffset=8 xadvance=7 page=0 chnl=15
    19 char id=46 x=120 y=1 width=7 height=2 xoffset=0 yoffset=10 xadvance=7 page=0 chnl=15
    20 char id=47 x=129 y=1 width=7 height=10 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    21 char id=48 x=138 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    22 char id=49 x=147 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    23 char id=50 x=156 y=1 width=8 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    24 char id=51 x=166 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    25 char id=52 x=175 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    26 char id=53 x=184 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    27 char id=54 x=193 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    28 char id=55 x=202 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    29 char id=56 x=211 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    30 char id=57 x=220 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    31 char id=58 x=229 y=1 width=7 height=6 xoffset=0 yoffset=6 xadvance=7 page=0 chnl=15
    32 char id=59 x=238 y=1 width=7 height=7 xoffset=0 yoffset=6 xadvance=7 page=0 chnl=15
    33 char id=60 x=247 y=1 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    34 char id=61 x=256 y=1 width=7 height=5 xoffset=0 yoffset=7 xadvance=7 page=0 chnl=15
    35 char id=62 x=265 y=1 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    36 char id=63 x=274 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    37 char id=64 x=283 y=1 width=7 height=10 xoffset=0 yoffset=4 xadvance=7 page=0 chnl=15
    38 char id=65 x=292 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    39 char id=66 x=301 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    40 char id=67 x=310 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    41 char id=68 x=319 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    42 char id=69 x=328 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    43 char id=70 x=337 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    44 char id=71 x=346 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    45 char id=72 x=355 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    46 char id=73 x=364 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    47 char id=74 x=373 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    48 char id=75 x=382 y=1 width=8 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    49 char id=76 x=392 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    50 char id=77 x=401 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    51 char id=78 x=410 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    52 char id=79 x=419 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    53 char id=80 x=428 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    54 char id=81 x=437 y=1 width=7 height=11 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    55 char id=82 x=446 y=1 width=8 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    56 char id=83 x=456 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    57 char id=84 x=465 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    58 char id=85 x=474 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    59 char id=86 x=483 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    60 char id=87 x=492 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    61 char id=88 x=501 y=1 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    62 char id=89 x=1 y=14 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    63 char id=90 x=10 y=14 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    64 char id=91 x=19 y=14 width=7 height=11 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    65 char id=92 x=28 y=14 width=7 height=10 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    66 char id=93 x=37 y=14 width=7 height=11 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    67 char id=94 x=46 y=14 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    68 char id=95 x=55 y=14 width=7 height=3 xoffset=0 yoffset=12 xadvance=7 page=0 chnl=15
    69 char id=96 x=64 y=14 width=7 height=10 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    70 char id=97 x=73 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    71 char id=98 x=82 y=14 width=7 height=10 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    72 char id=99 x=91 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    73 char id=100 x=100 y=14 width=7 height=10 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    74 char id=101 x=109 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    75 char id=102 x=118 y=14 width=7 height=10 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    76 char id=103 x=127 y=14 width=7 height=10 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    77 char id=104 x=136 y=14 width=7 height=10 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    78 char id=105 x=145 y=14 width=7 height=10 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    79 char id=106 x=154 y=14 width=7 height=13 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    80 char id=107 x=163 y=14 width=7 height=10 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    81 char id=108 x=172 y=14 width=7 height=10 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    82 char id=109 x=181 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    83 char id=110 x=190 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    84 char id=111 x=199 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    85 char id=112 x=208 y=14 width=7 height=10 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    86 char id=113 x=217 y=14 width=7 height=10 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    87 char id=114 x=226 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    88 char id=115 x=235 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    89 char id=116 x=244 y=14 width=7 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
    90 char id=117 x=253 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    91 char id=118 x=262 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    92 char id=119 x=271 y=14 width=8 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    93 char id=120 x=281 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    94 char id=121 x=290 y=14 width=7 height=10 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    95 char id=122 x=299 y=14 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    96 char id=123 x=308 y=14 width=7 height=11 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    97 char id=124 x=317 y=14 width=7 height=12 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    98 char id=125 x=326 y=14 width=7 height=11 xoffset=0 yoffset=2 xadvance=7 page=0 chnl=15
    99 char id=126 x=335 y=14 width=7 height=5 xoffset=0 yoffset=7 xadvance=7 page=0 chnl=15
    100 char id=12353 x=344 y=14 width=12 height=10 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    101 char id=12354 x=358 y=14 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    102 char id=12355 x=372 y=14 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    103 char id=12356 x=386 y=14 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    104 char id=12357 x=400 y=14 width=12 height=10 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    105 char id=12358 x=414 y=14 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    106 char id=12359 x=428 y=14 width=12 height=10 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    107 char id=12360 x=442 y=14 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    108 char id=12361 x=456 y=14 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    109 char id=12362 x=470 y=14 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    110 char id=12363 x=484 y=14 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    111 char id=12364 x=498 y=14 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    112 char id=12365 x=1 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    113 char id=12366 x=15 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    114 char id=12367 x=29 y=29 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    115 char id=12368 x=43 y=29 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    116 char id=12369 x=57 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    117 char id=12370 x=71 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    118 char id=12371 x=85 y=29 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    119 char id=12372 x=99 y=29 width=12 height=12 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    120 char id=12373 x=113 y=29 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    121 char id=12374 x=127 y=29 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    122 char id=12375 x=141 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    123 char id=12376 x=155 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    124 char id=12377 x=169 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    125 char id=12378 x=183 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    126 char id=12379 x=197 y=29 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    127 char id=12380 x=211 y=29 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    128 char id=12381 x=225 y=29 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    129 char id=12382 x=239 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    130 char id=12383 x=253 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    131 char id=12384 x=267 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    132 char id=12385 x=281 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    133 char id=12386 x=295 y=29 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    134 char id=12387 x=309 y=29 width=12 height=7 xoffset=0 yoffset=5 xadvance=12 page=0 chnl=15
    135 char id=12388 x=323 y=29 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    136 char id=12389 x=337 y=29 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    137 char id=12390 x=351 y=29 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    138 char id=12391 x=365 y=29 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    139 char id=12392 x=379 y=29 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    140 char id=12393 x=393 y=29 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    141 char id=12394 x=407 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    142 char id=12395 x=421 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    143 char id=12396 x=435 y=29 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    144 char id=12397 x=449 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    145 char id=12398 x=463 y=29 width=12 height=10 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    146 char id=12399 x=477 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    147 char id=12400 x=491 y=29 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    148 char id=12401 x=1 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    149 char id=12402 x=15 y=45 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    150 char id=12403 x=29 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    151 char id=12404 x=43 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    152 char id=12405 x=57 y=45 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    153 char id=12406 x=71 y=45 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    154 char id=12407 x=85 y=45 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    155 char id=12408 x=99 y=45 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    156 char id=12409 x=113 y=45 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    157 char id=12410 x=127 y=45 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    158 char id=12411 x=141 y=45 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    159 char id=12412 x=155 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    160 char id=12413 x=169 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    161 char id=12414 x=183 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    162 char id=12415 x=197 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    163 char id=12416 x=211 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    164 char id=12417 x=225 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    165 char id=12418 x=239 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    166 char id=12419 x=253 y=45 width=12 height=10 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    167 char id=12420 x=267 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    168 char id=12421 x=281 y=45 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    169 char id=12422 x=295 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    170 char id=12423 x=309 y=45 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    171 char id=12424 x=323 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    172 char id=12425 x=337 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    173 char id=12426 x=351 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    174 char id=12427 x=365 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    175 char id=12428 x=379 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    176 char id=12429 x=393 y=45 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    177 char id=12430 x=407 y=45 width=12 height=10 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    178 char id=12431 x=421 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    179 char id=12432 x=435 y=45 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    180 char id=12433 x=449 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    181 char id=12434 x=463 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    182 char id=12435 x=477 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    183 char id=12436 x=491 y=45 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    184 char id=12437 x=1 y=59 width=12 height=10 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    185 char id=12438 x=15 y=59 width=12 height=10 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    186 char id=12445 x=29 y=59 width=12 height=8 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    187 char id=12446 x=43 y=59 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    188 char id=12449 x=57 y=59 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    189 char id=12450 x=71 y=59 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    190 char id=12451 x=85 y=59 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    191 char id=12452 x=99 y=59 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    192 char id=12453 x=113 y=59 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    193 char id=12454 x=127 y=59 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    194 char id=12455 x=141 y=59 width=12 height=7 xoffset=0 yoffset=5 xadvance=12 page=0 chnl=15
    195 char id=12456 x=155 y=59 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    196 char id=12457 x=169 y=59 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    197 char id=12458 x=183 y=59 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    198 char id=12459 x=197 y=59 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    199 char id=12460 x=211 y=59 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    200 char id=12461 x=225 y=59 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    201 char id=12462 x=239 y=59 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    202 char id=12463 x=253 y=59 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    203 char id=12464 x=267 y=59 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    204 char id=12465 x=281 y=59 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    205 char id=12466 x=295 y=59 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    206 char id=12467 x=309 y=59 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    207 char id=12468 x=323 y=59 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    208 char id=12469 x=337 y=59 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    209 char id=12470 x=351 y=59 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    210 char id=12471 x=365 y=59 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    211 char id=12472 x=379 y=59 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    212 char id=12473 x=393 y=59 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    213 char id=12474 x=407 y=59 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    214 char id=12475 x=421 y=59 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    215 char id=12476 x=435 y=59 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    216 char id=12477 x=449 y=59 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    217 char id=12478 x=463 y=59 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    218 char id=12479 x=477 y=59 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    219 char id=12480 x=491 y=59 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    220 char id=12481 x=1 y=74 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    221 char id=12482 x=15 y=74 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    222 char id=12483 x=29 y=74 width=12 height=8 xoffset=0 yoffset=5 xadvance=12 page=0 chnl=15
    223 char id=12484 x=43 y=74 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    224 char id=12485 x=57 y=74 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    225 char id=12486 x=71 y=74 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    226 char id=12487 x=85 y=74 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    227 char id=12488 x=99 y=74 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    228 char id=12489 x=113 y=74 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    229 char id=12490 x=127 y=74 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    230 char id=12491 x=141 y=74 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    231 char id=12492 x=155 y=74 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    232 char id=12493 x=169 y=74 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    233 char id=12494 x=183 y=74 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    234 char id=12495 x=197 y=74 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    235 char id=12496 x=211 y=74 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    236 char id=12497 x=225 y=74 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    237 char id=12498 x=239 y=74 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    238 char id=12499 x=253 y=74 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    239 char id=12500 x=267 y=74 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    240 char id=12501 x=281 y=74 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    241 char id=12502 x=295 y=74 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    242 char id=12503 x=309 y=74 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    243 char id=12504 x=323 y=74 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    244 char id=12505 x=337 y=74 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    245 char id=12506 x=351 y=74 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    246 char id=12507 x=365 y=74 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    247 char id=12508 x=379 y=74 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    248 char id=12509 x=393 y=74 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    249 char id=12510 x=407 y=74 width=12 height=10 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    250 char id=12511 x=421 y=74 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    251 char id=12512 x=435 y=74 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    252 char id=12513 x=449 y=74 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    253 char id=12514 x=463 y=74 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    254 char id=12515 x=477 y=74 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    255 char id=12516 x=491 y=74 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    256 char id=12517 x=1 y=89 width=12 height=7 xoffset=0 yoffset=5 xadvance=12 page=0 chnl=15
    257 char id=12518 x=15 y=89 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    258 char id=12519 x=29 y=89 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    259 char id=12520 x=43 y=89 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    260 char id=12521 x=57 y=89 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    261 char id=12522 x=71 y=89 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    262 char id=12523 x=85 y=89 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    263 char id=12524 x=99 y=89 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    264 char id=12525 x=113 y=89 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    265 char id=12526 x=127 y=89 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    266 char id=12527 x=141 y=89 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    267 char id=12528 x=155 y=89 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    268 char id=12529 x=169 y=89 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    269 char id=12530 x=183 y=89 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    270 char id=12531 x=197 y=89 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    271 char id=12532 x=211 y=89 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    272 char id=12533 x=225 y=89 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    273 char id=12534 x=239 y=89 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    274 char id=12535 x=253 y=89 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    275 char id=12536 x=267 y=89 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    276 char id=12537 x=281 y=89 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    277 char id=12538 x=295 y=89 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    278 char id=12540 x=309 y=89 width=12 height=7 xoffset=0 yoffset=5 xadvance=12 page=0 chnl=15
    279 char id=12541 x=323 y=89 width=12 height=8 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    280 char id=12542 x=337 y=89 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    281 char id=12289 x=351 y=89 width=12 height=4 xoffset=0 yoffset=9 xadvance=12 page=0 chnl=15
    282 char id=12290 x=365 y=89 width=12 height=4 xoffset=0 yoffset=9 xadvance=12 page=0 chnl=15
    283 char id=12539 x=379 y=89 width=12 height=7 xoffset=0 yoffset=5 xadvance=12 page=0 chnl=15
    284 char id=12300 x=393 y=89 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    285 char id=12301 x=407 y=89 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    286 char id=12302 x=421 y=89 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    287 char id=12303 x=435 y=89 width=12 height=9 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=15
    288 char id=65288 x=449 y=89 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    289 char id=65289 x=463 y=89 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    290 char id=12304 x=477 y=89 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    291 char id=12305 x=491 y=89 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    292 char id=12316 x=1 y=104 width=12 height=7 xoffset=0 yoffset=5 xadvance=12 page=0 chnl=15
    293 char id=8230 x=15 y=104 width=12 height=6 xoffset=0 yoffset=6 xadvance=12 page=0 chnl=15
    294 char id=65281 x=29 y=104 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    295 char id=65311 x=43 y=104 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    296 char id=65306 x=57 y=104 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    297 char id=65291 x=71 y=104 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    298 char id=65293 x=85 y=104 width=12 height=5 xoffset=0 yoffset=7 xadvance=12 page=0 chnl=15
    299 char id=215 x=99 y=104 width=7 height=7 xoffset=0 yoffset=5 xadvance=7 page=0 chnl=15
    300 char id=247 x=108 y=104 width=7 height=6 xoffset=0 yoffset=6 xadvance=7 page=0 chnl=15
    301 char id=65309 x=117 y=104 width=12 height=7 xoffset=0 yoffset=5 xadvance=12 page=0 chnl=15
    302 char id=65285 x=131 y=104 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    303 char id=65286 x=145 y=104 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    304 char id=65283 x=159 y=104 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    305 char id=65290 x=173 y=104 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    306 char id=12288 x=187 y=104 width=0 height=0 xoffset=0 yoffset=12 xadvance=12 page=0 chnl=15
    307 char id=38283 x=189 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    308 char id=22987 x=203 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    309 char id=32066 x=217 y=104 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    310 char id=20102 x=231 y=104 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    311 char id=19968 x=245 y=104 width=12 height=6 xoffset=0 yoffset=6 xadvance=12 page=0 chnl=15
    312 char id=26178 x=259 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    313 char id=20572 x=273 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    314 char id=27490 x=287 y=104 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    315 char id=20877 x=301 y=104 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    316 char id=32154 x=315 y=104 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    317 char id=34892 x=329 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    318 char id=24471 x=343 y=104 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    319 char id=28857 x=357 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    320 char id=26368 x=371 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    321 char id=39640 x=385 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    322 char id=27531 x=399 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    323 char id=27231 x=413 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    324 char id=20307 x=427 y=104 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    325 char id=21147 x=441 y=104 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    326 char id=21629 x=455 y=104 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    327 char id=21213 x=469 y=104 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    328 char id=21033 x=483 y=104 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    329 char id=25943 x=497 y=104 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    330 char id=21271 x=1 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    331 char id=24341 x=15 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    332 char id=20998 x=29 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    333 char id=27425 x=43 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    334 char id=38754 x=57 y=120 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    335 char id=25147 x=71 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    336 char id=36984 x=85 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    337 char id=25246 x=99 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    338 char id=27770 x=113 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    339 char id=23450 x=127 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    340 char id=35373 x=141 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    341 char id=38899 x=155 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    342 char id=37327 x=169 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    343 char id=36895 x=183 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    344 char id=24230 x=197 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    345 char id=38291 x=211 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    346 char id=31186 x=225 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    347 char id=22238 x=239 y=120 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    348 char id=20154 x=253 y=120 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    349 char id=25973 x=267 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    350 char id=21619 x=281 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    351 char id=26041 x=295 y=120 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    352 char id=23453 x=309 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    353 char id=31665 x=323 y=120 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    354 char id=37749 x=337 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    355 char id=25161 x=351 y=120 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    356 char id=26449 x=365 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    357 char id=30010 x=379 y=120 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    358 char id=26862 x=393 y=120 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    359 char id=36947 x=407 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    360 char id=22478 x=421 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    361 char id=29579 x=435 y=120 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    362 char id=23019 x=449 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    363 char id=21191 x=463 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    364 char id=32773 x=477 y=120 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    365 char id=21091 x=491 y=120 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    366 char id=30462 x=1 y=135 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    367 char id=24339 x=15 y=135 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    368 char id=30690 x=29 y=135 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    369 char id=34220 x=43 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    370 char id=33609 x=57 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    371 char id=37329 x=71 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    372 char id=37504 x=85 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    373 char id=37509 x=99 y=135 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    374 char id=30707 x=113 y=135 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    375 char id=26408 x=127 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    376 char id=27700 x=141 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    377 char id=28779 x=155 y=135 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    378 char id=39080 x=169 y=135 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    379 char id=22303 x=183 y=135 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    380 char id=20809 x=197 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    381 char id=38343 x=211 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    382 char id=25915 x=225 y=135 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    383 char id=25731 x=239 y=135 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    384 char id=38450 x=253 y=135 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    385 char id=24481 x=267 y=135 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    386 char id=39764 x=281 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    387 char id=27861 x=295 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    388 char id=25216 x=309 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    389 char id=24517 x=323 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    390 char id=27578 x=337 y=135 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    391 char id=24489 x=351 y=135 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    392 char id=27602 x=365 y=135 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    393 char id=30496 x=379 y=135 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    394 char id=27494 x=393 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    395 char id=22120 x=407 y=135 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    396 char id=20855 x=421 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    397 char id=25345 x=435 y=135 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    398 char id=29289 x=449 y=135 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    399 char id=35013 x=463 y=135 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    400 char id=20633 x=477 y=135 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    401 char id=36023 x=491 y=135 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    402 char id=22770 x=1 y=151 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    403 char id=24215 x=15 y=151 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    404 char id=23487 x=29 y=151 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    405 char id=23627 x=43 y=151 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    406 char id=35441 x=57 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    407 char id=32862 x=71 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    408 char id=35211 x=85 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    409 char id=26469 x=99 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    410 char id=20837 x=113 y=151 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    411 char id=20986 x=127 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    412 char id=19978 x=141 y=151 width=12 height=11 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    413 char id=19979 x=155 y=151 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    414 char id=24038 x=169 y=151 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    415 char id=21491 x=183 y=151 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    416 char id=21069 x=197 y=151 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    417 char id=24460 x=211 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    418 char id=26481 x=225 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    419 char id=35199 x=239 y=151 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    420 char id=21335 x=253 y=151 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    421 char id=25276 x=267 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    422 char id=38626 x=281 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    423 char id=25163 x=295 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    424 char id=36275 x=309 y=151 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    425 char id=38957 x=323 y=151 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    426 char id=30446 x=337 y=151 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    427 char id=21475 x=351 y=151 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    428 char id=32819 x=365 y=151 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    429 char id=24515 x=379 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    430 char id=27671 x=393 y=151 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    431 char id=20803 x=407 y=151 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    432 char id=22825 x=421 y=151 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    433 char id=22320 x=435 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    434 char id=23665 x=449 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    435 char id=24029 x=463 y=151 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    436 char id=28023 x=477 y=151 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    437 char id=31354 x=491 y=151 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    438 char id=26143 x=1 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    439 char id=26376 x=15 y=167 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    440 char id=26085 x=29 y=167 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    441 char id=24180 x=43 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    442 char id=20170 x=57 y=167 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    443 char id=26397 x=71 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    444 char id=26172 x=85 y=167 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    445 char id=22812 x=99 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    446 char id=36196 x=113 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    447 char id=38738 x=127 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    448 char id=40644 x=141 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    449 char id=32209 x=155 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    450 char id=30333 x=169 y=167 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    451 char id=40658 x=183 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    452 char id=33394 x=197 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    453 char id=22823 x=211 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    454 char id=23567 x=225 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    455 char id=20302 x=239 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    456 char id=38263 x=253 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    457 char id=30701 x=267 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    458 char id=26032 x=281 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    459 char id=21476 x=295 y=167 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    460 char id=22810 x=309 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    461 char id=23569 x=323 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    462 char id=26089 x=337 y=167 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    463 char id=36933 x=351 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    464 char id=24375 x=365 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    465 char id=24369 x=379 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    466 char id=37325 x=393 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    467 char id=36605 x=407 y=167 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    468 char id=33391 x=421 y=167 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    469 char id=24746 x=435 y=167 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    470 char id=27491 x=449 y=167 width=12 height=10 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    471 char id=20840 x=463 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    472 char id=37096 x=477 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    473 char id=21322 x=491 y=167 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    474 char id=25968 x=1 y=183 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    475 char id=23383 x=15 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    476 char id=25991 x=29 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    477 char id=35501 x=43 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    478 char id=26360 x=57 y=183 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    479 char id=35328 x=71 y=183 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    480 char id=35486 x=85 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    481 char id=33521 x=99 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    482 char id=26412 x=113 y=183 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    483 char id=20013 x=127 y=183 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    484 char id=22269 x=141 y=183 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    485 char id=21517 x=155 y=183 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    486 char id=30058 x=169 y=183 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    487 char id=21495 x=183 y=183 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    488 char id=31532 x=197 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    489 char id=31456 x=211 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    490 char id=35352 x=225 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    491 char id=37682 x=239 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    492 char id=20445 x=253 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    493 char id=23384 x=267 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    494 char id=36796 x=281 y=183 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    495 char id=21066 x=295 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    496 char id=38500 x=309 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    497 char id=30011 x=323 y=183 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    498 char id=34920 x=337 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    499 char id=31034 x=351 y=183 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    500 char id=25805 x=365 y=183 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    501 char id=20316 x=379 y=183 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    502 char id=35500 x=393 y=183 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    503 char id=26126 x=407 y=183 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    504 char id=36938 x=421 y=183 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    505 char id=38627 x=435 y=183 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    506 char id=26131 x=449 y=183 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    507 char id=26222 x=463 y=183 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    508 char id=36890 x=477 y=183 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    509 char id=31777 x=491 y=183 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    510 char id=21336 x=1 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    511 char id=32244 x=15 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    512 char id=32722 x=29 y=199 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    513 char id=23550 x=43 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    514 char id=25126 x=57 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    515 char id=35430 x=71 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    516 char id=21512 x=85 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    517 char id=36000 x=99 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    518 char id=28310 x=113 y=199 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    519 char id=23436 x=127 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    520 char id=25104 x=141 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    521 char id=21151 x=155 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    522 char id=22833 x=169 y=199 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    523 char id=24565 x=183 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    524 char id=27515 x=197 y=199 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    525 char id=29983 x=211 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    526 char id=30772 x=225 y=199 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    527 char id=20498 x=239 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    528 char id=24618 x=253 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    529 char id=20027 x=267 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    530 char id=20844 x=281 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    531 char id=20210 x=295 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    532 char id=26053 x=309 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    533 char id=20882 x=323 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    534 char id=38522 x=337 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    535 char id=19990 x=351 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    536 char id=30028 x=365 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    537 char id=22259 x=379 y=199 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    538 char id=37489 x=393 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    539 char id=27934 x=407 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    540 char id=31391 x=421 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    541 char id=22612 x=435 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    542 char id=38272 x=449 y=199 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    543 char id=27211 x=463 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    544 char id=23478 x=477 y=199 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    545 char id=23460 x=491 y=199 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    546 char id=38542 x=1 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    547 char id=27573 x=15 y=214 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    548 char id=31348 x=29 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    549 char id=33853 x=43 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    550 char id=25342 x=57 y=214 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    551 char id=20351 x=71 y=214 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    552 char id=25448 x=85 y=214 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    553 char id=21463 x=99 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    554 char id=28193 x=113 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    555 char id=25506 x=127 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    556 char id=35519 x=141 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    557 char id=38598 x=155 y=214 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    558 char id=24403 x=169 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    559 char id=8592 x=183 y=214 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    560 char id=8594 x=197 y=214 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    561 char id=20107 x=211 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    562 char id=20108 x=225 y=214 width=12 height=9 xoffset=0 yoffset=3 xadvance=12 page=0 chnl=15
    563 char id=20117 x=239 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    564 char id=20196 x=253 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    565 char id=20197 x=267 y=214 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    566 char id=20250 x=281 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    567 char id=20309 x=295 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    568 char id=20808 x=309 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    569 char id=21015 x=323 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    570 char id=21161 x=337 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    571 char id=21177 x=351 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    572 char id=21360 x=365 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    573 char id=21407 x=379 y=214 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    574 char id=21516 x=393 y=214 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    575 char id=21916 x=407 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    576 char id=22256 x=421 y=214 width=12 height=11 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    577 char id=22580 x=435 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    578 char id=22768 x=449 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    579 char id=22793 x=463 y=214 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    580 char id=22806 x=477 y=214 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    581 char id=22827 x=491 y=214 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    582 char id=23376 x=1 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    583 char id=23455 x=15 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    584 char id=24133 x=29 y=230 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    585 char id=24195 x=43 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    586 char id=24237 x=57 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    587 char id=25144 x=71 y=230 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    588 char id=26132 x=85 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    589 char id=26613 x=99 y=230 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    590 char id=26684 x=113 y=230 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    591 char id=27005 x=127 y=230 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    592 char id=27597 x=141 y=230 width=12 height=12 xoffset=0 yoffset=2 xadvance=12 page=0 chnl=15
    593 char id=27744 x=155 y=230 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    594 char id=27891 x=169 y=230 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    595 char id=28988 x=183 y=230 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    596 char id=30171 x=197 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    597 char id=30330 x=211 y=230 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    598 char id=30452 x=225 y=230 width=12 height=13 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    599 char id=30693 x=239 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    600 char id=31036 x=253 y=230 width=12 height=14 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
    601 char id=31278 x=267 y=230 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    602 char id=33136 x=281 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    603 char id=35201 x=295 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    604 char id=36786 x=309 y=230 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    605 char id=37326 x=323 y=230 width=12 height=12 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    606 char id=39006 x=337 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15
    607 char id=39131 x=351 y=230 width=12 height=13 xoffset=0 yoffset=1 xadvance=12 page=0 chnl=15

ファイル: /dev/null | b/games/rpg/assets/fonts/pixel12.png

新しいファイル:100644 / バイナリファイル

ファイル: /dev/null | b/games/rpg/assets/items.atlas

前新
@@ -0,0 +1,14 @@
    1 # rpg items (generated by the author's own script): 16x16 icons
    2 image items.png
    3 sprite herb 1 1 16 16
    4 sprite key 19 1 16 16
    5 sprite bread 37 1 16 16
    6 sprite apple 55 1 16 16
    7 sprite sword 73 1 16 16
    8 sprite coin 91 1 16 16
    9 sprite potion 109 1 16 16
    10 sprite sparkle0 1 19 16 16
    11 sprite sparkle1 19 19 16 16
    12 sprite sparkle2 37 19 16 16
    13 sprite sparkle3 55 19 16 16
    14 clip sparkle 8 loop sparkle0 sparkle1 sparkle2 sparkle3

ファイル: /dev/null | b/games/rpg/assets/items.png

新しいファイル:100644 / バイナリファイル

ファイル: /dev/null | b/games/rpg/assets/items.txt

前新
@@ -0,0 +1,18 @@
    1 # 持ち物の種類 / item kinds (games/rpg/src/items.hh)
    2 # item <id> <items.atlasのアイコン / icon> <日本語> | <English>
    3 # info ja <説明> info en <description>
    4 item herb herb 薬草 | Healing herb
    5 info ja 野原の池のそばに生える草。よく効く薬になる。
    6 info en A herb from beside the pond in the field. It makes a good medicine.
    7 item key key 古い鍵 | Old key
    8 info ja 村長にもらった鍵。野原の庭の門が開く。
    9 info en A gift from the elder. It opens the garden gate in the field.
    10 item bread bread パン | Bread
    11 info ja お母さんが焼いたパン。いいにおいがする。
    12 info en Bread baked by Mom. It smells wonderful.
    13 item apple apple りんご | Apple
    14 info ja 赤くておいしそうなりんご。
    15 info en A shiny red apple.
    16 item sword sword 古い剣 | Old sword
    17 info ja 昔の村長が使っていた剣。冒険のはじまりだ!
    18 info en The sword of the old elder. Your adventure begins!

ファイル: a/games/rpg/assets/maps/field.map | b/games/rpg/assets/maps/field.map

前新
@@ -1,8 +1,8 @@
1 # のはら / Field 1 # 野原 / Field
2 # 書式は games/rpg/src/tilemap.hh、文字の意味は ../tiles.tileset / format: games/rpg/src/tilemap.hh, 2 # 書式は games/rpg/src/tilemap.hh、文字の意味は ../tiles.tileset / format: games/rpg/src/tilemap.hh,
3 # characters: ../tiles.tileset ('.' = 空 / empty) 3 # characters: ../tiles.tileset ('.' = 空 / empty)
4 map field 4 map field
5 title のはら / Field 5 title 野原 | Field
6 tileset ../tiles.tileset 6 tileset ../tiles.tileset
7 size 40 24 7 size 40 24
8   8  
@@ -88,4 +88,8 @@ tttttttttttttttttttttttttttttttttttttttt
88 object spawn start 1 10 face=right 88 object spawn start 1 10 face=right
89 object spawn west 1 10 face=right 89 object spawn west 1 10 face=right
90 object warp west 0 10 h=2 map=village spawn=east 90 object warp west 0 10 h=2 map=village spawn=east
91 object chest garden_chest 30 5 gold=100 91 object chest garden_chest 30 5 item=sword
    92 object npc farmer 8 15 look=4 say=farmer mode=wander radius=2
    93 object item herb 22 17 item=herb
    94 object gate garden_gate 30 9 w=2 unless=gate_open say=gate
    95 object sign field_sign 13 13 say=sign_field

ファイル: a/games/rpg/assets/maps/home.map | b/games/rpg/assets/maps/home.map

前新
@@ -2,7 +2,7 @@
2 # 書式は games/rpg/src/tilemap.hh、文字の意味は ../tiles.tileset / format: games/rpg/src/tilemap.hh, 2 # 書式は games/rpg/src/tilemap.hh、文字の意味は ../tiles.tileset / format: games/rpg/src/tilemap.hh,
3 # characters: ../tiles.tileset ('.' = 空 / empty) 3 # characters: ../tiles.tileset ('.' = 空 / empty)
4 map home 4 map home
5 title 家 / Home 5 title 家 | Home
6 tileset ../tiles.tileset 6 tileset ../tiles.tileset
7 size 12 10 7 size 12 10
8   8  
@@ -46,4 +46,5 @@ layer overlay above
46 object spawn start 5 7 face=up 46 object spawn start 5 7 face=up
47 object spawn door 5 8 face=up 47 object spawn door 5 8 face=up
48 object door out 5 9 map=village spawn=home_door 48 object door out 5 9 map=village spawn=home_door
49 object chest home_chest 8 2 gold=50 49 object chest home_chest 8 2 item=bread
    50 object npc mother 3 6 look=3 say=mother mode=wander radius=1

ファイル: a/games/rpg/assets/maps/village.map | b/games/rpg/assets/maps/village.map

前新
@@ -2,7 +2,7 @@
2 # 書式は games/rpg/src/tilemap.hh、文字の意味は ../tiles.tileset / format: games/rpg/src/tilemap.hh, 2 # 書式は games/rpg/src/tilemap.hh、文字の意味は ../tiles.tileset / format: games/rpg/src/tilemap.hh,
3 # characters: ../tiles.tileset ('.' = 空 / empty) 3 # characters: ../tiles.tileset ('.' = 空 / empty)
4 map village 4 map village
5 title 村 / Village 5 title 村 | Village
6 tileset ../tiles.tileset 6 tileset ../tiles.tileset
7 size 40 28 7 size 40 28
8   8  
@@ -102,4 +102,10 @@ object door home 7 7 map=home spawn=door
102 object warp east 39 10 h=2 map=field spawn=west 102 object warp east 39 10 h=2 map=field spawn=west
103 object spawn home_door 7 8 face=down 103 object spawn home_door 7 8 face=down
104 object spawn east 38 10 face=left 104 object spawn east 38 10 face=left
105 object chest village_chest 21 8 gold=30 105 object chest village_chest 21 8 item=apple
    106 object npc elder 18 14 look=1 say=elder mode=idle face=down
    107 object npc girl 30 13 look=2 say=girl mode=wander radius=2
    108 object sign elder_sign 13 7 say=sign_elder
    109 object sign pond_sign 11 19 say=sign_pond
    110 object sign elder_door 17 7 say=locked_door
    111 object sign store_door 31 7 say=locked_door

ファイル: /dev/null | b/games/rpg/src/dialogue.cc

前新
@@ -0,0 +1,178 @@
    1 #include "dialogue.hh"
    2  
    3 #include "world.hh"
    4  
    5 #include "engine/file_util.hh"
    6  
    7 #include <cstdio>
    8 #include <sstream>
    9  
    10 static std::string restOf(std::istringstream &in) {
    11 std::string rest;
    12 std::getline(in >> std::ws, rest);
    13 while (!rest.empty() && (rest.back() == '\r' || rest.back() == ' ')) rest.pop_back();
    14 return rest;
    15 }
    16  
    17 std::optional<DialogueScript> DialogueScript::load(const std::string &path) {
    18 std::optional<std::string> text = readTextFile(path);
    19 if (!text) {
    20 fprintf(stderr, "%s: 読めない / cannot read\n", path.c_str());
    21 return std::nullopt;
    22 }
    23 DialogueScript s;
    24 std::istringstream lines(*text);
    25 std::string line;
    26 int number = 0;
    27 bool inBlock = false;
    28 auto fail = [&](const std::string &what) {
    29 fprintf(stderr, "%s:%d: %s\n", path.c_str(), number, what.c_str());
    30 return std::nullopt;
    31 };
    32 auto add = [&](Command c) {
    33 c.line = number;
    34 s.commands.push_back(std::move(c));
    35 };
    36 while (std::getline(lines, line)) {
    37 ++number;
    38 std::istringstream in(line);
    39 std::string command;
    40 if (!(in >> command) || command[0] == '#') continue;
    41 if (command[0] == '@') {
    42 // 新しい会話:前の会話はここで終わる / a new conversation: the one before ends here
    43 if (inBlock) add({.op = Op::End});
    44 std::string label = command.substr(1);
    45 if (label.empty() || s.labels.contains(label)) return fail("空か二度目のラベル / empty or repeated label: " + label);
    46 s.labels[label] = s.commands.size();
    47 inBlock = true;
    48 continue;
    49 }
    50 if (!inBlock) return fail("@labelの前の命令 / a command before the first @label");
    51 if (command == "name") {
    52 std::string rest = restOf(in);
    53 add({.op = Op::Name, .text = rest == "-" ? Text{} : splitPair(rest)});
    54 } else if (command == "ja") {
    55 add({.op = Op::Page, .text = {restOf(in), ""}});
    56 } else if (command == "en") {
    57 if (s.commands.empty() || s.commands.back().op != Op::Page || !s.commands.back().text.en.empty())
    58 return fail("enはjaのすぐ後に / en must directly follow ja");
    59 s.commands.back().text.en = restOf(in);
    60 } else if (command == "choice") {
    61 // 選択肢はページ(ja/en)かほかのchoiceのすぐ後だけ:ほかの場所のchoiceは実行のときに無視されてしまう
    62 // A choice may only directly follow a page (ja/en) or another choice: anywhere else it would be ignored when
    63 // the script runs
    64 if (s.commands.empty() || (s.commands.back().op != Op::Page && s.commands.back().op != Op::Choice))
    65 return fail("choiceはページかchoiceのすぐ後に / choice must directly follow a page or another choice");
    66 std::string rest = restOf(in);
    67 size_t arrow = rest.rfind(" -> ");
    68 if (arrow == std::string::npos) return fail("choice <日本語> | <English> -> <label>");
    69 add({.op = Op::Choice, .text = splitPair(rest.substr(0, arrow)), .a = rest.substr(arrow + 4)});
    70 } else if (command == "if") {
    71 std::string what, name, target;
    72 if (!(in >> what >> name >> target)) return fail("if [!]flag|[!]item <name> <label>");
    73 bool negate = what[0] == '!';
    74 if (negate) what.erase(0, 1);
    75 if (what != "flag" && what != "item") return fail("ifの後はflagかitem / if needs flag or item: " + what);
    76 add({.op = what == "flag" ? Op::IfFlag : Op::IfItem, .a = name, .b = target, .negate = negate});
    77 } else if (command == "set" || command == "clear" || command == "give" || command == "take" || command == "goto") {
    78 std::string name;
    79 if (!(in >> name)) return fail(command + " <name>");
    80 Op op = command == "set" ? Op::Set : command == "clear" ? Op::Clear : command == "give" ? Op::Give
    81 : command == "take" ? Op::Take : Op::Goto;
    82 add({.op = op, .a = name, .b = op == Op::Goto ? name : ""});
    83 } else if (command == "end") {
    84 add({.op = Op::End});
    85 } else {
    86 return fail("知らない命令 / unknown command: " + command);
    87 }
    88 }
    89 if (inBlock) add({.op = Op::End});
    90 // 飛び先がみなあるか、ページにenがあるかを今確かめる(遊んでいる途中で見つかるより良い)
    91 // Check now that every jump target exists and every page has its English (better than finding out while playing)
    92 for (const Command &c : s.commands) {
    93 number = c.line;
    94 if ((c.op == Op::Choice && !s.labels.contains(c.a)) ||
    95 ((c.op == Op::IfFlag || c.op == Op::IfItem || c.op == Op::Goto) && !s.labels.contains(c.b)))
    96 return fail("ないラベルへ飛ぶ / jump to a label that does not exist: " + (c.op == Op::Choice ? c.a : c.b));
    97 if (c.op == Op::Page && c.text.en.empty()) return fail("英語の行がない / the en line is missing");
    98 }
    99 return s;
    100 }
    101  
    102 DialogueScript DialogueScript::single(Text text, Text speaker) {
    103 DialogueScript s;
    104 s.labels["message"] = 0;
    105 s.commands.push_back({.op = Op::Name, .text = std::move(speaker)});
    106 s.commands.push_back({.op = Op::Page, .text = std::move(text)});
    107 s.commands.push_back({.op = Op::End});
    108 return s;
    109 }
    110  
    111 DialogueRunner::DialogueRunner(const DialogueScript &s, World &w, const std::string &label) : script(s), world(w) {
    112 if (!jump(label)) {
    113 fprintf(stderr, "会話がない / no such conversation: @%s\n", label.c_str());
    114 running = false;
    115 }
    116 }
    117  
    118 bool DialogueRunner::jump(const std::string &label) {
    119 auto it = script.labels.find(label);
    120 if (it == script.labels.end()) return false;
    121 pc = it->second;
    122 return true;
    123 }
    124  
    125 bool DialogueRunner::next() {
    126 using Op = DialogueScript::Op;
    127 // ページのないgotoの輪で止まらないように、命令の数に上限 / a limit on commands, so a goto loop without pages cannot
    128 // hang the game
    129 for (int guard = 0; running && guard < 10000 && pc < script.commands.size(); ++guard) {
    130 const DialogueScript::Command &c = script.commands[pc++];
    131 switch (c.op) {
    132 case Op::Name: speaker = c.text; break;
    133 case Op::Page:
    134 current = {.speaker = speaker, .text = c.text, .choices = {}};
    135 // すぐ後のchoiceはこのページの選択肢 / choices right after belong to this page
    136 while (pc < script.commands.size() && script.commands[pc].op == Op::Choice) {
    137 current.choices.push_back({script.commands[pc].text, script.commands[pc].a});
    138 ++pc;
    139 }
    140 return true;
    141 case Op::Choice: break; // ページの後でしか意味がない(読み込みで並びは保証) / only meaningful after a page
    142 case Op::IfFlag:
    143 if (world.flag(c.a) != c.negate) jump(c.b);
    144 break;
    145 case Op::IfItem:
    146 if ((world.itemCount(c.a) > 0) != c.negate) jump(c.b);
    147 break;
    148 // 筋書きを変える命令は標準出力にも出す(スクリプトで動かしたときの確認用) / commands that change the story are also
    149 // printed to stdout (to check scripted runs)
    150 case Op::Set:
    151 world.setFlag(c.a);
    152 printf(" set %s\n", c.a.c_str());
    153 break;
    154 case Op::Clear:
    155 world.clearFlag(c.a);
    156 printf(" clear %s\n", c.a.c_str());
    157 break;
    158 case Op::Give:
    159 world.addItem(c.a);
    160 printf(" give %s\n", c.a.c_str());
    161 break;
    162 case Op::Take:
    163 if (!world.removeItem(c.a)) fprintf(stderr, "take %s: 持っていない / not in the inventory\n", c.a.c_str());
    164 else printf(" take %s\n", c.a.c_str());
    165 break;
    166 case Op::Goto: jump(c.b); break;
    167 case Op::End: running = false; break;
    168 }
    169 }
    170 running = false;
    171 return false;
    172 }
    173  
    174 bool DialogueRunner::choose(size_t option) {
    175 if (option >= current.choices.size()) return next();
    176 jump(current.choices[option].next);
    177 return next();
    178 }

ファイル: /dev/null | b/games/rpg/src/dialogue.hh

前新
@@ -0,0 +1,82 @@
    1 // 会話の台本(第35章):テキストファイルの小さな命令の並び。C++を直さずに会話と筋書きを書ける
    2 // Dialogue scripts (chapter 35): a list of small commands in a text file. Dialogue and plot can be written without
    3 // touching the C++
    4 //
    5 // 書式(games/rpg/assets/dialogue.txt) / format:
    6 // @<label> ここから一つの会話(次の@で終わる) / a conversation starts here (ends at the next @)
    7 // name <日本語> | <English> 話し手の名前(- = なし) / the speaker's name (- = none)
    8 // ja <文> 1ページ。すぐ次の行に en <text> / one page; the next line must be en <text>
    9 // choice <日本語> | <English> -> <label> 直前のページの選択肢(続けて何行でも) / an option of the page before
    10 // (as many lines as you like)
    11 // if [!]flag <name> <label> 印があれば(!: なければ)labelへ / jump to label if the flag is set (!: not set)
    12 // if [!]item <id> <label> 持ち物にあれば(!: なければ) / if the item is in the inventory (!: is not)
    13 // set <flag> / clear <flag> 印を付ける・消す / set / clear a flag
    14 // give <item> / take <item> 持ち物を足す・減らす / add / remove an item
    15 // goto <label> / end ほかの会話へ / おしまい / jump / the end
    16 #pragma once
    17  
    18 #include "text.hh"
    19  
    20 #include <optional>
    21 #include <string>
    22 #include <unordered_map>
    23 #include <vector>
    24  
    25 class World;
    26  
    27 // 画面に出す1ページ:話し手、文、選択肢 / one page on screen: speaker, text, options
    28 struct DialoguePage {
    29 Text speaker{};
    30 Text text{};
    31 struct Choice {
    32 Text label;
    33 std::string next; // 選んだら飛ぶ会話 / the conversation to jump to
    34 };
    35 std::vector<Choice> choices{};
    36 };
    37  
    38 class DialogueScript {
    39 public:
    40 // 読み込みと検査(知らない命令、enのないja、存在しないlabelへの飛び先…)。エラーは「ファイル:行: 説明」
    41 // Loads and checks (unknown commands, ja without en, jumps to labels that do not exist...). Errors are
    42 // "file:line: message"
    43 static std::optional<DialogueScript> load(const std::string &path);
    44 // 1ページだけの台本(拾った物のお知らせなど、コードで作る文) / a one-page script (e.g. "you found an item": text
    45 // made in code)
    46 static DialogueScript single(Text text, Text speaker = {});
    47 bool has(const std::string &label) const { return labels.contains(label); }
    48  
    49 private:
    50 friend class DialogueRunner;
    51 enum class Op { Name, Page, Choice, IfFlag, IfItem, Set, Clear, Give, Take, Goto, End };
    52 struct Command {
    53 Op op;
    54 Text text{}; // Name, Page, Choice
    55 std::string a{}, b{}; // flag/item名、飛び先 / flag or item name, jump target
    56 bool negate = false;
    57 int line = 0;
    58 };
    59 std::vector<Command> commands;
    60 std::unordered_map<std::string, size_t> labels;
    61 };
    62  
    63 // 台本を一つの会話のあいだ実行する:next()が次のページまで進め(途中のif・set・giveを実行)、
    64 // ページがなくなればfalse。選択肢はchoose()で選ぶ
    65 // Runs a script for one conversation: next() advances to the next page (executing the ifs, sets and gives on the way)
    66 // and returns false when there are no more pages. Options are picked with choose()
    67 class DialogueRunner {
    68 public:
    69 DialogueRunner(const DialogueScript &script, World &world, const std::string &label);
    70 bool next();
    71 bool choose(size_t option);
    72 const DialoguePage &page() const { return current; }
    73  
    74 private:
    75 bool jump(const std::string &label);
    76 const DialogueScript &script;
    77 World &world;
    78 size_t pc = 0;
    79 bool running = true;
    80 Text speaker;
    81 DialoguePage current;
    82 };

ファイル: /dev/null | b/games/rpg/src/dialogue_scene.cc

前新
@@ -0,0 +1,149 @@
    1 // 会話の箱:下のマップは描かれたまま止まる(isOverlay)。文字は一つずつ出る(タイプライター)
    2 // The dialogue box: the map below stays visible but frozen (isOverlay). Characters appear one by one (typewriter)
    3 #include "game.hh"
    4  
    5 #include <algorithm>
    6 #include <cmath>
    7  
    8 constexpr Rect kBox = {6.0f, 120.0f, 308.0f, 56.0f};
    9 constexpr float kTextWidth = 292.0f; // 箱の中の文の幅 / the width of text inside the box
    10 constexpr size_t kLines = 3; // 一度に見せる行 / lines shown at once
    11 constexpr float kLineHeight = 16.0f; // pixel12の行の高さ / pixel12's line height
    12  
    13 void drawPanel(SpriteBatch &b, const Rect &r, float alpha) {
    14 b.drawRect(r, {0.106f, 0.09f, 0.15f, 0.92f * alpha});
    15 b.drawRectOutline(r, {0.95f, 0.76f, 0.31f, alpha});
    16 b.drawRectOutline({r.x + 1.0f, r.y + 1.0f, r.w - 2.0f, r.h - 2.0f}, {0.24f, 0.2f, 0.35f, alpha});
    17 }
    18  
    19 Text Game::gotItem(const std::string &id) const {
    20 const ItemKind *kind = itemTable.find(id);
    21 Text name = kind ? kind->name : Text{id, id};
    22 return {name.ja + "を手に入れた!", "You found: " + name.en + "!"};
    23 }
    24  
    25 DialogueScene::DialogueScene(Game &game, const std::string &label)
    26 : g(game), runner(game.script, game.world, label) {}
    27  
    28 DialogueScene::DialogueScene(Game &game, Text message)
    29 : g(game), own(DialogueScript::single(std::move(message))), runner(*own, game.world, "message") {}
    30  
    31 void DialogueScene::enter() {
    32 done = !runner.next(); // 最初のページまで進める(途中のif・setも実行) / run up to the first page (ifs and sets on
    33 // the way are executed)
    34 if (!done) layout();
    35 }
    36  
    37 void DialogueScene::layout() {
    38 // ページを今の言語で折り返し、3行ずつのかたまりにする。長いページは自動で何回かに分かれる
    39 // Wrap the page in the current language and cut it into chunks of 3 lines: a long page is split automatically
    40 std::vector<std::string> lines = wrapText(g.pixel, g.tr(runner.page().text), kTextWidth);
    41 chunks.clear();
    42 for (size_t i = 0; i < lines.size(); i += kLines)
    43 chunks.emplace_back(lines.begin() + static_cast<std::ptrdiff_t>(i),
    44 lines.begin() + static_cast<std::ptrdiff_t>(std::min(lines.size(), i + kLines)));
    45 chunk = 0;
    46 shown = 0.0f;
    47 choice = 0;
    48 total = 0;
    49 for (const std::string &l : chunks[0]) total += charCount(l);
    50 }
    51  
    52 bool DialogueScene::showingChoices() const {
    53 return lastChunk() && shown >= static_cast<float>(total) && !runner.page().choices.empty();
    54 }
    55  
    56 void DialogueScene::update(float dt) {
    57 time += dt;
    58 if (done) {
    59 scenes().pop();
    60 return;
    61 }
    62 Input &in = g.input;
    63 if (in.pressed(GLFW_KEY_L)) {
    64 // 言語を変えたら折り返し直す(今のページを最初から全部見せる) / a language change re-wraps the page (shown in full
    65 // from its first chunk)
    66 g.world.language = g.world.language == Language::Ja ? Language::En : Language::Ja;
    67 layout();
    68 shown = static_cast<float>(total);
    69 return;
    70 }
    71 // 文字の速さ:日本語は1文字に情報が多いのでゆっくり / typing speed: slower for Japanese (more per character)
    72 float speed = g.world.language == Language::Ja ? 30.0f : 60.0f;
    73 shown = std::min(static_cast<float>(total), shown + speed * dt);
    74  
    75 if (showingChoices()) {
    76 int n = static_cast<int>(runner.page().choices.size());
    77 if (in.actionPressed("up")) choice = (choice + n - 1) % n;
    78 if (in.actionPressed("down")) choice = (choice + 1) % n;
    79 }
    80 if (!in.actionPressed("confirm")) return;
    81 if (shown < static_cast<float>(total)) {
    82 shown = static_cast<float>(total); // 途中なら全部出す / still typing: show everything
    83 return;
    84 }
    85 if (!lastChunk()) {
    86 ++chunk; // 同じページの次の3行 / the next 3 lines of the same page
    87 shown = 0.0f;
    88 total = 0;
    89 for (const std::string &l : chunks[chunk]) total += charCount(l);
    90 return;
    91 }
    92 // 次のページへ(選択肢があれば、選んだ会話へ飛んで) / to the next page (jumping to the chosen conversation, if
    93 // there are options)
    94 bool more = runner.page().choices.empty() ? runner.next() : runner.choose(static_cast<size_t>(choice));
    95 if (!more) {
    96 done = true;
    97 scenes().pop();
    98 return;
    99 }
    100 layout();
    101 }
    102  
    103 void DialogueScene::draw(float /*alpha*/) {
    104 if (done || chunks.empty()) return;
    105 SpriteBatch &b = g.batch;
    106 b.begin(canvasMatrix());
    107 drawPanel(b, kBox);
    108 // 話し手の名前の札 / the speaker's name tag
    109 const std::string &speaker = g.tr(runner.page().speaker);
    110 if (!speaker.empty()) {
    111 Vec2 size = g.pixel.measure(speaker);
    112 Rect tag = {kBox.x + 6.0f, kBox.y - 15.0f, size.x + 12.0f, 16.0f};
    113 drawPanel(b, tag);
    114 g.pixel.draw(b, speaker, {tag.x + 6.0f, tag.y + 1.0f}, {.color = hexColor(0xf2c14eff)});
    115 }
    116 // 出した文字の数だけ、行ごとに描く / draw line by line, only as many characters as have been shown
    117 size_t left = static_cast<size_t>(shown);
    118 float y = kBox.y + 4.0f;
    119 for (const std::string &line : chunks[chunk]) {
    120 size_t n = std::min(left, charCount(line));
    121 g.pixel.draw(b, firstChars(line, n), {kBox.x + 8.0f, y}, {.color = hexColor(0xfff4d6ff)});
    122 left -= n;
    123 y += kLineHeight;
    124 }
    125 // 「次へ」の印:全部出たら点滅する三角 / the "next" marker: a blinking triangle once everything is shown
    126 if (shown >= static_cast<float>(total) && !showingChoices() && std::fmod(time, 0.8f) < 0.5f) {
    127 float x = kBox.right() - 14.0f, ty = kBox.bottom() - 9.0f + std::round(std::sin(time * 6.0f));
    128 for (int i = 0; i < 3; ++i)
    129 b.drawRect({x + static_cast<float>(i), ty + static_cast<float>(i), 5.0f - 2.0f * static_cast<float>(i), 1.0f},
    130 hexColor(0xf2c14eff));
    131 }
    132 // 選択肢:箱の右上に別の箱、選んでいる物に「>」 / options: a second box above the right end, ">" marks the selection
    133 if (showingChoices()) {
    134 const auto &choices = runner.page().choices;
    135 float w = 0.0f;
    136 for (const auto &c : choices) w = std::max(w, g.pixel.measure(g.tr(c.label)).x);
    137 float h = kLineHeight * static_cast<float>(choices.size()) + 8.0f;
    138 Rect box = {kBox.right() - (w + 30.0f), kBox.y - h - 2.0f, w + 30.0f, h};
    139 drawPanel(b, box);
    140 for (size_t i = 0; i < choices.size(); ++i) {
    141 float cy = box.y + 4.0f + kLineHeight * static_cast<float>(i);
    142 bool sel = static_cast<int>(i) == choice;
    143 if (sel) g.pixel.draw(b, ">", {box.x + 7.0f, cy}, {.color = hexColor(0xf2c14eff)});
    144 g.pixel.draw(b, g.tr(choices[i].label), {box.x + 18.0f, cy},
    145 {.color = sel ? hexColor(0xfff4d6ff) : hexColor(0x9a96b0ff)});
    146 }
    147 }
    148 b.end();
    149 }

ファイル: a/games/rpg/src/game.hh | b/games/rpg/src/game.hh

前新
@@ -3,6 +3,10 @@
3 #pragma once 3 #pragma once
4   4  
5 #include "character.hh" 5 #include "character.hh"
    6 #include "dialogue.hh"
    7 #include "items.hh"
    8 #include "npc.hh"
    9 #include "text.hh"
6 #include "tile_renderer.hh" 10 #include "tile_renderer.hh"
7 #include "tilemap.hh" 11 #include "tilemap.hh"
8 #include "world.hh" 12 #include "world.hh"
@@ -11,10 +15,12 @@
11 #include "engine/font.hh" 15 #include "engine/font.hh"
12 #include "engine/game_loop.hh" 16 #include "engine/game_loop.hh"
13 #include "engine/input.hh" 17 #include "engine/input.hh"
    18 #include "engine/rng.hh"
14 #include "engine/scene.hh" 19 #include "engine/scene.hh"
15 #include "engine/sprite_batch.hh" 20 #include "engine/sprite_batch.hh"
16   21  
17 #include <array> 22 #include <array>
    23 #include <memory>
18 #include <optional> 24 #include <optional>
19 #include <string> 25 #include <string>
20 #include <vector> 26 #include <vector>
@@ -42,14 +48,29 @@ struct Game {
42 TileRenderer &tiles; // GPUの物は一つを使い回す(マップが変わったらbuildし直す) / one set of GPU objects, rebuilt 48 TileRenderer &tiles; // GPUの物は一つを使い回す(マップが変わったらbuildし直す) / one set of GPU objects, rebuilt
43 // when the map changes 49 // when the map changes
44 World &world; // マップの置き場と、残る状態 / the loaded maps and the persistent state 50 World &world; // マップの置き場と、残る状態 / the loaded maps and the persistent state
45 const Font &ui; // mono16:画面の解像度 / screen resolution 51 const Font &ui; // mono16:画面の解像度(HUD) / screen resolution (the HUD)
46 const Font &pixel; // pixel12:キャンバスの中 / inside the canvas 52 const Font &pixel; // ゲームのpixel12(会話の漢字入り):キャンバスの中 / the game's pixel12 (with the dialogue's
    53 // kanji): inside the canvas
47 const CharacterSheet &characters; 54 const CharacterSheet &characters;
    55 const SpriteSheet &items; // 持ち物のアイコン / item icons
    56 const AnimationClip &sparkle;
    57 const ItemTable &itemTable;
    58 const DialogueScript &script;
48 Camera2D screen; // 1280 × 720のUI / the 1280 × 720 UI 59 Camera2D screen; // 1280 × 720のUI / the 1280 × 720 UI
49 Viewport uiViewport; 60 Viewport uiViewport;
50 DebugView debug; 61 DebugView debug;
    62  
    63 // 今の言語で / in the current language
    64 const std::string &tr(const Text &t) const { return t.get(world.language); }
    65 // 「〜を手に入れた!」の文 / the "you got ...!" message
    66 Text gotItem(const std::string &id) const;
51 }; 67 };
52   68  
    69 // キャンバスの画面の座標(320 × 180)の行列 / the matrix for canvas screen coordinates (320 × 180)
    70 inline Mat4 canvasMatrix() { return Camera2D::screen(kView).matrix(); }
    71 // 枠付きの箱(会話・メニュー) / a framed box (dialogue, menus)
    72 void drawPanel(SpriteBatch &b, const Rect &r, float alpha = 1.0f);
    73  
53 // マップの上を歩くシーン。マップ1つにつき1つ作り、扉で次のマップのシーンに入れ替える 74 // マップの上を歩くシーン。マップ1つにつき1つ作り、扉で次のマップのシーンに入れ替える
54 // The scene where you walk around a map. One per map; a door replaces it with the next map's scene 75 // The scene where you walk around a map. One per map; a door replaces it with the next map's scene
55 class MapScene : public Scene { 76 class MapScene : public Scene {
@@ -59,26 +80,37 @@ public:
59 MapScene(Game &game, std::string mapName, std::string spawn); 80 MapScene(Game &game, std::string mapName, std::string spawn);
60 void enter() override; 81 void enter() override;
61 void pause() override; 82 void pause() override;
    83 void resume() override;
62 void update(float dt) override; 84 void update(float dt) override;
63 void draw(float alpha) override; 85 void draw(float alpha) override;
64 void drawUi(float alpha) override; 86 void drawUi(float alpha) override;
65   87  
66 private: 88 private:
67 // 宝箱:開いたかどうかはWorldの印(マップ名/宝箱名)に残る / a chest: whether it is open is a World flag 89 // 宝箱:開いたかどうかはWorldの印(マップ名/宝箱名) / a chest: whether it is open is a World flag (map name/chest
68 // (map name/chest name) 90 // name)
69 struct Chest { 91 struct Chest {
70 const MapObject *object; 92 const MapObject *object;
71 Rect box; 93 Rect box;
72 std::string flag; 94 std::string flag;
73 }; 95 };
    96 // 落ちている物:拾うとWorldの印が付き、もう出てこない / an item on the ground: picking it up sets a World flag, so it
    97 // never comes back
    98 struct Pickup {
    99 const MapObject *object;
    100 std::string item, flag;
    101 };
74 struct Popup { 102 struct Popup {
75 std::string text; 103 std::string text;
76 Vec2 position; 104 Vec2 position;
77 float life; 105 float life;
78 }; 106 };
79 void setUp(); // マップの物からシーンの物を作る / builds the scene's things from the map's objects 107 void setUp(); // マップの物からシーンの物を作る / builds the scene's things from the map's objects
    108 bool present(const MapObject &o) const; // if= / unless= の印を見る / checks the if= / unless= flags
    109 void collectBlockers(const Npc *except);
80 void interact(); 110 void interact();
    111 void talk(const std::string &label);
81 void checkWarps(); 112 void checkWarps();
    113 void checkPickups();
82 Rect facingProbe() const; 114 Rect facingProbe() const;
83 Camera2D followCamera(Vec2 target) const; 115 Camera2D followCamera(Vec2 target) const;
84   116  
@@ -86,13 +118,75 @@ private:
86 std::string mapName, spawnName; 118 std::string mapName, spawnName;
87 Tilemap *map = nullptr; // Worldの中(読み直しても同じ場所) / inside World (same address across reloads) 119 Tilemap *map = nullptr; // Worldの中(読み直しても同じ場所) / inside World (same address across reloads)
88 Character hero; 120 Character hero;
    121 std::vector<Npc> npcs;
89 std::vector<Chest> chests; 122 std::vector<Chest> chests;
90 std::vector<Rect> blockers; // 固い物(宝箱)の箱 / boxes of solid objects (chests) 123 std::vector<Pickup> pickups;
    124 std::vector<Rect> blockers; // 固い物(宝箱・門・人)の箱 / boxes of solid things (chests, gates, people)
91 std::vector<Popup> popups; 125 std::vector<Popup> popups;
92 std::vector<Rect> scratch; // 当たり判定の箱の作業用 / scratch boxes for collision 126 std::vector<Rect> scratch; // 当たり判定の箱の作業用 / scratch boxes for collision
    127 Rng rng{35}; // 人の歩き方(マップごとに種を決める) / how people stroll (seeded per map)
93 float time = 0.0f; 128 float time = 0.0f;
94 bool warpArmed = false; // 出発点が扉の上でも、一度離れるまで扉は効かない / doors only work after the hero has 129 bool warpArmed = false; // 出発点が扉の上でも、一度離れるまで扉は効かない / doors only work after the hero has
95 // stepped off all of them once (in case a spawn point is on a door) 130 // stepped off all of them once (in case a spawn point is on a door)
96 bool leaving = false; // 扉に入った:フェードが終わるまで動かない / entered a door: frozen until the fade ends 131 bool leaving = false; // 扉に入った:フェードが終わるまで動かない / entered a door: frozen until the fade ends
    132 bool covered = false; // 会話・持ち物の画面が上にある(HUDの帯を隠す) / a dialogue or the inventory is on top
    133 // (hide the HUD bars)
97 int rowFirst = 0, rowLast = 0, spriteCalls = 0; 134 int rowFirst = 0, rowLast = 0, spriteCalls = 0;
98 }; 135 };
    136  
    137 // 会話の箱(上に重ねるシーン):タイプライターの文字、折り返し、次へ(▼)と選択肢
    138 // The dialogue box (an overlay scene): typewriter text, word wrapping, a "next" marker (▼) and options
    139 class DialogueScene : public Scene {
    140 public:
    141 DialogueScene(Game &game, const std::string &label); // dialogue.txtの会話 / a conversation from dialogue.txt
    142 DialogueScene(Game &game, Text message); // コードで作った1ページ / one page made in code
    143 bool isOverlay() const override { return true; }
    144 void enter() override;
    145 void update(float dt) override;
    146 void draw(float alpha) override;
    147  
    148 private:
    149 void layout(); // 今のページを今の言語で折り返し、3行ずつに分ける / wrap the page in the current language, in
    150 // chunks of 3 lines
    151 bool lastChunk() const { return chunk + 1 >= chunks.size(); }
    152 bool showingChoices() const;
    153  
    154 Game &g;
    155 std::optional<DialogueScript> own; // single()の台本はシーンが持つ / a single() script is owned by the scene
    156 DialogueRunner runner;
    157 bool done = false;
    158 std::vector<std::vector<std::string>> chunks; // ページ → 3行ずつ / the page → groups of 3 lines
    159 size_t chunk = 0;
    160 float shown = 0.0f; // 出した文字の数(小数:速さ × 時間) / characters shown (fractional: speed × time)
    161 size_t total = 0; // このかたまりの文字の数 / characters in this chunk
    162 int choice = 0;
    163 float time = 0.0f;
    164 };
    165  
    166 // 持ち物の画面(上に重ねるシーン) / the inventory screen (an overlay scene)
    167 class InventoryScene : public Scene {
    168 public:
    169 explicit InventoryScene(Game &game) : g(game) {}
    170 bool isOverlay() const override { return true; }
    171 void update(float dt) override;
    172 void draw(float alpha) override;
    173  
    174 private:
    175 Game &g;
    176 int selected = 0;
    177 float time = 0.0f;
    178 };
    179  
    180 // タイトル:言語を選んで始める / the title: choose the language and start
    181 class TitleScene : public Scene {
    182 public:
    183 explicit TitleScene(Game &game) : g(game) {}
    184 void update(float dt) override;
    185 void draw(float alpha) override;
    186 void drawUi(float alpha) override;
    187  
    188 private:
    189 Game &g;
    190 float time = 0.0f;
    191 bool starting = false;
    192 };

ファイル: /dev/null | b/games/rpg/src/inventory_scene.cc

前新
@@ -0,0 +1,69 @@
    1 // 持ち物の画面:Worldの持ち物を、アイコン・名前・数・説明で見せる(上に重ねるシーン)
    2 // The inventory screen: shows World's items with icon, name, count and description (an overlay scene)
    3 #include "game.hh"
    4  
    5 #include <algorithm>
    6  
    7 constexpr Rect kPanel = {30.0f, 6.0f, 260.0f, 168.0f};
    8  
    9 void InventoryScene::update(float dt) {
    10 time += dt;
    11 Input &in = g.input;
    12 if (in.pressed(GLFW_KEY_I) || in.pressed(GLFW_KEY_ESCAPE) || in.pressed(GLFW_KEY_BACKSPACE)) {
    13 scenes().pop();
    14 return;
    15 }
    16 if (in.pressed(GLFW_KEY_L)) g.world.language = g.world.language == Language::Ja ? Language::En : Language::Ja;
    17 int n = static_cast<int>(g.world.items().size());
    18 if (n > 0) {
    19 if (in.actionPressed("up")) selected = (selected + n - 1) % n;
    20 if (in.actionPressed("down")) selected = (selected + 1) % n;
    21 }
    22 selected = std::clamp(selected, 0, std::max(0, n - 1));
    23 }
    24  
    25 void InventoryScene::draw(float /*alpha*/) {
    26 SpriteBatch &b = g.batch;
    27 bool ja = g.world.language == Language::Ja;
    28 b.begin(canvasMatrix());
    29 b.drawRect({0.0f, 0.0f, kView.x, kView.y}, {0.03f, 0.02f, 0.06f, std::min(1.0f, time / 0.15f) * 0.5f});
    30 drawPanel(b, kPanel);
    31 g.pixel.draw(b, ja ? "持ち物 (I: とじる)" : "Items (I: close)", {kPanel.x + 10.0f, kPanel.y + 5.0f},
    32 {.color = hexColor(0xf2c14eff)});
    33 if (g.world.gold > 0) {
    34 char gold[32];
    35 snprintf(gold, sizeof gold, "%d G", g.world.gold);
    36 g.pixel.draw(b, gold, {kPanel.right() - 10.0f, kPanel.y + 5.0f}, {.color = hexColor(0xf2c14eff), .align = TextAlign::Right});
    37 }
    38 b.drawRect({kPanel.x + 6.0f, kPanel.y + 21.0f, kPanel.w - 12.0f, 1.0f}, hexColor(0x3d3459ff));
    39  
    40 const auto &items = g.world.items();
    41 if (items.empty())
    42 g.pixel.draw(b, ja ? "何も持っていない。" : "You have nothing.", {kPanel.x + 12.0f, kPanel.y + 30.0f},
    43 {.color = hexColor(0x9a96b0ff)});
    44 float y = kPanel.y + 26.0f;
    45 for (size_t i = 0; i < items.size(); ++i, y += 17.0f) {
    46 const ItemKind *kind = g.itemTable.find(items[i].first);
    47 bool sel = static_cast<int>(i) == selected;
    48 if (sel) b.drawRect({kPanel.x + 6.0f, y - 1.0f, kPanel.w - 12.0f, 17.0f}, hexColor(0x3d3459ff));
    49 if (kind) b.draw(g.items.sprite(kind->sprite, {kPanel.x + 10.0f, y}));
    50 g.pixel.draw(b, kind ? g.tr(kind->name) : items[i].first, {kPanel.x + 30.0f, y + 2.0f},
    51 {.color = sel ? hexColor(0xfff4d6ff) : hexColor(0xc8cce0ff)});
    52 g.pixel.draw(b, "×" + std::to_string(items[i].second), {kPanel.right() - 10.0f, y + 2.0f},
    53 {.color = hexColor(0xc8cce0ff), .align = TextAlign::Right});
    54 }
    55 // 選んだ物の説明(折り返し) / the selected item's description (wrapped)
    56 if (!items.empty()) {
    57 const ItemKind *kind = g.itemTable.find(items[static_cast<size_t>(selected)].first);
    58 Rect info = {kPanel.x + 6.0f, kPanel.bottom() - 54.0f, kPanel.w - 12.0f, 50.0f};
    59 b.drawRect(info, hexColor(0x241f33ff));
    60 if (kind) {
    61 float ly = info.y + 2.0f;
    62 for (const std::string &line : wrapText(g.pixel, g.tr(kind->info), info.w - 8.0f)) {
    63 g.pixel.draw(b, line, {info.x + 4.0f, ly}, {.color = hexColor(0xc8cce0ff)});
    64 ly += 16.0f;
    65 }
    66 }
    67 }
    68 b.end();
    69 }

ファイル: /dev/null | b/games/rpg/src/items.cc

前新
@@ -0,0 +1,51 @@
    1 #include "items.hh"
    2  
    3 #include "engine/file_util.hh"
    4  
    5 #include <cstdio>
    6 #include <sstream>
    7  
    8 std::optional<ItemTable> ItemTable::load(const std::string &path) {
    9 std::optional<std::string> text = readTextFile(path);
    10 if (!text) {
    11 fprintf(stderr, "%s: 読めない / cannot read\n", path.c_str());
    12 return std::nullopt;
    13 }
    14 ItemTable table;
    15 std::istringstream lines(*text);
    16 std::string line;
    17 int number = 0;
    18 while (std::getline(lines, line)) {
    19 ++number;
    20 if (!line.empty() && line.back() == '\r') line.pop_back();
    21 std::istringstream in(line);
    22 std::string command;
    23 if (!(in >> command) || command[0] == '#') continue;
    24 std::string rest;
    25 if (command == "item") {
    26 ItemKind kind;
    27 if (!(in >> kind.id >> kind.icon)) {
    28 fprintf(stderr, "%s:%d: item <id> <icon> <日本語> | <English>\n", path.c_str(), number);
    29 return std::nullopt;
    30 }
    31 std::getline(in >> std::ws, rest);
    32 kind.name = splitPair(rest);
    33 table.items.push_back(std::move(kind));
    34 } else if (command == "info" && !table.items.empty()) {
    35 std::string language;
    36 in >> language;
    37 std::getline(in >> std::ws, rest);
    38 (language == "ja" ? table.items.back().info.ja : table.items.back().info.en) = rest;
    39 } else {
    40 fprintf(stderr, "%s:%d: 知らない命令 / unknown command: %s\n", path.c_str(), number, command.c_str());
    41 return std::nullopt;
    42 }
    43 }
    44 return table;
    45 }
    46  
    47 const ItemKind *ItemTable::find(const std::string &id) const {
    48 for (const ItemKind &k : items)
    49 if (k.id == id) return &k;
    50 return nullptr;
    51 }

ファイル: /dev/null | b/games/rpg/src/items.hh

前新
@@ -0,0 +1,27 @@
    1 // 持ち物の種類(第35章):games/rpg/assets/items.txt から / item kinds (chapter 35): from games/rpg/assets/items.txt
    2 // item <id> <アイコン / icon sprite in items.atlas> <日本語の名前> | <English name>
    3 // info ja <説明> / info en <description> 直前のitemの説明 / the description of the item above
    4 #pragma once
    5  
    6 #include "text.hh"
    7  
    8 #include <optional>
    9 #include <string>
    10 #include <vector>
    11  
    12 struct ItemKind {
    13 std::string id;
    14 std::string icon;
    15 int sprite = -1; // items.atlasの番号(mainで引く) / index in items.atlas (looked up in main)
    16 Text name, info;
    17 };
    18  
    19 class ItemTable {
    20 public:
    21 static std::optional<ItemTable> load(const std::string &path);
    22 const ItemKind *find(const std::string &id) const;
    23 std::vector<ItemKind> &kinds() { return items; }
    24  
    25 private:
    26 std::vector<ItemKind> items;
    27 };

ファイル: a/games/rpg/src/main.cc | b/games/rpg/src/main.cc

前新
@@ -1,12 +1,13 @@
1 // 第34章:見下ろし型RPG(2)いくつものマップ、扉と出口、フェードでのシーンの切り替え、ファイルからのマップ 1 // 第35章:見下ろし型RPG(3)村の人、会話の箱、持ち物、小さなクエスト(二か国語)
2 // Chapter 34: a top-down RPG (2) several maps, doors and exits, scene switching with fades, maps loaded from files 2 // Chapter 35: a top-down RPG (3) villagers, dialogue boxes, items and an inventory, a tiny quest (bilingual)
3 // 3 //
4 // 操作 / Controls: 4 // 操作 / Controls:
5 // 矢印 / WASD 移動 / move Shift 走る / run Space / Enter 調べる(宝箱) / check (chests) 5 // タイトル / title ← → 言語 / language Space / Enter はじめる / start Esc 終了 / quit
6 // 1 2 3 層の表示 / toggle layers (ground, decor, overlay) 6 // マップ / map 矢印 / WASD 移動 / move Shift 走る / run Space / Enter 話す・調べる / talk, check
7 // B 当たり判定の箱 / collision boxes Z 引いて見る(カリングの確認) / zoom out (shows culling) 7 // I 持ち物 / items L 日本語 ⇔ English
8 // H HUDの表示 / toggle the HUD 8 // 1 2 3 層 / layers B 当たり判定 / boxes Z 引いて見る / zoom out H HUD R 読み直す / reload
9 // R マップをファイルから読み直す / reload the map from its file Esc 終了 / quit 9 // Esc 終了 / quit
    10 // 会話 / dialogue Space / Enter 次へ(途中なら全部出す) / next (or show the rest) ↑ ↓ 選ぶ / choose L 言語
10 // 11 //
11 // 実行はプロジェクトのルートから / run from the project root: ./build/games/rpg/rpg 12 // 実行はプロジェクトのルートから / run from the project root: ./build/games/rpg/rpg
12 #include "game.hh" 13 #include "game.hh"
@@ -25,12 +26,27 @@ int main() {
25 std::optional<SpriteBatch> batch = SpriteBatch::create(); 26 std::optional<SpriteBatch> batch = SpriteBatch::create();
26 std::optional<TileRenderer> tiles = TileRenderer::create(); 27 std::optional<TileRenderer> tiles = TileRenderer::create();
27 std::optional<Font> ui = Font::load("assets/fonts/mono16.fnt"); 28 std::optional<Font> ui = Font::load("assets/fonts/mono16.fnt");
28 std::optional<Font> pixel = Font::load("assets/fonts/pixel12.fnt", TextureFilter::Nearest); 29 // 会話の文字はゲームのフォント:共有のpixel12と同じ作りで、会話に出る漢字を足したもの(自作スクリプトで生成)
    30 // Dialogue text uses the game's own font: built like the shared pixel12, plus the kanji the dialogue uses
    31 // (generated by the author's own script)
    32 std::optional<Font> pixel = Font::load("games/rpg/assets/fonts/pixel12.fnt", TextureFilter::Nearest);
29 std::optional<CharacterSheet> characters = CharacterSheet::load("games/rpg/assets/characters.png"); 33 std::optional<CharacterSheet> characters = CharacterSheet::load("games/rpg/assets/characters.png");
30 // マップは使うときにWorldが読む(最初の村だけ、ここで読めるか確かめる) / World loads maps when they are first 34 std::optional<SpriteSheet> items = SpriteSheet::loadAtlas("games/rpg/assets/items.atlas");
31 // needed (only the first one, the village, is checked here) 35 std::optional<ItemTable> itemTable = ItemTable::load("games/rpg/assets/items.txt");
    36 std::optional<DialogueScript> script = DialogueScript::load("games/rpg/assets/dialogue.txt");
32 World world; 37 World world;
33 if (!batch || !tiles || !ui || !pixel || !characters || !world.map("village")) return 1; 38 if (!batch || !tiles || !ui || !pixel || !characters || !items || !itemTable || !script || !world.map("village"))
    39 return 1;
    40 const AnimationClip *sparkle = items->clip("sparkle");
    41 if (!sparkle) return 1;
    42 for (ItemKind &k : itemTable->kinds()) {
    43 k.sprite = items->find(k.icon);
    44 if (k.sprite < 0) {
    45 fprintf(stderr, "items.txt: %s のアイコン %s がない / icon %s not in items.atlas\n", k.id.c_str(), k.icon.c_str(),
    46 k.icon.c_str());
    47 return 1;
    48 }
    49 }
34   50  
35 Input input; 51 Input input;
36 input.attach(window); 52 input.attach(window);
@@ -44,13 +60,13 @@ int main() {
44 GameLoop loop({.step = 1.0 / 60.0, .maxSteps = 5}); 60 GameLoop loop({.step = 1.0 / 60.0, .maxSteps = 5});
45 PixelCanvas canvas(static_cast<int>(kView.x), static_cast<int>(kView.y)); 61 PixelCanvas canvas(static_cast<int>(kView.x), static_cast<int>(kView.y));
46 Game game{.window = window, .input = input, .loop = loop, .batch = *batch, .tiles = *tiles, .world = world, .ui = *ui, 62 Game game{.window = window, .input = input, .loop = loop, .batch = *batch, .tiles = *tiles, .world = world, .ui = *ui,
47 .pixel = *pixel, .characters = *characters, .screen = Camera2D::screen({1280.0f, 720.0f}), 63 .pixel = *pixel, .characters = *characters, .items = *items, .sparkle = *sparkle, .itemTable = *itemTable,
48 .uiViewport = {}, .debug = {}}; 64 .script = *script, .screen = Camera2D::screen({1280.0f, 720.0f}), .uiViewport = {}, .debug = {}};
49   65  
50 SceneManager scenes; 66 SceneManager scenes;
51 // 黒から明るくなって始まる(空のスタックへのpushもフェードできる) / starts by fading in from black (a push onto the 67 // 黒から明るくなって始まる(空のスタックへのpushもフェードできる) / starts by fading in from black (a push onto the
52 // empty stack can fade too) 68 // empty stack can fade too)
53 scenes.push(std::make_unique<MapScene>(game, "village", "start"), kMapFade); 69 scenes.push(std::make_unique<TitleScene>(game), kMapFade);
54   70  
55 loop.run( 71 loop.run(
56 window, input, 72 window, input,
@@ -59,12 +75,12 @@ int main() {
59 if (scenes.empty()) window.close(); 75 if (scenes.empty()) window.close();
60 }, 76 },
61 [&](float alpha) { 77 [&](float alpha) {
62 // 1. 世界:320 × 180のキャンバスに描き、整数倍で画面へ / 1. the world: into the 320 × 180 canvas, then scaled 78 // 1. 世界:320 × 180のキャンバスに描き、整数倍で画面へ(会話・持ち物の箱もキャンバスの中) / 1. the world: into
63 // by a whole number onto the screen 79 // the 320 × 180 canvas, then scaled by a whole number onto the screen (dialogue and menus are in the canvas)
64 canvas.begin(hexColor(0x1b1726ff)); 80 canvas.begin(hexColor(0x1b1726ff));
65 scenes.draw(alpha); 81 scenes.draw(alpha);
66 canvas.present(window.width(), window.height()); 82 canvas.present(window.width(), window.height());
67 // 2. UI:1280 × 720の文字 / 2. the UI: text at 1280 × 720 83 // 2. UI:1280 × 720の文字(HUD) / 2. the UI: text at 1280 × 720 (the HUD)
68 game.uiViewport = letterbox(window.width(), window.height(), game.screen.viewSize, false); 84 game.uiViewport = letterbox(window.width(), window.height(), game.screen.viewSize, false);
69 game.uiViewport.apply(); 85 game.uiViewport.apply();
70 scenes.drawUi(alpha); 86 scenes.drawUi(alpha);

ファイル: a/games/rpg/src/map_scene.cc | b/games/rpg/src/map_scene.cc

前新
@@ -1,6 +1,8 @@
1 // マップのシーン:主人公を歩かせ、カメラで追い、層の順にタイルと人物を描く。扉で別のマップへ(フェード付き) 1 // マップのシーン:主人公を歩かせ、カメラで追い、層の順にタイルと人物を描く。扉で別のマップへ(フェード付き)。
    2 // 第35章:村の人、落ちている物、門、看板。話しかけると会話のシーンを上に載せる
2 // The map scene: walks the hero around, follows it with the camera, draws tiles and characters in layer order. Doors 3 // The map scene: walks the hero around, follows it with the camera, draws tiles and characters in layer order. Doors
3 // lead to other maps (with a fade) 4 // lead to other maps (with a fade). Chapter 35: villagers, items on the ground, gates, signs. Talking pushes the
    5 // dialogue scene on top
4 #include "game.hh" 6 #include "game.hh"
5   7  
6 #include "engine/collision.hh" 8 #include "engine/collision.hh"
@@ -8,6 +10,7 @@
8 #include <algorithm> 10 #include <algorithm>
9 #include <cmath> 11 #include <cmath>
10 #include <cstdio> 12 #include <cstdio>
    13 #include <cstdint>
11 #include <memory> 14 #include <memory>
12   15  
13 constexpr float kWalkSpeed = 72.0f; // ピクセル毎秒(4.5マス/秒) / pixels per second (4.5 tiles/s) 16 constexpr float kWalkSpeed = 72.0f; // ピクセル毎秒(4.5マス/秒) / pixels per second (4.5 tiles/s)
@@ -21,9 +24,26 @@ void MapScene::enter() {
21 // マップはWorldから(初めてならファイルを読む)。扉は入る前に読めることを確かめてある 24 // マップはWorldから(初めてならファイルを読む)。扉は入る前に読めることを確かめてある
22 // The map comes from World (loaded from its file the first time). Doors check that it loads before switching 25 // The map comes from World (loaded from its file the first time). Doors check that it loads before switching
23 map = g.world.map(mapName); 26 map = g.world.map(mapName);
    27 // 人の動きの乱数はマップの名前から種を作る(FNV-1a):同じ入力なら毎回、どの環境でも同じ動き。
    28 // std::hashは標準ライブラリごとに値が違うので使わない(Rngの<random>の分布と同じ理由)
    29 // The villagers' random numbers are seeded from the map's name (FNV-1a): the same input gives the same movement
    30 // every time, on every platform. std::hash differs between standard libraries, so it is not used (the same reason
    31 // as for <random>'s distributions and Rng)
    32 std::uint32_t seed = 2166136261u;
    33 for (char c : mapName) seed = (seed ^ static_cast<unsigned char>(c)) * 16777619u;
    34 rng.seed(seed);
24 setUp(); 35 setUp();
25 } 36 }
26   37  
    38 // if=<印> なら印があるときだけ、unless=<印> なら印がないときだけ、その物はある
    39 // With if=<flag> the object exists only while the flag is set, with unless=<flag> only while it is not
    40 bool MapScene::present(const MapObject &o) const {
    41 std::string_view need = o.get("if"), avoid = o.get("unless");
    42 if (!need.empty() && !g.world.flag(std::string(need))) return false;
    43 if (!avoid.empty() && g.world.flag(std::string(avoid))) return false;
    44 return true;
    45 }
    46  
27 void MapScene::setUp() { 47 void MapScene::setUp() {
28 g.tiles.build(*map); // 静的な頂点バッファを作る(マップに入るたびに一度) / build the static vertex buffer (once per 48 g.tiles.build(*map); // 静的な頂点バッファを作る(マップに入るたびに一度) / build the static vertex buffer (once per
29 // visit) 49 // visit)
@@ -35,27 +55,61 @@ void MapScene::setUp() {
35 } 55 }
36 hero.look = 0; 56 hero.look = 0;
37 hero.placeAt(start ? start->rect.position() : Vec2{kTile, kTile}); 57 hero.placeAt(start ? start->rect.position() : Vec2{kTile, kTile});
38 std::string_view face = start ? start->get("face", "down") : "down"; 58 hero.facing = parseFacing(start ? start->get("face", "down") : "down");
39 hero.facing = face == "up" ? Facing::Up : face == "left" ? Facing::Left : face == "right" ? Facing::Right : Facing::Down;    
40 // 最初のフレームは更新なしで描かれる:今のうちに立ちのクリップを選んでおく / the first frame is drawn before any 59 // 最初のフレームは更新なしで描かれる:今のうちに立ちのクリップを選んでおく / the first frame is drawn before any
41 // update: pick the standing clip now 60 // update: pick the standing clip now
42 hero.animate(g.characters, 0.0f); 61 hero.animate(g.characters, 0.0f);
43   62  
44 // 宝箱:開いたかどうかはWorldに残っている(マップ名/宝箱名) / chests: whether they are open is kept in World 63 // 人はマップのファイルの通りに置き直す(シーンの中の物:戻ってくると元の場所) / people are placed as the map file says
45 // (map name/chest name) 64 // (they belong to the scene: when you come back they are at their starting spots)
46 chests.clear(); 65 chests.clear();
47 blockers.clear(); 66 pickups.clear();
48 for (const MapObject &o : map->objects()) 67 npcs.clear();
49 if (o.kind == "chest") { 68 for (const MapObject &o : map->objects()) {
50 Rect box = {o.rect.x + 1.0f, o.rect.y + 4.0f, 14.0f, 12.0f}; 69 if (o.kind == "chest") chests.push_back({&o, {o.rect.x + 1.0f, o.rect.y + 4.0f, 14.0f, 12.0f}, mapName + "/" + o.name});
51 chests.push_back({&o, box, mapName + "/" + o.name}); 70 if (o.kind == "item") pickups.push_back({&o, std::string(o.get("item", o.name)), mapName + "/" + o.name});
52 blockers.push_back(box); 71 if (o.kind == "npc" && present(o)) npcs.push_back(Npc::fromObject(o));
53 } 72 }
    73 for (Npc &n : npcs) n.body.animate(g.characters, 0.0f); // 人も同じ / people too
54 warpArmed = false; 74 warpArmed = false;
55 leaving = false; 75 leaving = false;
56 } 76 }
57   77  
58 void MapScene::pause() { hero.previous = hero.box.position(); } 78 void MapScene::pause() {
    79 // 会話や持ち物の画面が上に載った:補間で震えないよう、前の位置 = 今の位置 / a dialogue or the inventory went on top:
    80 // previous = current so nothing shakes with the interpolation
    81 hero.previous = hero.box.position();
    82 for (Npc &n : npcs) n.body.previous = n.body.box.position();
    83 covered = true;
    84 }
    85  
    86 void MapScene::resume() {
    87 covered = false;
    88 // 会話で印が変わったかもしれない(門が開いた…):印で出たり消えたりする人を置き直す。門・宝箱・落ちている物は
    89 // present()を毎回見るので、そのままで変わる
    90 // The dialogue may have changed flags (the gate opened...): re-check people that depend on flags. Gates, chests and
    91 // items on the ground check present() every time, so they change by themselves
    92 std::erase_if(npcs, [&](const Npc &n) { return !present(*n.object); });
    93 for (const MapObject &o : map->objects())
    94 if (o.kind == "npc" && present(o) &&
    95 std::none_of(npcs.begin(), npcs.end(), [&](const Npc &n) { return n.object == &o; }))
    96 npcs.push_back(Npc::fromObject(o));
    97 // 新しく出た人は更新の前に描かれる:クリップを選んでおく(今いる人はそのまま) / people who just appeared are drawn
    98 // before their first update: pick their clip (the others keep theirs)
    99 for (Npc &n : npcs) n.body.animate(g.characters, 0.0f);
    100 }
    101  
    102 // 固い物の箱(宝箱・閉じた門・人)。exceptの人は除く(自分自身とはぶつからない) / boxes of solid things (chests,
    103 // closed gates, people), without `except` (nobody collides with themselves)
    104 void MapScene::collectBlockers(const Npc *except) {
    105 blockers.clear();
    106 for (const Chest &c : chests)
    107 if (present(*c.object)) blockers.push_back(c.box);
    108 for (const MapObject &o : map->objects())
    109 if (o.kind == "gate" && present(o)) blockers.push_back(o.rect);
    110 for (const Npc &n : npcs)
    111 if (&n != except) blockers.push_back(n.body.box);
    112 }
59   113  
60 // 顔の前の小さな箱:これに触れる物を調べる / a small box in front of the face: things touching it can be checked 114 // 顔の前の小さな箱:これに触れる物を調べる / a small box in front of the face: things touching it can be checked
61 Rect MapScene::facingProbe() const { 115 Rect MapScene::facingProbe() const {
@@ -70,15 +124,56 @@ Rect MapScene::facingProbe() const {
70 return b; 124 return b;
71 } 125 }
72   126  
    127 void MapScene::talk(const std::string &label) {
    128 printf("%s: 会話 / talk @%s\n", mapName.c_str(), label.c_str());
    129 scenes().push(std::make_unique<DialogueScene>(g, label)); // フェードなし、上に重ねる / no fade, an overlay
    130 }
    131  
73 void MapScene::interact() { 132 void MapScene::interact() {
74 Rect probe = facingProbe(); 133 Rect probe = facingProbe();
    134 // 人:こちらを向かせてから話す / people: make them face the hero, then talk
    135 for (Npc &n : npcs)
    136 if (overlaps(probe, n.body.box)) {
    137 n.faceTowards(hero.facing);
    138 // 会話の間はマップが更新されないので、新しい向きの絵を今選ぶ / the map is not updated during the dialogue, so
    139 // pick the picture for the new facing now
    140 n.body.animate(g.characters, 0.0f);
    141 talk(n.say);
    142 return;
    143 }
75 for (const Chest &c : chests) { 144 for (const Chest &c : chests) {
76 if (!overlaps(probe, c.box) || g.world.flag(c.flag)) continue; 145 if (!present(*c.object) || !overlaps(probe, c.box)) continue;
    146 if (g.world.flag(c.flag)) return; // もう空 / already empty
77 g.world.setFlag(c.flag); // マップを出ても開いたまま / stays open after leaving the map 147 g.world.setFlag(c.flag); // マップを出ても開いたまま / stays open after leaving the map
78 int gold = c.object->getInt("gold", 0); 148 if (std::string item(c.object->get("item")); !item.empty()) {
79 g.world.gold += gold; 149 g.world.addItem(item);
80 popups.push_back({"+" + std::to_string(gold) + " G", {c.box.centre().x, c.box.y - 10.0f}, 1.2f}); 150 printf("%s: 開けた / opened (%s)\n", c.flag.c_str(), item.c_str());
81 printf("%s: 開けた / opened (+%d G, %d G)\n", c.flag.c_str(), gold, g.world.gold); 151 scenes().push(std::make_unique<DialogueScene>(g, g.gotItem(item)));
    152 } else {
    153 int gold = c.object->getInt("gold", 0);
    154 g.world.gold += gold;
    155 popups.push_back({"+" + std::to_string(gold) + " G", {c.box.centre().x, c.box.y - 10.0f}, 1.2f});
    156 printf("%s: 開けた / opened (+%d G, %d G)\n", c.flag.c_str(), gold, g.world.gold);
    157 }
    158 return;
    159 }
    160 // 看板・鍵のかかった扉・門:sayの会話 / signs, locked doors, gates: the `say` conversation
    161 for (const MapObject &o : map->objects())
    162 if ((o.kind == "sign" || o.kind == "gate") && present(o) && overlaps(probe, o.rect)) {
    163 talk(std::string(o.get("say", o.name)));
    164 return;
    165 }
    166 }
    167  
    168 void MapScene::checkPickups() {
    169 for (const Pickup &p : pickups) {
    170 if (g.world.flag(p.flag) || !present(*p.object)) continue;
    171 Rect box = Rect::fromCentre(p.object->rect.centre(), {10.0f, 10.0f});
    172 if (!overlaps(hero.box, box)) continue;
    173 g.world.setFlag(p.flag);
    174 g.world.addItem(p.item);
    175 printf("%s: 拾った / picked up %s\n", p.flag.c_str(), p.item.c_str());
    176 scenes().push(std::make_unique<DialogueScene>(g, g.gotItem(p.item)));
82 return; 177 return;
83 } 178 }
84 } 179 }
@@ -86,7 +181,7 @@ void MapScene::interact() {
86 void MapScene::checkWarps() { 181 void MapScene::checkWarps() {
87 bool onWarp = false; 182 bool onWarp = false;
88 for (const MapObject &o : map->objects()) { 183 for (const MapObject &o : map->objects()) {
89 if ((o.kind != "door" && o.kind != "warp") || !overlaps(hero.box, o.rect)) continue; 184 if ((o.kind != "door" && o.kind != "warp") || !present(o) || !overlaps(hero.box, o.rect)) continue;
90 onWarp = true; 185 onWarp = true;
91 if (!warpArmed) continue; 186 if (!warpArmed) continue;
92 std::string target(o.get("map")), spawn(o.get("spawn", "start")); 187 std::string target(o.get("map")), spawn(o.get("spawn", "start"));
@@ -105,6 +200,7 @@ void MapScene::checkWarps() {
105 leaving = true; 200 leaving = true;
106 hero.moving = false; 201 hero.moving = false;
107 hero.previous = hero.box.position(); // 止める:フェードの間は更新されない / freeze: no updates during the fade 202 hero.previous = hero.box.position(); // 止める:フェードの間は更新されない / freeze: no updates during the fade
    203 for (Npc &n : npcs) n.body.previous = n.body.box.position();
108 return; 204 return;
109 } 205 }
110 if (!onWarp) warpArmed = true; // 扉から離れた:次に触れた扉は効く / off every door: the next one works 206 if (!onWarp) warpArmed = true; // 扉から離れた:次に触れた扉は効く / off every door: the next one works
@@ -124,6 +220,12 @@ void MapScene::update(float dt) {
124 if (in.pressed(GLFW_KEY_H)) dbg.hud = !dbg.hud; 220 if (in.pressed(GLFW_KEY_H)) dbg.hud = !dbg.hud;
125 for (int i = 0; i < 3; ++i) 221 for (int i = 0; i < 3; ++i)
126 if (in.pressed(GLFW_KEY_1 + i)) dbg.layers[static_cast<size_t>(i)] = !dbg.layers[static_cast<size_t>(i)]; 222 if (in.pressed(GLFW_KEY_1 + i)) dbg.layers[static_cast<size_t>(i)] = !dbg.layers[static_cast<size_t>(i)];
    223 if (in.pressed(GLFW_KEY_L))
    224 g.world.language = g.world.language == Language::Ja ? Language::En : Language::Ja;
    225 if (in.pressed(GLFW_KEY_I)) {
    226 scenes().push(std::make_unique<InventoryScene>(g));
    227 return;
    228 }
127 if (in.pressed(GLFW_KEY_R) && g.world.reload(mapName)) { 229 if (in.pressed(GLFW_KEY_R) && g.world.reload(mapName)) {
128 // ファイルから読み直す。物のポインターが変わるので作り直し、主人公は今の場所に戻す 230 // ファイルから読み直す。物のポインターが変わるので作り直し、主人公は今の場所に戻す
129 // Reload from the file. Object pointers change, so rebuild them; the hero goes back to where it was 231 // Reload from the file. Object pointers change, so rebuild them; the hero goes back to where it was
@@ -136,11 +238,12 @@ void MapScene::update(float dt) {
136 printf("%s: 読み直した / reloaded\n", map->path().c_str()); 238 printf("%s: 読み直した / reloaded\n", map->path().c_str());
137 } 239 }
138   240  
139 // 主人公:自由に動く(マス目に縛られない)。斜めは正規化して同じ速さ / the hero moves freely (not locked to the 241 // 主人公:自由に動く(マス目に縛られない)。人・宝箱・閉じた門にもぶつかる / the hero moves freely (not locked to
140 // grid); diagonals are normalized to the same speed 242 // the grid) and also collides with people, chests and closed gates
141 hero.beginStep(); 243 hero.beginStep();
142 Vec2 move = {in.axis("left", "right"), in.axis("up", "down")}; 244 Vec2 move = {in.axis("left", "right"), in.axis("up", "down")};
143 hero.moving = move.x != 0.0f || move.y != 0.0f; 245 hero.moving = move.x != 0.0f || move.y != 0.0f;
    246 collectBlockers(nullptr);
144 if (hero.moving) { 247 if (hero.moving) {
145 hero.facing = facingFor(move, hero.facing); 248 hero.facing = facingFor(move, hero.facing);
146 float speed = in.actionHeld("run") ? kRunSpeed : kWalkSpeed; 249 float speed = in.actionHeld("run") ? kRunSpeed : kWalkSpeed;
@@ -148,7 +251,16 @@ void MapScene::update(float dt) {
148 } 251 }
149 hero.anim.speed = in.actionHeld("run") ? 1.5f : 1.0f; 252 hero.anim.speed = in.actionHeld("run") ? 1.5f : 1.0f;
150 hero.animate(g.characters, dt); 253 hero.animate(g.characters, dt);
    254  
    255 // 人:主人公・ほかの人・固い物にぶつかる / people collide with the hero, each other and solid things
    256 for (Npc &n : npcs) {
    257 collectBlockers(&n);
    258 blockers.push_back(hero.box);
    259 n.update(dt, rng, *map, blockers, scratch, g.characters);
    260 }
    261  
151 if (in.actionPressed("confirm")) interact(); 262 if (in.actionPressed("confirm")) interact();
    263 checkPickups();
152 checkWarps(); 264 checkWarps();
153   265  
154 for (Popup &p : popups) { 266 for (Popup &p : popups) {
@@ -183,14 +295,39 @@ void MapScene::draw(float alpha) {
183 const SpriteSheet &tileSheet = map->tileset().sheet(); 295 const SpriteSheet &tileSheet = map->tileset().sheet();
184   296  
185 auto drawCharacters = [&] { 297 auto drawCharacters = [&] {
186 // 人物と、背の低い物(宝箱)を足元のyの順に / characters and low objects (chests) sorted by the y of their feet 298 // 人物と背の低い物(宝箱・門・落ちている物)を足元のyの順に / characters and low objects (chests, gates, items on the
    299 // ground) sorted by the y of their feet
187 b.begin(vp, SpriteSort::Layer); 300 b.begin(vp, SpriteSort::Layer);
188 for (const Chest &c : chests) { 301 for (const Chest &c : chests) {
    302 if (!present(*c.object)) continue;
189 Sprite s = tileSheet.sprite(tileSheet.find(g.world.flag(c.flag) ? "chest_open" : "chest_closed"), 303 Sprite s = tileSheet.sprite(tileSheet.find(g.world.flag(c.flag) ? "chest_open" : "chest_closed"),
190 c.object->rect.position()); 304 c.object->rect.position());
191 s.layer = c.box.bottom(); 305 s.layer = c.box.bottom();
192 b.draw(s); 306 b.draw(s);
193 } 307 }
    308 for (const MapObject &o : map->objects())
    309 if (o.kind == "gate" && present(o))
    310 for (float x = o.rect.x; x < o.rect.right(); x += kTile) {
    311 Sprite s = tileSheet.sprite(tileSheet.find("gate"), {x, o.rect.y});
    312 s.layer = o.rect.bottom();
    313 b.draw(s);
    314 }
    315 for (const Pickup &p : pickups) {
    316 if (g.world.flag(p.flag) || !present(*p.object)) continue;
    317 const ItemKind *kind = g.itemTable.find(p.item);
    318 Vec2 at = p.object->rect.position();
    319 at.y += std::round(1.5f * std::sin(3.0f * time)) - 2.0f; // ふわふわ / bobbing
    320 if (kind) {
    321 Sprite s = g.items.sprite(kind->sprite, at);
    322 s.layer = p.object->rect.bottom() - 4.0f;
    323 b.draw(s);
    324 }
    325 int frame = g.sparkle.frames[static_cast<size_t>(time * g.sparkle.fps) % g.sparkle.frames.size()];
    326 Sprite sp = g.items.sprite(frame, at + Vec2{5.0f, -5.0f});
    327 sp.layer = p.object->rect.bottom();
    328 b.draw(sp);
    329 }
    330 for (const Npc &n : npcs) b.draw(n.body.sprite(g.characters, alpha));
194 b.draw(hero.sprite(g.characters, alpha)); 331 b.draw(hero.sprite(g.characters, alpha));
195 b.end(); 332 b.end();
196 spriteCalls += b.stats().drawCalls; 333 spriteCalls += b.stats().drawCalls;
@@ -224,9 +361,12 @@ void MapScene::draw(float alpha) {
224 scratch.clear(); 361 scratch.clear();
225 map->solidRects(visible, scratch); 362 map->solidRects(visible, scratch);
226 for (const Rect &r : scratch) b.drawRectOutline(r, hexColor(0xff5050c0)); 363 for (const Rect &r : scratch) b.drawRectOutline(r, hexColor(0xff5050c0));
    364 collectBlockers(nullptr);
227 for (const Rect &r : blockers) b.drawRectOutline(r, hexColor(0xff9040ff)); 365 for (const Rect &r : blockers) b.drawRectOutline(r, hexColor(0xff9040ff));
228 for (const MapObject &o : map->objects()) 366 for (const MapObject &o : map->objects()) {
229 if (o.kind == "door" || o.kind == "warp") b.drawRectOutline(o.rect, hexColor(0x40c0ffff)); // 扉 / doors 367 if (o.kind == "door" || o.kind == "warp") b.drawRectOutline(o.rect, hexColor(0x40c0ffff)); // 扉 / doors
    368 if (o.kind == "sign") b.drawRectOutline(o.rect, hexColor(0xd080ffff)); // 看板 / signs
    369 }
230 Vec2 p = lerp(hero.previous, hero.box.position(), alpha); 370 Vec2 p = lerp(hero.previous, hero.box.position(), alpha);
231 b.drawRectOutline({p.x, p.y, hero.box.w, hero.box.h}, hexColor(0x50ff60ff)); 371 b.drawRectOutline({p.x, p.y, hero.box.w, hero.box.h}, hexColor(0x50ff60ff));
232 b.drawRectOutline(facingProbe(), hexColor(0xffff60c0)); 372 b.drawRectOutline(facingProbe(), hexColor(0xffff60c0));
@@ -235,45 +375,46 @@ void MapScene::draw(float alpha) {
235 b.end(); 375 b.end();
236   376  
237 // キャンバスの画面に固定の物:マップの名前、お金 / things fixed to the canvas screen: the map's name, the money 377 // キャンバスの画面に固定の物:マップの名前、お金 / things fixed to the canvas screen: the map's name, the money
238 Camera2D canvas = Camera2D::screen(kView); 378 b.begin(canvasMatrix());
239 b.begin(canvas.matrix());    
240 float banner = std::clamp((kBannerTime - time) / 0.5f, 0.0f, 1.0f); 379 float banner = std::clamp((kBannerTime - time) / 0.5f, 0.0f, 1.0f);
241 if (banner > 0.0f) { 380 if (banner > 0.0f) {
242 Vec2 size = g.pixel.measure(map->title()); 381 // trは渡したTextの中への参照を返す。ここのTextは一時的なので文字列を写す(参照は行の終わりで無効になる)
    382 // tr returns a reference into the Text it is given. This Text is a temporary, so copy the string (a reference
    383 // would dangle after this line)
    384 std::string title = g.tr(splitPair(map->title()));
    385 Vec2 size = g.pixel.measure(title);
243 Rect box = Rect::fromCentre({160.0f, 30.0f}, {size.x + 16.0f, size.y + 6.0f}); 386 Rect box = Rect::fromCentre({160.0f, 30.0f}, {size.x + 16.0f, size.y + 6.0f});
244 b.drawRect(box, {0.106f, 0.09f, 0.15f, 0.85f * banner}); 387 drawPanel(b, box, banner);
245 b.drawRectOutline(box, {0.95f, 0.76f, 0.31f, banner}); 388 g.pixel.draw(b, title, {160.0f, box.y + 3.0f}, {.color = {1.0f, 0.96f, 0.84f, banner}, .align = TextAlign::Centre});
246 g.pixel.draw(b, map->title(), {160.0f, box.y + 3.0f}, {.color = {1.0f, 0.96f, 0.84f, banner}, .align = TextAlign::Centre}); 389 }
    390 if (g.world.gold > 0) { // 第35章の宝箱は物が入っているので、お金はたまにしか出ない / chapter 35's chests hold items
    391 char gold[32];
    392 snprintf(gold, sizeof gold, "%d G", g.world.gold);
    393 g.pixel.draw(b, gold, {314.0f, 160.0f}, {.color = hexColor(0xf2c14eff), .align = TextAlign::Right, .shadow = hexColor(0x1b1726ff)});
247 } 394 }
248 char gold[32];    
249 snprintf(gold, sizeof gold, "%d G", g.world.gold);    
250 g.pixel.draw(b, gold, {314.0f, 160.0f}, {.color = hexColor(0xf2c14eff), .align = TextAlign::Right, .shadow = hexColor(0x1b1726ff)});    
251 b.end(); 395 b.end();
252 } 396 }
253   397  
254 void MapScene::drawUi(float /*alpha*/) { 398 void MapScene::drawUi(float /*alpha*/) {
255 if (!g.debug.hud) return; 399 if (!g.debug.hud || covered) return;
256 SpriteBatch &b = g.batch; 400 SpriteBatch &b = g.batch;
257 const TileRenderer::Stats &ts = g.tiles.stats(); 401 const TileRenderer::Stats &ts = g.tiles.stats();
258 char line[256]; 402 char line[256];
259 int col = static_cast<int>(std::floor(hero.box.centre().x / kTile)), row = static_cast<int>(std::floor(hero.box.centre().y / kTile)); 403 int col = static_cast<int>(std::floor(hero.box.centre().x / kTile)), row = static_cast<int>(std::floor(hero.box.centre().y / kTile));
260 snprintf(line, sizeof line, "%s %d×%d tile (%d, %d) rows %d-%d tile quads %d / %d draws: tiles %d + sprites %d maps %d", 404 snprintf(line, sizeof line, "%s %d×%d tile (%d, %d) rows %d-%d tile quads %d / %d draws: tiles %d + sprites %d people %zu",
261 map->name().c_str(), map->width(), map->height(), col, row, rowFirst, rowLast, ts.quads, ts.totalQuads, 405 map->name().c_str(), map->width(), map->height(), col, row, rowFirst, rowLast, ts.quads, ts.totalQuads,
262 ts.drawCalls, spriteCalls, g.world.loadedMaps()); 406 ts.drawCalls, spriteCalls, npcs.size());
263 b.begin(g.screen.matrix()); 407 b.begin(g.screen.matrix());
264 TextStyle hud = {.color = hexColor(0xfff4d6ff), .shadow = hexColor(0x000000ff)}; 408 TextStyle hud = {.color = hexColor(0xfff4d6ff), .shadow = hexColor(0x000000ff)};
265 b.drawRect({0.0f, 0.0f, 1280.0f, 30.0f}, hexColor(0x1b1726c0)); 409 b.drawRect({0.0f, 0.0f, 1280.0f, 30.0f}, hexColor(0x1b1726c0));
266 g.ui.draw(b, line, {12.0f, 6.0f}, hud); 410 g.ui.draw(b, line, {12.0f, 6.0f}, hud);
267 char layers[64];    
268 snprintf(layers, sizeof layers, "layers %s %s %s", g.debug.layers[0] ? "1" : "-", g.debug.layers[1] ? "2" : "-",    
269 g.debug.layers[2] ? "3" : "-");    
270 hud.align = TextAlign::Right; 411 hud.align = TextAlign::Right;
271 hud.color = hexColor(0xf2c14eff); 412 hud.color = hexColor(0xf2c14eff);
272 g.ui.draw(b, layers, {1268.0f, 6.0f}, hud); 413 g.ui.draw(b, g.world.language == Language::Ja ? "日本語" : "English", {1268.0f, 6.0f}, hud);
273 b.drawRect({0.0f, 690.0f, 1280.0f, 30.0f}, hexColor(0x1b1726c0)); 414 b.drawRect({0.0f, 690.0f, 1280.0f, 30.0f}, hexColor(0x1b1726c0));
274 hud.align = TextAlign::Centre; 415 hud.align = TextAlign::Centre;
275 hud.color = hexColor(0xc8cce0ff); 416 hud.color = hexColor(0xc8cce0ff);
276 g.ui.draw(b, "arrows / WASD: move Shift: run Space: 調べる / check 1 2 3: layers B: boxes Z: zoom out H: HUD R: reload Esc: 終了 / quit", 417 g.ui.draw(b, "WASD: move Shift: run Space: 話す・調べる / talk, check I: 持ち物 / items L: 日本語 / English B Z H 1 2 3 R Esc: 終了 / quit",
277 {640.0f, 696.0f}, hud); 418 {640.0f, 696.0f}, hud);
278 b.end(); 419 b.end();
279 } 420 }

ファイル: /dev/null | b/games/rpg/src/npc.cc

前新
@@ -0,0 +1,72 @@
    1 #include "npc.hh"
    2  
    3 #include <cmath>
    4  
    5 constexpr float kNpcSpeed = 36.0f; // 主人公の半分くらい / about half the hero's speed
    6  
    7 Facing parseFacing(std::string_view s) {
    8 return s == "up" ? Facing::Up : s == "left" ? Facing::Left : s == "right" ? Facing::Right : Facing::Down;
    9 }
    10  
    11 Npc Npc::fromObject(const MapObject &o) {
    12 Npc n;
    13 n.object = &o;
    14 n.body.look = o.getInt("look", 1);
    15 n.body.placeAt(o.rect.position());
    16 n.body.facing = parseFacing(o.get("face", "down"));
    17 n.say = std::string(o.get("say", o.name));
    18 n.mode = o.get("mode", "idle") == "wander" ? Mode::Wander : Mode::Idle;
    19 n.home = n.body.box.position();
    20 n.radius = kTile * static_cast<float>(o.getInt("radius", 2));
    21 n.timer = 0.5f;
    22 return n;
    23 }
    24  
    25 void Npc::faceTowards(Facing hero) {
    26 body.facing = hero == Facing::Up ? Facing::Down : hero == Facing::Down ? Facing::Up : hero == Facing::Left ? Facing::Right
    27 : Facing::Left;
    28 direction = {};
    29 body.moving = false;
    30 timer = 1.5f;
    31 }
    32  
    33 static Facing facingOf(Vec2 d) {
    34 if (std::abs(d.x) > std::abs(d.y)) return d.x < 0.0f ? Facing::Left : Facing::Right;
    35 return d.y < 0.0f ? Facing::Up : Facing::Down;
    36 }
    37  
    38 void Npc::update(float dt, Rng &rng, const Tilemap &map, std::span<const Rect> others, std::vector<Rect> &scratch,
    39 const CharacterSheet &sheet) {
    40 body.beginStep();
    41 timer -= dt;
    42 if (timer <= 0.0f) {
    43 if (mode == Mode::Idle) {
    44 // ときどき向きを変える(下向きが多め) / turn now and then (mostly facing down)
    45 static const Facing kLook[] = {Facing::Down, Facing::Down, Facing::Left, Facing::Right, Facing::Down, Facing::Up};
    46 body.facing = rng.pick(std::span<const Facing>(kLook));
    47 timer = rng.range(1.5f, 3.5f);
    48 } else if (direction.x != 0.0f || direction.y != 0.0f) {
    49 direction = {}; // 歩いた:しばらく立ち止まる / walked: stand still for a while
    50 timer = rng.range(1.0f, 2.5f);
    51 } else {
    52 // 次の向き:家から離れすぎていれば家の方、でなければ4方向から乱数 / next direction: toward home when too far,
    53 // otherwise one of the 4 directions at random
    54 Vec2 toHome = home - body.box.position();
    55 if (length(toHome) > radius) {
    56 direction = std::abs(toHome.x) > std::abs(toHome.y) ? Vec2{toHome.x > 0.0f ? 1.0f : -1.0f, 0.0f}
    57 : Vec2{0.0f, toHome.y > 0.0f ? 1.0f : -1.0f};
    58 } else {
    59 static const Vec2 kDirs[] = {{1.0f, 0.0f}, {-1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, -1.0f}};
    60 direction = rng.pick(std::span<const Vec2>(kDirs));
    61 }
    62 body.facing = facingOf(direction);
    63 timer = rng.range(0.4f, 1.1f);
    64 }
    65 }
    66 body.moving = direction.x != 0.0f || direction.y != 0.0f;
    67 if (body.moving) {
    68 MoveResult hit = moveOnMap(body.box, direction * (kNpcSpeed * dt), map, others, scratch);
    69 if (hit.hitX || hit.hitY) timer = 0.0f; // ぶつかったら立ち止まって考え直す / bumped: stop and decide again
    70 }
    71 body.animate(sheet, dt);
    72 }

ファイル: /dev/null | b/games/rpg/src/npc.hh

前新
@@ -0,0 +1,37 @@
    1 // 村の人(第35章):その場で向きを変える(idle)か、家の近くを歩き回る(wander)。話しかけると振り向く
    2 // Villagers (chapter 35): either stand and look around (idle) or stroll near their home spot (wander). They turn to
    3 // face you when you talk to them
    4 #pragma once
    5  
    6 #include "character.hh"
    7  
    8 #include "engine/rng.hh"
    9  
    10 #include <span>
    11 #include <string>
    12 #include <vector>
    13  
    14 struct Npc {
    15 enum class Mode { Idle, Wander };
    16  
    17 Character body;
    18 const MapObject *object = nullptr;
    19 std::string say; // 話しかけたときの会話(dialogue.txtの@label) / the conversation when talked to (an @label)
    20 Mode mode = Mode::Idle;
    21 Vec2 home; // 出発点(足元の箱の左上) / the starting point (top left of the foot box)
    22 float radius = 0.0f; // 家からどこまで歩くか(ピクセル) / how far from home it strolls (pixels)
    23 float timer = 0.0f; // 次に決めるまでの秒数 / seconds until the next decision
    24 Vec2 direction; // 歩く向き(0 = 立ち止まっている) / walking direction (0 = standing)
    25  
    26 // マップの物(object npc <名前> <列> <行> look= say= mode=idle|wander radius= face=)から作る
    27 // Made from a map object (object npc <name> <col> <row> look= say= mode=idle|wander radius= face=)
    28 static Npc fromObject(const MapObject &o);
    29 // 1ステップ:決める(乱数)・歩く(固いマスとothersに当たる)・絵を進める / one step: decide (random), walk
    30 // (colliding with solid cells and `others`), animate
    31 void update(float dt, Rng &rng, const Tilemap &map, std::span<const Rect> others, std::vector<Rect> &scratch,
    32 const CharacterSheet &sheet);
    33 // 話しかけられた:相手の方を向いて、少しのあいだ止まる / talked to: face the speaker and pause for a moment
    34 void faceTowards(Facing heroFacing);
    35 };
    36  
    37 Facing parseFacing(std::string_view s);

ファイル: /dev/null | b/games/rpg/src/text.cc

前新
@@ -0,0 +1,149 @@
    1 #include "text.hh"
    2  
    3 static std::string_view trim(std::string_view s) {
    4 while (!s.empty() && (s.front() == ' ' || s.front() == '\t')) s.remove_prefix(1);
    5 while (!s.empty() && (s.back() == ' ' || s.back() == '\t' || s.back() == '\r')) s.remove_suffix(1);
    6 return s;
    7 }
    8  
    9 Text splitPair(std::string_view s) {
    10 size_t bar = s.find(" | ");
    11 if (bar == std::string_view::npos) {
    12 std::string both(trim(s));
    13 return {both, both};
    14 }
    15 return {std::string(trim(s.substr(0, bar))), std::string(trim(s.substr(bar + 3)))};
    16 }
    17  
    18 // 日本語・中国語の文字(かな・漢字・全角の記号):どこでも折り返せる / CJK characters (kana, kanji, full-width
    19 // punctuation): a line may break before any of them
    20 static bool isCjk(char32_t c) { return c >= 0x3000 && c <= 0x9FFF; }
    21 static bool isCjkOrFullWidth(char32_t c) { return isCjk(c) || (c >= 0xFF00 && c <= 0xFFEF); }
    22  
    23 // 行の頭に来てはいけない文字(行頭禁則) / characters that must not start a line (kinsoku)
    24 static bool noLineStart(char32_t c) {
    25 switch (c) {
    26 case U'。': case U'、': case U'!': case U'?': case U'」': case U'』': case U')': case U'ー': case U'…':
    27 case U'ぁ': case U'ぃ': case U'ぅ': case U'ぇ': case U'ぉ': case U'っ': case U'ゃ': case U'ゅ': case U'ょ':
    28 case U'ァ': case U'ィ': case U'ゥ': case U'ェ': case U'ォ': case U'ッ': case U'ャ': case U'ュ': case U'ョ':
    29 case U'.': case U',': case U'!': case U'?': case U')': case U':': case U';':
    30 return true;
    31 default:
    32 return false;
    33 }
    34 }
    35  
    36 static float advanceOf(const Font &font, char32_t c) {
    37 const Glyph *g = font.glyph(c);
    38 if (!g) g = font.glyph(U'?');
    39 return g ? g->advance : 0.0f;
    40 }
    41  
    42 // 折り返しの単位:英語の一語、空白一つ、日本語の一文字、改行。行頭禁則の文字は前の単位にくっつける
    43 // Units of wrapping: an English word, one space, one CJK character, a newline. Kinsoku characters stick to the unit
    44 // before them
    45 struct Unit {
    46 std::string bytes;
    47 float width = 0.0f;
    48 enum Kind { Word, Space, Newline } kind = Word;
    49 };
    50  
    51 static std::vector<Unit> units(const Font &font, std::string_view text) {
    52 std::vector<Unit> out;
    53 bool inWord = false; // 英語の語の途中 / inside an English word
    54 size_t i = 0;
    55 while (i < text.size()) {
    56 size_t start = i;
    57 char32_t c = decodeUtf8(text, i);
    58 std::string_view bytes = text.substr(start, i - start);
    59 float w = advanceOf(font, c);
    60 if (c == U'\n') {
    61 out.push_back({"", 0.0f, Unit::Newline});
    62 inWord = false;
    63 } else if (c == U' ') {
    64 out.push_back({" ", w, Unit::Space});
    65 inWord = false;
    66 } else if (noLineStart(c) && !out.empty() && out.back().kind == Unit::Word) {
    67 out.back().bytes += bytes; // 「。」は前の文字と一緒に動く(追い出し) / 。 moves with the character before it
    68 out.back().width += w;
    69 } else if (isCjkOrFullWidth(c)) {
    70 out.push_back({std::string(bytes), w, Unit::Word});
    71 inWord = false;
    72 } else if (inWord) {
    73 out.back().bytes += bytes;
    74 out.back().width += w;
    75 } else {
    76 out.push_back({std::string(bytes), w, Unit::Word});
    77 inWord = true;
    78 }
    79 }
    80 return out;
    81 }
    82  
    83 std::vector<std::string> wrapText(const Font &font, std::string_view text, float maxWidth) {
    84 std::vector<std::string> lines(1);
    85 float width = 0.0f;
    86 bool pendingSpace = false; // 行の途中の空白は、次の語が同じ行に入るときだけ書く / a space is written only if the
    87 // next word stays on the same line
    88 float spaceWidth = advanceOf(font, U' ');
    89 for (const Unit &u : units(font, text)) {
    90 if (u.kind == Unit::Newline) {
    91 lines.emplace_back();
    92 width = 0.0f;
    93 pendingSpace = false;
    94 continue;
    95 }
    96 if (u.kind == Unit::Space) {
    97 pendingSpace = !lines.back().empty();
    98 continue;
    99 }
    100 float needed = u.width + (pendingSpace ? spaceWidth : 0.0f);
    101 if (width + needed > maxWidth && !lines.back().empty()) {
    102 lines.emplace_back(); // 次の行へ(空白は捨てる) / to the next line (the space is dropped)
    103 width = 0.0f;
    104 pendingSpace = false;
    105 }
    106 if (pendingSpace) {
    107 lines.back() += ' ';
    108 width += spaceWidth;
    109 pendingSpace = false;
    110 }
    111 if (u.width <= maxWidth || !lines.back().empty()) {
    112 lines.back() += u.bytes;
    113 width += u.width;
    114 continue;
    115 }
    116 // 一語だけで行より長い:文字ごとに切る / one word longer than a line: cut it character by character
    117 size_t i = 0;
    118 while (i < u.bytes.size()) {
    119 size_t start = i;
    120 char32_t c = decodeUtf8(u.bytes, i);
    121 float w = advanceOf(font, c);
    122 if (width + w > maxWidth && !lines.back().empty()) {
    123 lines.emplace_back();
    124 width = 0.0f;
    125 }
    126 lines.back() += u.bytes.substr(start, i - start);
    127 width += w;
    128 }
    129 }
    130 return lines;
    131 }
    132  
    133 size_t charCount(std::string_view utf8) {
    134 size_t i = 0, n = 0;
    135 while (i < utf8.size()) {
    136 decodeUtf8(utf8, i);
    137 ++n;
    138 }
    139 return n;
    140 }
    141  
    142 std::string firstChars(std::string_view utf8, size_t n) {
    143 size_t i = 0;
    144 while (i < utf8.size() && n > 0) {
    145 decodeUtf8(utf8, i);
    146 --n;
    147 }
    148 return std::string(utf8.substr(0, i));
    149 }

ファイル: /dev/null | b/games/rpg/src/text.hh

前新
@@ -0,0 +1,36 @@
    1 // 二か国語の文と、折り返し(第35章) / bilingual text and word wrapping (chapter 35)
    2 #pragma once
    3  
    4 #include "engine/font.hh"
    5  
    6 #include <string>
    7 #include <string_view>
    8 #include <vector>
    9  
    10 enum class Language { Ja, En };
    11  
    12 // 同じ文の日本語と英語。ゲームのデータ(会話・持ち物の名前)はみなこの形 / the same text in Japanese and English;
    13 // all game data (dialogue, item names) has this form
    14 struct Text {
    15 std::string ja, en;
    16 const std::string &get(Language l) const { return l == Language::Ja || en.empty() ? ja : en; }
    17 };
    18  
    19 // "日本語 | English" を分ける(| がなければ両方同じ) / splits "日本語 | English" (both the same without a |)
    20 Text splitPair(std::string_view s);
    21  
    22 // utf8をmaxWidth(ピクセル、scale 1)に収まる行に分ける。
    23 // * 英語:空白で折り返す(行頭の空白は捨てる)。一語が長すぎれば文字の途中で切る
    24 // * 日本語:どの文字の間でも折り返せる。ただし「。、!?)ー…」や小さい「っゃ」は行の頭に来ないよう、
    25 // 前の文字と一緒に次の行へ送る(行頭禁則の追い出し)
    26 // * "\n" で必ず改行
    27 // Splits utf8 into lines that fit into maxWidth (pixels at scale 1).
    28 // * English: breaks at spaces (a space at a line start is dropped); a word that is too long is cut mid-word
    29 // * Japanese: a break is allowed between any two characters, except that 。、!?」)ー… and small kana (っゃ…)
    30 // must not start a line: they move to the next line together with the character before them (kinsoku, "push out")
    31 // * "\n" always starts a new line
    32 std::vector<std::string> wrapText(const Font &font, std::string_view utf8, float maxWidth);
    33  
    34 // 最初のn文字(コードポイント)。タイプライター表示用 / the first n characters (code points), for the typewriter
    35 std::string firstChars(std::string_view utf8, size_t n);
    36 size_t charCount(std::string_view utf8);

ファイル: a/games/rpg/src/tilemap.hh | b/games/rpg/src/tilemap.hh

前新
@@ -89,6 +89,11 @@ public:
89 // (1 character = 1 tile, '.' = empty) 89 // (1 character = 1 tile, '.' = empty)
90 // object <kind> <name> <col> <row> [key=value …] w= h= でマスの大きさ(既定1×1) / w= h= set the size in tiles 90 // object <kind> <name> <col> <row> [key=value …] w= h= でマスの大きさ(既定1×1) / w= h= set the size in tiles
91 // (default 1 × 1) 91 // (default 1 × 1)
    92 // ゲームが使う物の種類 / object kinds the game uses:
    93 // spawn (face=) door / warp (map= spawn=) chest (gold= | item=)
    94 // npc (look= say= mode=idle|wander radius= face=) item (item=) sign (say=) gate (say=; solid while present)
    95 // どの物にも if=<印> / unless=<印>:印があるとき・ないときだけある / any object: if=<flag> / unless=<flag> makes it
    96 // exist only while the flag is set / not set
92 // エラーは「ファイル:行: 説明」でstderrに出してnullopt / errors go to stderr as "file:line: message", then nullopt. 97 // エラーは「ファイル:行: 説明」でstderrに出してnullopt / errors go to stderr as "file:line: message", then nullopt.
93 // cacheがあれば、タイルセットはそこから取る(なければ読んで入れる) / with a cache, the tileset comes from it (loaded 98 // cacheがあれば、タイルセットはそこから取る(なければ読んで入れる) / with a cache, the tileset comes from it (loaded
94 // and added if missing) 99 // and added if missing)

ファイル: /dev/null | b/games/rpg/src/title_scene.cc

前新
@@ -0,0 +1,77 @@
    1 // タイトル:言語を選んで始める。絵はタイルと人物の絵を並べるだけ / the title: pick the language and start. The picture is
    2 // just tiles and characters laid out
    3 #include "game.hh"
    4  
    5 #include <cmath>
    6 #include <memory>
    7  
    8 void TitleScene::update(float dt) {
    9 time += dt;
    10 if (starting) return;
    11 Input &in = g.input;
    12 if (in.pressed(GLFW_KEY_ESCAPE)) {
    13 scenes().pop();
    14 return;
    15 }
    16 if (in.actionPressed("left") || in.actionPressed("right") || in.actionPressed("up") || in.actionPressed("down") ||
    17 in.pressed(GLFW_KEY_L))
    18 g.world.language = g.world.language == Language::Ja ? Language::En : Language::Ja;
    19 if (in.actionPressed("confirm")) {
    20 starting = true;
    21 scenes().replace(std::make_unique<MapScene>(g, "village", "start"), {.duration = 1.0f});
    22 }
    23 }
    24  
    25 void TitleScene::draw(float /*alpha*/) {
    26 SpriteBatch &b = g.batch;
    27 const SpriteSheet &tiles = g.world.map("village")->tileset().sheet();
    28 bool ja = g.world.language == Language::Ja;
    29 b.begin(canvasMatrix(), SpriteSort::Layer);
    30 // 空・草・森(タイルを並べる) / sky, grass, forest (tiles laid out)
    31 b.drawRect({0.0f, 0.0f, 320.0f, 116.0f}, hexColor(0x8fd0f0ff));
    32 b.drawRect({0.0f, 76.0f, 320.0f, 40.0f}, hexColor(0xb0e0f4ff));
    33 for (int col = 0; col < 20; ++col) {
    34 float x = 16.0f * static_cast<float>(col);
    35 b.draw(tiles.sprite(tiles.find("tree_top"), {x, 100.0f}));
    36 Sprite ground = tiles.sprite(tiles.find("grass"), {x, 116.0f}); // 幹のタイルの透明な所の下 / under the trunk's
    37 ground.layer = -1.0f; // transparent pixels
    38 b.draw(ground);
    39 b.draw(tiles.sprite(tiles.find("tree_bottom"), {x, 116.0f}));
    40 for (int row = 0; row < 3; ++row)
    41 b.draw(tiles.sprite(tiles.find((col + row) % 5 == 0 ? "grass2" : "grass"), {x, 132.0f + 16.0f * static_cast<float>(row)}));
    42 Sprite path = tiles.sprite(tiles.find(col % 4 == 1 ? "path2" : "path"), {x, 148.0f});
    43 path.layer = 0.5f;
    44 b.draw(path);
    45 }
    46 // 5人が歩く(その場で) / the five characters walking (on the spot)
    47 for (int look = 0; look < g.characters.looks(); ++look) {
    48 const AnimationClip *walk = g.characters.walk(look, Facing::Down);
    49 int frame = walk->frames[static_cast<size_t>((time + 0.13f * static_cast<float>(look)) * walk->fps) % walk->frames.size()];
    50 Sprite s = g.characters.sheet().sprite(frame, {112.0f + 24.0f * static_cast<float>(look), 160.0f}, {0.5f, 1.0f});
    51 s.layer = 2.0f;
    52 b.draw(s);
    53 }
    54 b.end();
    55  
    56 b.begin(canvasMatrix());
    57 // 題名:pixel12を2倍(整数倍なのでくっきり) / the title: pixel12 at ×2 (an integer scale, so it stays crisp)
    58 TextStyle title = {.color = hexColor(0xfff4d6ff), .scale = 2.0f, .align = TextAlign::Centre, .shadow = hexColor(0x1b1726ff)};
    59 g.pixel.draw(b, ja ? "薬草と古い鍵" : "The Herb and\nthe Old Key", {160.0f, ja ? 16.0f : 6.0f}, title);
    60 g.pixel.draw(b, ja ? "The Herb and the Old Key" : "薬草と古い鍵", {160.0f, ja ? 50.0f : 72.0f},
    61 {.color = hexColor(0x3d3459ff), .align = TextAlign::Centre});
    62 // 言語の選択 / the language choice
    63 const char *names[2] = {"日本語", "English"};
    64 for (int i = 0; i < 2; ++i) {
    65 bool sel = (i == 0) == ja;
    66 Rect r = Rect::fromCentre({120.0f + 80.0f * static_cast<float>(i), 96.0f}, {64.0f, 16.0f});
    67 if (sel) drawPanel(b, r);
    68 g.pixel.draw(b, names[i], {r.centre().x, r.y + 1.0f},
    69 {.color = sel ? hexColor(0xf2c14eff) : hexColor(0x3d3459ff), .align = TextAlign::Centre});
    70 }
    71 if (std::fmod(time, 1.2f) < 0.8f)
    72 g.pixel.draw(b, ja ? "← →: 言語 スペース: はじめる" : "← →: language Space: start", {160.0f, 165.0f},
    73 {.color = hexColor(0xfff4d6ff), .align = TextAlign::Centre, .shadow = hexColor(0x1b1726ff)});
    74 b.end();
    75 }
    76  
    77 void TitleScene::drawUi(float /*alpha*/) {}

ファイル: a/games/rpg/src/world.cc | b/games/rpg/src/world.cc

前新
@@ -36,3 +36,29 @@ bool World::reload(const std::string &name) {
36 // texture) is freed here 36 // texture) is freed here
37 return true; 37 return true;
38 } 38 }
    39  
    40 int World::itemCount(const std::string &id) const {
    41 for (const auto &[item, count] : inventory)
    42 if (item == id) return count;
    43 return 0;
    44 }
    45  
    46 void World::addItem(const std::string &id, int count) {
    47 for (auto &[item, n] : inventory)
    48 if (item == id) {
    49 n += count;
    50 return;
    51 }
    52 inventory.emplace_back(id, count);
    53 }
    54  
    55 bool World::removeItem(const std::string &id, int count) {
    56 for (size_t i = 0; i < inventory.size(); ++i)
    57 if (inventory[i].first == id) {
    58 if (inventory[i].second < count) return false;
    59 inventory[i].second -= count;
    60 if (inventory[i].second == 0) inventory.erase(inventory.begin() + static_cast<std::ptrdiff_t>(i));
    61 return true;
    62 }
    63 return false;
    64 }

ファイル: a/games/rpg/src/world.hh | b/games/rpg/src/world.hh

前新
@@ -1,5 +1,7 @@
1 // 世界の状態(第34章):読んだマップの置き場と、マップを出ても残るもの(開けた宝箱・お金) 1 // 世界の状態(第34章):読んだマップの置き場と、マップを出ても残るもの(開けた宝箱・お金)
2 // The world state (chapter 34): where loaded maps are kept, and what survives leaving a map (opened chests, money) 2 // The world state (chapter 34): where loaded maps are kept, and what survives leaving a map (opened chests, money)
    3 // 第35章:持ち物、会話で付く印(クエストの進み具合)、言語 / chapter 35: the inventory, flags set by dialogue (the quest's
    4 // progress), the language
3 // 5 //
4 // シーンはマップに入るたびに作り直される(scenes().replace)。だから「残すもの」はシーンではなくここに置く: 6 // シーンはマップに入るたびに作り直される(scenes().replace)。だから「残すもの」はシーンではなくここに置く:
5 // 残す:開けた宝箱などの印(flags)、お金 → 戻ってきても宝箱は開いたまま 7 // 残す:開けた宝箱などの印(flags)、お金 → 戻ってきても宝箱は開いたまま
@@ -11,12 +13,15 @@
11 // file says 13 // file says
12 #pragma once 14 #pragma once
13   15  
    16 #include "text.hh"
14 #include "tilemap.hh" 17 #include "tilemap.hh"
15   18  
16 #include <memory> 19 #include <memory>
17 #include <string> 20 #include <string>
18 #include <unordered_map> 21 #include <unordered_map>
19 #include <unordered_set> 22 #include <unordered_set>
    23 #include <utility>
    24 #include <vector>
20   25  
21 class World { 26 class World {
22 public: 27 public:
@@ -31,8 +36,17 @@ public:
31   36  
32 bool flag(const std::string &name) const { return flags.contains(name); } 37 bool flag(const std::string &name) const { return flags.contains(name); }
33 void setFlag(const std::string &name) { flags.insert(name); } 38 void setFlag(const std::string &name) { flags.insert(name); }
    39 void clearFlag(const std::string &name) { flags.erase(name); }
    40  
    41 // 持ち物:手に入れた順(持ち物の画面の並び) / the inventory, in the order things were found (the menu's order)
    42 int itemCount(const std::string &id) const;
    43 void addItem(const std::string &id, int count = 1);
    44 bool removeItem(const std::string &id, int count = 1); // 足りなければ何もしないでfalse / false (and nothing
    45 // changes) if there are not enough
    46 const std::vector<std::pair<std::string, int>> &items() const { return inventory; }
34   47  
35 int gold = 0; 48 int gold = 0;
    49 Language language = Language::Ja; // Lで切り替え / switched with L
36   50  
37 static std::string pathOf(const std::string &name) { return "games/rpg/assets/maps/" + name + ".map"; } 51 static std::string pathOf(const std::string &name) { return "games/rpg/assets/maps/" + name + ".map"; }
38   52  
@@ -40,4 +54,5 @@ private:
40 std::unordered_map<std::string, std::unique_ptr<Tilemap>> maps; 54 std::unordered_map<std::string, std::unique_ptr<Tilemap>> maps;
41 TilesetCache tilesets; 55 TilesetCache tilesets;
42 std::unordered_set<std::string> flags; 56 std::unordered_set<std::string> flags;
    57 std::vector<std::pair<std::string, int>> inventory;
43 }; 58 };


コメント(0)

まだコメントはありません。