35. トップダウンRPG パート3:NPC・会話・アイテム

第34章で、RPGには世界が出来ました。
3つのマップ、フェード付きの扉、開いた儘の宝箱、そしてマップを移っても残すべき物を覚えているWorldです。
でも、其処には誰も住んでいません。
此の章では人と、歩き回る理由を足します。
散歩して、話しかけるとこちらを向く村の人、タイプライターの様に文字が出る会話の箱、アイテムと持ち物、そして解くとマップが変わる小さなクエストです。

仕事の殆どは文字です。
ゲームは2か国語なので、全ての文が日本語と英語で存在し、表示する時に其々の言語の決まりに従って行に折り返します。
会話はC++ではなく、ゲームが読み込み、検査し、実行する小さな台本のファイルです。
そして、ゲームには第26章の共有のフォントに無い漢字が要るので、自分のアトラスを持ちます。
此の章で新しいOpenGLの関数はありません。
文字はSpriteBatchの普通のスプライトで、難しいのは配置、データ、ゲームの状態です。

35.1 此の章で作る物

ゲームはタイトル画面から始まり、其処で言語を選びます:

2つのタイトル画面を並べた物。左:2倍の大きさの日本語の題名「薬草と古い鍵」と其の下の英語の副題、日本語が選ばれている。右:2行のThe Herb and the Old Keyと日本語の副題、Englishが選ばれている。どちらにも木の列、草、其の場で歩く5人がいる

1つ目の動画は、タイトルから村に入り、村長に話しかけます。
村長は薬草を頼み、「はい・いいえ」の選択肢を出します:

2つ目はクエスト全体です。
引き受け、りんごの入った宝箱を開け、野原へ歩き、薬草を拾い、持って帰り、古い鍵をもらい、庭の門を開け、其の奥の宝箱から剣を取り、持ち物を日本語で見て、Lの後で英語で見ます:

操作:

  • タイトル:←と→(又はL)で言語を選び、スペース又はEnterで開始、Escで終了
  • マップ:矢印キー又はW、A、S、Dで歩き、Shiftで走る。スペース又はEnterで前にいる人に話しかけ、前にある物を調べ、開ける。Iで持ち物、Lで日本語と英語の切り替え。デバッグのキー1 2 3 B Z H Rは今まで通り、Escで終了
  • 会話:スペース又はEnterで、文字が出ている途中ならページの残りを全部出し、出終わっていれば次のページへ。↑と↓で答えを選び、Lで言語を切り替え
  • 持ち物:↑と↓で選び、Lで言語を切り替え、I又はEscで閉じる

第34章からの変更は全てgames/rpg/の中です:

  • src/text.hh、src/text.cc(新規):Language、2か国語のText、splitPair、禁則処理付きの折り返し、タイプライターの為のUTF-8の小さな関数2つ
  • src/dialogue.hh、src/dialogue.cc(新規):会話の台本(DialogueScript、起動時に読み込んで検査)と其のインタプリタ(DialogueRunner)
  • src/dialogue_scene.cc(新規):DialogueScene、上に重ねる会話の箱
  • src/items.hh、src/items.cc(新規):items.txtから読むItemKindとItemTable
  • src/npc.hh、src/npc.cc(新規):Npc、村の人
  • src/inventory_scene.cc、src/title_scene.cc(新規):持ち物の画面とタイトル
  • src/world.hh、src/world.cc:持ち物、clearFlag、今の言語
  • src/game.hh、src/map_scene.cc、src/main.cc:NPC、落ちている物、条件付きの物、新しいシーン、ゲームのフォント
  • assets/dialogue.txt、assets/items.txt(新規、手書き)、assets/items.pngと.atlas(新規)、assets/fonts/pixel12.pngと.fnt(新規)、3つのマップ、LICENSE.txtとREADME.md(完成したファイルは章のZIPとアセットのZIPのch35/に入っています)

新しい7つのソースはゲームの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)

何時も通り、プログラムはrpgで、プロジェクトのルートから動かします。
LinuxとFreeBSDでは./build/games/rpg/rpg、Visual Studioではスタートアッププロジェクトのrpgです。

35.2 何処でも2か国語

Text

プレイヤーが読む文字は全てデータから来ます。
会話の1ページ、話し手の名前、答え、アイテムの名前と説明、マップの題名。
其の全てが同じ型です:

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);

Textは両方の訳を同時に持ち、言語は何かを描く時に初めて選ばれます。
此れが此の章の一番大事な決定です。
もう一つのやり方、今の言語だけを読み込む方法だと、プレイヤーがLを押す度に全てのファイルを読み直し、開いている画面を全部作り直す事になります。
両方の文字列がメモリにあれば、切り替えは代入1つで、次のフレームが単にもう一方の文字列を選びます。
代わりに、表示されない数キロバイトの文字を持つ事になります。

言語其の物はゲームの状態なので、印やお金の隣のWorldに置きます:Language language = Language::Ja;。
第34章がシーンを変えても残すべき物を全部置いた場所です。
シーンはGameに正しい文字列を聞きます:

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

trは多くのUIツールキットで「翻訳」(translate)を表す伝統的な名前です。
trは渡されたTextの中への参照を返します。
コストは掛かりませんが、其の参照は其のTextが生きている間しか使えません。
マップの題名の帯は其の場でsplitPair(map->title())でTextを作り、此れは文の終わりで消える一時オブジェクトなので、帯は写しを持ちます:std::string title = g.tr(splitPair(map->title()));。
此の結果をconst std::string &で受けると、警告無しでコンパイルが通り、消えたオブジェクトを読みます。
AddressSanitizerは其れをstack-use-after-scopeとして報告します。
データファイルでは、短い組は1行に日本語 | Englishと書き、splitPairで分けます。
マップの題名(title 村 | Village)、話し手の名前、答え、アイテムの名前です。
長い文は言語ごとに1行で、其の方が読み易く、diffで比べ易いです(35.6で見ます)。

タイトル、マップ、会話の箱、持ち物の画面は、其々Lでg.world.languageを切り替えます。
マップの題名の帯、HUDの言語の表示、アイテムの名前は同じフレームで変わります。
会話の箱は、ページを折り返し直す必要もあります。
日本語と英語の文は、全く違う所で行に分かれるからです。

タイトルのシーン

TitleSceneはゲームに既にある物で描きます。
drawRect2つの空、村のタイルセットの木と草の列、そして其の場で歩くcharacters.pngの5人です。
題名はpixel12を2倍にした物で、2は整数なのでくっきりした儘です。
英語の題名は此の大きさでは2行要ります。
「The Herb and the Old Key」は24文字 × 7 px × 2 = 336 pxで、320 pxのキャンバスより広いからです。
← →(又はL)で言語を切り替え、スペースで1秒のフェード付きでタイトルを村のマップのシーンにreplaceします。

35.3 ゲーム専用のフォント

第26章はエンジンに554文字のアトラスを2つ入れました。
ASCII、かな、記号、そしてゲームのUIの為に選んだ252の漢字です。
そして決まりを一つ作りました。
もっと漢字が要るゲームは自分のフォルダに自分のアトラスを作り、assets/fonts/には触らない事です。
RPGの会話は、此のシリーズで初めての、ラベルではなく本当の文章で、腰、痛、野原、池、庭、柵の様な言葉が要ります。

其の為、ゲームはgames/rpg/assets/fonts/pixel12.pngと.fntを持ちます。
共有のpixel12に、ゲームの文字が使う物を足した物です:

ゲームのpixel12のアトラスを暗い背景の上で2倍にした物。603 glyphs、共有の554+会話の49、1ビットと書いてある。ASCII、ひらがな、カタカナ、記号、UIの漢字、最後に足した実 幅 広 庭 戸 昔 柵 格 楽 母 池 泳 焼 痛 発 直 知 礼 種 腰 要 農 野 類 飛など。其の下にitems.png:薬草、鍵、パン、りんご、剣、コイン、薬のアイコンと、きらめきの4コマ

アトラスはあたしの新しい生成スクリプトが作ります。
此のシリーズの他のアセットのスクリプトと同じく、ダウンロードには含まれないので、何をするかを説明します。
先ず、ゲームが表示出来る全ての文字を集めます。
dialogue.txtとitems.txtのコメント以外の行、マップのtitleの行、そしてgames/rpg/src/*.ccの文字列リテラルです(文字列リテラルだけなので、コメントの漢字は数えません)。
其処から共有のアトラスに既にある文字を除き、残りを第26章のアトラスと同じ生成器に追加の文字として渡します。
生成器は標準の文字と其の文字を、共有のpixel12と同じ寸法で、12 px、1ビットで描きます。
結果は603文字で、共有の554に49文字を足した物です。
其の内47文字が漢字で、2文字はタイトルの説明の行が使う矢印←と→です。
共有のアトラスと同じ512 × 256に今も収まります。

スクリプトはソースを読むので、stderrのエラーメッセージにしか出ない文字(例えば幅、直、印)もアトラスに入ります。
其れは害がありません。
空きのマスが少し増えるだけです。
大事なのは逆の間違いです。
dialogue.txtにアトラスに無い漢字を書くと、エンジンは第26章の設計通り?を描き、character not in the font: U+XXXXを1回出します。
なので問題は最初のテストで見つかります。
自分の台詞で新しい漢字を使いたい時は、アセットのZIPのextras/jis-level1-fonts/にある大きな版を使って下さい。
JIS第1水準の漢字2 965字全部と、かな、記号、全角の英数字を足した3 443文字のpixel12です。
同じ生成器と同じフォントで作ったので、今の603文字はピクセル単位で同じで、寸法(行の高さ16、ベースライン12)も同じです。
games/rpg/assets/fonts/pixel12.pngと.fntを其れで置き換えれば、良く使う日本語は何でも書けます。
アトラスは1024 × 1024(4 MiB)になりますが、此のゲームには問題の無い大きさです。
ゲームのREADMEにも同じ事が書いてあります。

mainは共有のフォントの代わりにゲームのフォントを読み込みます。
1ビットのピクセルアートなのでTextureFilter::Nearestです:

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

320 × 180のキャンバスの中に描く物は全て、此のフォントを倍率1(タイトルは2)で使います。
会話、メニュー、題名の帯です。
1280 × 720のUIの層のデバッグ用HUDは共有のmono16の儘で、其の文字列は共有の文字の範囲に収まっています。
DejaVu Sans MonoとNoto Sans CJK JPのライセンスの表示は文字の絵と一緒に付いて来るので、assets/LICENSE.txtと同じくgames/rpg/assets/LICENSE.txtにも書いてあります。

35.4 英語と日本語の折り返し

2つの違う決まり

会話の箱には1行に292 pxの文字が入ります。
pixel12では、空白を含めて全てのラテン文字が7 px、全ての日本語の文字が12 pxなので、1行にはラテン文字なら最大41文字(41 × 7 = 287)、日本語なら24文字(24 × 12 = 288)入ります。
ページは1行より遥かに長いので、ゲームは何処で行を分けるか決めなければなりません。

英語は単語の間に空白を入れて書き、行は空白でしか分けられません。
折り返した所の空白は消えます。
空白で始まる行は誰も見たくありません。

日本語には空白がありません。
「お礼にこの古い鍵をやろう。」の様な文は切れ目の無い文字の並びで、殆どどの2文字の間でも行を分けられます。
「殆ど」というのは、日本語の組版には禁則処理という決まりがあるからです:

  • 行頭禁則:行の頭に来てはいけない文字。。(句点)、、(読点)、!?などの閉じる記号、」』)などの閉じ括弧、長音符ー、三点リーダー…、そして発音の上で前の文字に属する小さい「ぁぃぅぇぉっゃゅょ」(とカタカナの同じ物)。
  • 行末禁則:行の終わりに来てはいけない文字。「『(などの開き括弧。

英語の読者にとって一番近いのは、コンマやピリオドで行を始めない、引用符を行末に一つだけぶら下げないという決まりです。
どの文字の境目でも折り返せる日本語では、此の決まりをはっきり書かなければなりません。
自然な切れ目が禁止の文字を行頭に置く時、昔からの直し方が3つあります:

  • 追い出し:禁止の文字の前の文字も次の行に送り、2文字一緒に新しい行を始めます。1行目は少し短くなります。
  • 追い込み:字間を少し詰めて、禁止の文字を今の行に押し込みます。字間を変えられる必要があります。
  • ぶら下げ:句読点を右の余白からはみ出させます。日本の新聞や本でよく見ます。

村長の会話で実際に此れが起きる行です:

同じ日本語の行を3通りに並べた物。どの文字も12 pxのマスで、292 pxの余白は破線。規則なし:24文字が入り、「。」が2行目の頭に来るので×印で禁止。追い出し(wrapTextのやり方):23文字276 pxで行が終わり、「よ」が「。」と一緒に次の行へ。ぶら下げ(課題3):25文字全部が1行に残り、「。」が余白から8 pxはみ出す

「お礼にこの古い鍵をやろう。野原の庭の門の鍵じゃよ。」は25文字、300 pxです。
23文字(276 px)の後には12 pxの文字をもう1文字入れる余裕がある(288 px)ので、素朴な折り返しは「よ」を1行目に置き、2行目を「。」で始めてしまいます。
あたし達の折り返しは追い出しを使います。
「よ」と「。」が一緒に2行目へ移ります。
等幅のピクセルフォントでは追い込みは出来ず、ぶら下げは1行の変更で、課題3で試します。
ゲームは行頭禁則を実装しています。
開き括弧の行末禁則は課題4に残してあります。
ゲームの文には、行の途中に括弧が来る物が一つも無いからです。

同じ考えはソフトウェア向けにUnicodeの行分割アルゴリズム(UAX #14)として標準化されていて、全ての文字を前後に何が来て良いかで分類します。
ブラウザやワープロは其れを使います。
あたし達の物は其の小さな一部で、手書きの文を表示するゲームには其れで十分です。

単位

wrapTextは先ず文字列を単位に切ります。
決して分けない欠片です:

// 折り返しの単位:英語の一語、空白一つ、日本語の一文字、改行。行頭禁則の文字は前の単位にくっつける
// 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;
}

ラテン文字は今の単語に加わり、空白か日本語の文字が単語を終わらせます。
日本語の文字は1文字ずつが自分の単位で、此れが正に「どの2文字の間でも折り返せる」です。
禁則の決まりは3つ目の分岐です。
行頭に来てはいけない文字は前の単位に付け足されるので、2つは一緒にしか動けません。
追い出しは、行を埋める処理に特別な場合を作らなくても、データの構造から自然に出て来ます。
此処で「日本語の文字」とは、U+3000〜U+9FFF(CJKの記号、ひらがな、カタカナ、統合漢字)とU+FF00〜U+FFEF(!や?の様な全角の形)です。
各単位の幅はフォントのFont::glyph(c)->advanceから来るので、折り返しはどのアトラスでも動きます。

行頭禁則の文字の一覧はswitchで、英語の句読点も含みます。
なので「the east,」のコンマが置いて行かれる事もありません:

// 行の頭に来てはいけない文字(行頭禁則) / 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;
  }
}

此れらはchar32_tのリテラル(U'。')なので、バイトではなく読み取ったコードポイントと比べます。
ソースがUTF-8の儘コンパイラに届かなければならない理由の一つでもあります(35.11)。

行を埋める

単位があれば、行を埋めるのは貪欲法です。
次の単位が入らなくなるまで、行に単位を置いていきます。

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;
}

微妙なのは空白だけです。
空白は読んだ時には書かず、覚えておき(pendingSpace)、次の単語が同じ行に残る時だけ其の前に書きます。
なので行は空白で始まる事も終わる事も無く、続いた空白は1つにまとまります。
日本語のページでは「ありがたい! 薬草は…」の様に!の後に半角の空白を入れていて、此れも同じ扱いです。
行より広い1つの単語(例えば長いURL)は空白で分けられないので、最後の手段として文字の間で切ります。

折り返しは貪欲法で、殆ど全てのゲームと端末が此うしています。
TeXの様な組版のプログラムは代わりに段落全体の切れ目を一度に選び、行の長さを出来るだけそろえます(Knuth–Plassのアルゴリズム)。
ゲームの会話の3行には其の手間に見合いません。

此れが追い出しと英語のページの会話の箱です:

会話の箱を2つ切り出した物。左はkinsoku:1行目が「門の鍵じゃ」で終わり、2行目は「よ。」。右は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...

英語の行の幅は252、280、217 pxです。
「healing」を入れると1行目は252 + 7 + 49 = 308 pxになるので、次の行に行きます。
「east」の後のコンマはどの道其の単語の一部です。

バイトではなく文字を数える

タイプライターはページを1文字ずつ出すので、「文字列の最初のn文字」が要ります。
UTF-8では其れはsubstr(0, n)ではありません。
ASCIIの文字は1バイト、かなや漢字は3バイトで、文字の途中で切ると壊れたバイトになり、フォントは其れをU+FFFDとして読みます(第26章)。
小さな関数2つが、エンジンの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));
}

村長の2ページ目「実は腰を痛めてしまってな。東の野原に生える薬草があれば、よく効く薬が作れるんじゃが……。」は44文字、132バイトです。
厳密には此れはコードポイントを数えていて、あたし達の2つの言語では人が「1文字」と呼ぶ物と同じです。
結合文字や絵文字の並びを持つ文字体系には書記素クラスタが要り、其れは文字のシェーピングのライブラリの話です。

35.5 会話の箱

上に重ねるシーン

話しかけると、フェード無しでDialogueSceneをマップの上に載せます:

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
}

此れは第26章の重ねるシーンの仕組みで、デモの一時停止メニューと同じ物です。
isOverlay()がtrueを返すので、下のマップは描かれ続けますが、更新されるのは一番上のシーンだけです。
会話が開いている間、村の人は止まり、主人公は歩けず、キーは全部タイプライターに届きます。
モーダルな会話は其うあるべきで、其れがシーンのスタックからただで手に入ります。
マップのpause()は、第26章で学んだ様に全てのpreviousの位置を今の位置にするので、止まった絵が補間で震える事はありません。
又、coveredの印を立てて1280 × 720のHUDの帯を隠します。
UIのパスはキャンバスの後なので、隠さないと箱の下の部分に重なってしまいます。
会話が終わると、会話のシーンは自分でpopし、マップのresume()が呼ばれます。
其れがクエストに何故大事なのかは35.9で見ます。

会話の箱は320 × 180のキャンバスの中に、pixel12を倍率1で描きます。
なので文字は絵と同じピクセルの格子に乗り、絵と一緒に4倍になります:

320 × 180のキャンバスを2倍にした物。下にkBox, 6, 120, 308 × 56があり、中に16 pxの3本の破線の行(y 124、140、156)。文字の幅は292 pxで、xは14から306まで。箱の左端の上に話し手の札、右端の上に「> はい」「いいえ」の選択肢の箱、右下の角に小さな「次へ」の三角

箱は(6, 120)にある308 × 56で、文字は其の8 px内側から始まり、pixel12の行の高さ16 pxの3行が上下に4 pxの余白を残して入ります。
話し手の名前は上の縁に重なる小さな札に、「次へ」の印は右下の角で点滅し、質問の答えは右端の上の2つ目の箱に出ます。
全てSpriteBatchへのdrawRect、drawRectOutline、Font::drawの呼び出しで、会話全体でbegin/endは1回です。

配置:1回折り返し、かたまりで見せる

ページが来た時(又は言語が変わった時)、シーンは其れを折り返し、行を3行ずつのかたまりに分けます:

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);
}

書く人は行を数える必要がありません。
3行より多く折り返されるページは、自動で何回かに分けて見せます。
実は、入っている台本では其れは起きません。
一番長いページは村長の英語の2つの文(109文字と90文字)で、丁度3行になります。
表示する時に折り返すもう一つの良い所は、データに配置の情報が入らない事です。
翻訳する人は1ページに1つの文を書き、手で改行を入れる事はありません。
フォントを大きくしても箱を広くしても、dialogue.txtは何も変わりません。

タイプライター

shownは画面に出ている文字の数で、更新ごとに速さ × dtずつ増えるのでfloatです:

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();
}

速さは設計の選択で、日本語は毎秒30文字、英語は毎秒60文字です。
日本語の1文字はラテン文字1つより遥かに多くを運ぶ(古い鍵はold key)ので、同じ速さだと日本語は急かされ、英語はのろく感じます。
時間にすると、2つの言語は近くなります。
村長の2ページ目は日本語で44 / 30 ≈ 1.47秒、英語で109 / 60 ≈ 1.82秒です。
GameLoopは更新を60 Hzの固定で動かすので、タイプライターは日本語では更新ごとに丁度半文字、英語では1文字進み、どのマシンでも同じです。

決定のキーは、此の順で3つの事の一つをします。
まだ出ている途中のページの残りを全部出す(せっかちなプレイヤーが多数派です)、同じページの次のかたまりを見せる、又は台本に次のページを頼む、です。
此の順番の為、台本通りに動かす時はタイプライターを待たなければなりません。
早すぎるキーはページを全部出すだけです。
Lは言語を切り替え、ページを折り返し直し、最初のかたまりから全部見せます。
言語を変えた後、読む人はページを読みたいのであって、もう一度出て来るのを見たい訳ではありません。

描く時も同じ数を使います。
各行は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;
  }

ページは文字を出し始める前に折り返してあるので、出ている途中で単語が次の行に飛ぶ事はありません。
出しながら折り返すタイプライターの典型的なバグです。

全部出ると、角で小さな三角が点滅します。
5、3、1 pxのdrawRect3つで、sinで1ピクセル上下します。
質問の最後のかたまりでは、其の代わりに答えが出て、選んでいる物の前に>が付きます:

村の広場の会話の4つのフレーム。村長のページが出ている途中で44文字の内16文字。同じページが2行で全部出て「次へ」の印。質問「薬草をとってきてくれんかのう?」と「> はい」「いいえ」の選択肢の箱。そして2つ目と同じページをLの後で英語にし、空白で3行に折り返した物

35.6 データとしての会話:小さな台本の言語

何故C++ではないのか

「村長が何か言う」の素直な最初の版はコードです:if (talkingTo == "elder" && world.flag("quest_done")) …。
1人なら動きますが、3人で読めなくなり、物語を書く人も翻訳する人もコンパイラ無しには触れない所に置く事になります。
其の為、会話はテキストファイルgames/rpg/assets/dialogue.txtで、ゲームは其の小さなインタプリタを持ちます。
書式は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

此れが村長の最初の会話と2つの答えです:

@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.

マップの物はsay=で自分の会話を指します。
例えばobject npc elder 18 14 look=1 say=elder mode=idle face=downです。
看板と鍵のかかった扉もsay=の付いた物なので、村の鍵のかかった2つの扉の「鍵がかかっている。」はデータ2行です。

此れは第33章のマップの書式と同じ設計です。
1行に1命令、最初にキーワード、#でコメント。
わざと小さくしてあります。
式も、印と持ち物以外の変数も、入れ子もありません。
分岐はラベルと飛び先で、アセンブリ言語やBASICの様です。
数ページの会話なら、其れで十分読めます。

命令の並びに変換する

DialogueScript::loadは起動時にファイルを1回読み、1本の命令のvectorと、ラベルから番号への表にします:

  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;

各命令はエラーメッセージの為にファイルの行を覚えています。
ラベルは命令ではなく、其の会話が始まる番号に過ぎません。
読み込みは新しいラベルの前に必ずEndを足すので、会話が次の会話に流れ込む事はありません:

    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;
    }

1ページはjaの行と、其の直後のenの行で、enは同じ命令の英語の半分を埋めます:

    } 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);

choiceは其の直前のページの物なので、ページか別のchoiceの後にしか置けません。
其れ以外の場所ではインタプリタが其れを拾う事は無く(理由は後の「実行する」で見ます)、質問が答え無しで出てしまうので、此れも読み込みのエラーにします:

    } 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");

dialogue.txt全体は、20のラベルの下の81の命令になります。
此れが最初の21命令、村長の会話と其の飛び先です:

0から20までの命令を行にした物。@elderは0から:IfFlag quest_doneでelder_after(29)へ、IfItem herbでelder_thanks(20)へ、IfFlag quest_startedでelder_waiting(17)へ、次にName、Page3つ、elder_yes(10)とelder_no(14)へのChoice2つ、9にEnd。@elder_yesはSet quest_started、Name、Page、End。@elder_noはName、Page、End。@elder_waitingはName、Page、End。@elder_thanksはTake herbから。Pageは黄色、飛ぶ命令は青、Worldを変える命令はピンク、Endは赤

起動時に全部確かめる

プレイヤーが其の会話に着いた時に初めて見つかる台本の打ち間違いは、一番悪い種類のバグです。
其の儘出荷されてしまいます。
其の為loadは、ゲームが始まる前にファイルを全部確かめます。
文法の間違い(知らない命令、jaの無いen、ページの後に無いchoice、flagでもitemでもないif、二度目のラベル)は読みながら見つけます。
最後の行の後に、最後にならないと分からない事を確かめる為にもう1回回ります。
全ての飛び先があるか、全てのページに英語があるかです:

  // 飛び先がみなあるか、ページに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");
  }

エラーはコンパイラと同じファイル:行: 説明の形で出るので、エディタやIDEで其処に飛べます。
次の3つはよくある間違いで、其々ファイルのコピーで試した物です(21行目のラベルの打ち間違い、14行目の後のenの抜け、40行目のtakeをtak)。
ゲームはメッセージを出し、始まらずに終わります:

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

村長の質問と最初のchoiceの間に紛れ込んだset quest_startedも見つかります。
場所の間違ったchoiceは21行目に下がっています:

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

但し、確かめるのは一覧にある事だけです。
他のファイルからの参照は確かめていません。
マップのsay=のラベルは其の人に話しかけた時に初めて探され、無ければno such conversationと出て、箱はすぐ閉じます。
アイテムの名前も同じです。
items.txtに無いアイテムのgiveは其の名前を其の儘持ち物に入れ、持ち物の画面にはアイコン無しで其の名前が其の儘出ます(課題5で起動時に確かめます)。

実行する

DialogueRunnerは会話を1つ実行します。
見せる物に着くまで命令を実行する、プログラムカウンターpcを持った昔ながらのインタプリタのループです:

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()はPageで止まると新しいpage()と共にtrueを返し、Endに着くとfalseを返します。
2つのページの間の物は全て一瞬で実行されます。
ifがどの枝に行くかを決め、set、give、takeがWorldを変え、nameが後のページの話し手を変えます。
ページの直後のchoiceの行は其のページに集められ、choose(i)は答えのラベルへ飛んで、もう一度next()を呼びます。
case Op::Choiceが何もしないのも其の為です。
読み込みが全てのchoiceがページか別のchoiceの後にある事を保証し、Pageが其れらを全部取るので、インタプリタがchoiceで止まる事はありません。
flagやitemの前の!は条件を逆にする(c.negate)ので、判定は!=で比べています。

2つの細かい所で丈夫にしています。
guardは1回の呼び出しを10 000命令までに抑えるので、ページに着かないgotoの輪はゲームを止めずに会話を終わらせます。
そして、物語を変える全ての命令を標準出力に出します。
此の章の動画の為の台本通りの通しプレイは、此の記録で確かめました。
クエストのあらすじの様に読めます:

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)

インタプリタは箱やタイプライターを何も知らず、会話のシーンは印を何も知りません。
ランナーがページを渡し、シーンが其れを見せます。
同じランナーで、声の付いたカットシーンを動かす事も、ウィンドウ無しで台本の全ての枝を通るテストを書く事も出来ます。

35.7 アイテムと持ち物

items.txt

アイテムもデータです:

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> <アイコン> <名前>で種類を決め、其の下のinfoの行が言語ごとの説明です。
idは台本とマップが使う物(give key、item=sword)で、アイコンはitems.atlasのスプライトの名前です。
items.atlasはタイルと同じスクリプトで作ったシートで、16 × 16のアイコン7つと4コマのきらめきのクリップがあります。
ItemTable::loadは種類を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;
};

アイコンの名前はmainで1回だけスプライトの番号に変え、無いアイコンは台本と同じ方針で起動時にゲームを止めます:

  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;
    }
  }

持ち物はWorldの状態

プレイヤーが持っている物は扉を越えて残らなければならないので、Worldに、手に入れた順に置きます:

  // 持ち物:手に入れた順(持ち物の画面の並び) / 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; }

表ではなく(id, 数)の組のvectorなのは、メニューには決まった並びが要り、5つのアイテムにハッシュ表は要らないからです。
removeItemは0より下にならないので、持っていない物のtakeは何も変えず、stderrで知らせます。

アイテムは何処から来るか

第34章の宝箱は、お金の代わりにアイテムを入れられる様になりました(chest village_chest 21 8 item=apple)。
開けると今まで通り印を付け、アイテムを足し、お知らせ付きの会話の箱を載せます:

    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)));

お知らせはアイテムの名前から作るので、dialogue.txtにはありません:

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には此の様な1回きりの文の為の2つ目のコンストラクターがあり、DialogueScript::singleで1ページの台本を作って自分で持ちます。
なので、コードからのお知らせもファイルからの会話も、同じ箱、タイプライター、折り返しを使います。
英語が「You found 」+ 名前ではない事に注意して下さい。
日本語は動詞を目的語の後に置き(薬草を手に入れた!)、1つの言語の語順で言葉をつなげて文を作るのは、翻訳の典型的なバグです。
コロンの形「You found: Healing herb!」なら、冠詞無しでどのアイテムの名前にも使えます。

薬草は地面に落ちています。
野原のobject item herb 22 17 item=herbです。
上下にふわふわ動き、隣にきらめきのクリップが付き、人物と同じyで並べたバッチで描かれます。
上を歩くと拾い、field/herbの印が付くので、二度と出て来ません:

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;
  }
}

持ち物の画面

IはInventorySceneを載せます。
此れも重ねるシーンで、マップを暗くし、全てのアイテムのアイコン、名前、数を並べ、選んだアイテムの説明を同じwrapTextで240 pxに折り返して見せます。
一覧は毎フレームWorldから描くので何時も最新で、此処でもLが効きます:

2つの言語の持ち物の画面。左は「持ち物」で、選ばれた「りんご ×1」と「古い剣 ×1」、下に説明「赤くておいしそうなりんご。」。右はLの後の同じ画面で、Items、Apple ×1とOld sword ×1、A shiny red apple.

35.8 村の人

4人、2つの振る舞い

村には井戸のそばの村長と、橋の東のミナがいて、家にはお母さん、野原には農夫がいます。
其々がマップの物で、例えばobject npc girl 30 13 look=2 say=girl mode=wander radius=2です。
characters.pngの行、会話、振る舞い、家から何処まで散歩するか(マス)です。
Npcは第33章のCharacterを包むので、村の人は主人公と同じ足元の箱、歩きのアニメーション、当たり判定を持ちます:

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)

振る舞いはタイマー1つで動く小さな状態機械です:

2つの状態機械。idle(村長):自分に戻る「見回す」状態。下を3/6、左・右・上を1/6ずつの確率で向き、1.5〜3.5秒ごと。wander(ミナ、お母さん、農夫):「立つ」はタイマーが切れると「歩く」へ。radiusより遠ければ家の方、でなければ4方向から乱数で向きを決め、0.4〜1.1秒歩く。「歩く」はタイマーが切れるか、ぶつかると「立つ」へ戻り、1〜2.5秒立ち止まる。毎秒36 px、主人公と同じ様にぶつかる。下:話しかけられると主人公の方を向き、止まり、タイマーを1.5秒にする

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);
}

idleの村長は見回すだけです。
表にFacing::Downを3回入れてあるので、半分の時間は画面のプレイヤーの側を向きます。
乱数の選択に重みを付ける安上がりな方法です。
散歩する人は主人公の72の半分の毎秒36 pxで0.4〜1.1秒歩くので、1回の散歩は14.4〜39.6 px、大体1〜2.5マスです。
「AI」と呼べるのは引き綱だけです。
家からradiusより遠い時(ミナと農夫は32 px、小さな家のお母さんは16 px)、次の散歩は長い方の軸に沿って家の方へ向かいます。
壁、宝箱、他の人にぶつかった人はすぐ止まる(timer = 0で次の更新が「立つ」を選ぶ)ので、柵に向かって歩き続ける人はいません。

村の人は主人公と同じくmoveOnMapで動き、固いタイルとblockersにぶつかります。
宝箱、閉じた門、そして他の全ての人です。
MapScene::updateでは先に主人公が村の人の箱に対して動き、其の後で各人が自分以外の全てと主人公に対して動きます:

  // 人:主人公・ほかの人・固い物にぶつかる / 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);
  }

一人ごとに一覧を作り直すのはO(n²)ですが、1つのマップに4人なら何でもありません。
何百人もいる町なら、第26章の「本物のエンジンではどうしているか」のブロードフェーズを使います。
人は主人公、宝箱、アイテムと同じyで並べたバッチで描くので、ミナの後ろを歩くと主人公はミナの後ろになります。

話しかける

スペースは第34章の、8 pxの「前の箱」(probe)を調べ、人が宝箱や看板より先です:

  // 人:こちらを向かせてから話す / 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;
    }

話す人の方を向くのは、スプライトを人らしく見せる小さな工夫です。
4方向の格子なら簡単で、村の人は主人公の向きの反対を向き、歩くのを止めて1.5秒待ちます:

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;
}

箱が開いている間マップは更新されないので、其の1.5秒は会話が終わってから始まります。
なので、箱を閉じた途端に村の人が歩き去る事はありません。
同じ理由で、interactはfaceTowardsのすぐ後に時間0でanimateを呼びます。
向きを絵にするのはanimateなので、其の呼び出しが無ければ、村の人は会話の間ずっと前の向きの儘で、箱が閉じてから振り向きます。

NPCはWorldではなくシーンの物です。
setUpでマップのファイルから作るので、村に戻ると皆最初の場所にいます。
第34章の「残す・残さない」の決まりで、印は残り、位置は元に戻ります。
課題6で村の人を「残す」側に移します。

何処でも同じ種

散歩は乱数ですが、再現出来なければなりません。
第26章がRngについて挙げたのと同じ理由です。
リプレイ、バグの報告、そして毎回同じに見えなければならない台本通りの実行で作る此のチュートリアルのスクリーンショットと動画です。
マップのシーンは其々自分のRngを持つので、他のマップで何かが起きても、其のマップの人の散歩は変わりません。
種はマップの名前から作ります:

  // 人の動きの乱数はマップの名前から種を作る(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);

最初の版は自然な道具に見えるstd::hash<std::string>を使っていて、作る途中で置き換えました。
第26章のstd::uniform_int_distributionと同じ落とし穴です。
規格はstd::hashが何をしなければならないか(同じ入力は、プログラムの1回の実行の中で同じ結果)は決めていますが、どうやるかは決めておらず、標準ライブラリごとに自分のアルゴリズムがあります。
GCCのlibstdc++はMurmurHashの変種、Clangのlibc++(FreeBSDの既定)は自分のMurmurHash2とCityHashのコード、MicrosoftのSTLは64ビットのFNV-1aを使います。
なので村の人はLinuxで一通り、FreeBSDで別の通り、Windowsで更に別の通りに歩き、あるマシンで撮ったスクリーンショットを他のマシンで再現出来なくなります。
実装は実行ごとにハッシュに塩を混ぜる事さえ許されていて、攻撃を防ぐ為にわざと其うしているハッシュ表を持つ言語もあります。

FNV-1a(Fowler–Noll–Vo)は2行で書ける程単純で、厳密に決まっているハッシュです。
オフセット基底2 166 136 261から始め、各バイトをXORで混ぜて素数16 777 619を掛け、32ビットを残します。
C++の符号無し整数の桁あふれは232を法として回り込むと決まっているので、結果はどのコンパイラでも同じです。
charをunsigned charにキャストするのが大事です。
charはx86では符号付き、殆どのARMのLinuxでは符号無しで、此うしないと127より大きいバイトの符号拡張が違ってしまいます。

マップ FNV-1a、32ビット(あたし達の種) std::hash、GCC 13(libstdc++、64ビット) std::hash、MSVC x64(64ビットの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

マップに手で番号を付ける代わりに名前をハッシュにすると、良い事があります。
新しいマップは、誰かが決めなくても自分の決まった種を持ちます。

35.9 クエスト:印が世界を変える

条件付きの物

クエストには世界が変わる事が要ります。
庭の門は、鍵を開けたら消えなければなりません。
第34章の物に、任意の性質を2つ足します。
if=<印>(印がある間だけ其の物がある)とunless=<印>(印が無い間だけ)です:

// 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;
}

宝箱、アイテム、扉、看板、門、村の人、全ての種類の物が此れに従います。
野原の新しい物を見ると、クエストがどうつながっているかが分かります。
全てデータです:

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

門は庭の柵にある2マスの幅の物で、ある間は固く、gateのタイルで描きます。
調べると@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()は宝箱、アイテム、門、扉について毎フレーム、当たり判定と描画の両方で見るので、set gate_openが動いた瞬間に門は消えます。
setはページが出る前に動くので、門は「古い鍵で門を開けた!」が出ている間に、箱の後ろで既に消えています。
門なら其れで構いません。
順番が大事なら(お知らせの後で開くべき扉など)、お知らせを先に置き、setはgotoで行く2つ目のブロックに置いて下さい。
村の人は1回の訪問につき1回作るので、重ねるシーンが閉じた時のresume()で確かめ直します。
会話で誰かが現れたり去ったりする印が変わったかもしれないからです。
此処で現れた人は、第33章の主人公と同じく最初の更新の前に描かれるので、最後のループが時間0で全員のクリップを選びます(setUpも作った人に同じ事をします)。
前からいた人は、playが今のクリップを其の儘続けるので、何も動きません:

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);
}

クエストは3つの印

クエストの仕組みはありません。
クエスト全体は3つの印と持ち物で、dialogue.txtの最初のコメントに書いてあります。
quest_started(引き受けた)、quest_done(薬草を持って来て鍵をもらった)、gate_openです。

5つの段階のクエスト。1、村長:「はい」を選ぶ、set quest_started、持ち物は無し。2、池のそばの薬草:上を歩く、印field/herb、持ち物は薬草。3、村長:if item herb、take herb、give key、set quest_done、持ち物は古い鍵。4、庭の門:if item key、take key、set gate_open、持ち物は無し。5、宝箱:門が無い、印field/garden_chest、持ち物は古い剣。下:村長が見る順はquest_done、薬草、quest_started、初めての会話。「いいえ」はelder_noへ行き印は付かない。門の物にはunless=gate_open

村長の会話は3つのifで始まり、其の順番がクエストの論理です。
一番進んだ状態を最初に調べます。
クエストの後なら腰の話をし、薬草を持っていれば受け取り、引き受けた後なら薬草の場所を教え、其れ以外なら頼みます。
薬草は引き受けるまで隠れている訳ではないので、先に探検したプレイヤーは頼まれる前に持って来られて、村長は単にお礼を言います。
if item herbがif flag quest_startedより前にあるからです。
お母さん、ミナ、農夫も同じ印を調べ、前と後で違う事を言います。
数行の文で、村がプレイヤーのした事を知っている様に感じられます。

通しプレイの大事な場面です:

クエストの6つのフレーム。1、池のそばの薬草:「薬草を手に入れた!」。2、村長が鍵をくれる、追い出しの折り返し付き。3、庭の柵の鍵のかかった門。4、「古い鍵で門を開けた!」で、箱の後ろで門は既に消えている。5、印gate_open:門が消え、主人公が中に入る。6、古い剣:宝箱の前で「古い剣を手に入れた!」

8ビットの時代から今まで、殆どのRPGは此うして作られています。
物語の印の大域的な集まり(RPGツクールのスイッチ、多くの日本のRPGのイベントフラグ)と、其れを調べる台本です。
弱点は、クエスト全体を表す物が何も無い事です。
印が何十にもなると、書く人は其れを並べた別の文書を持ちます。
dialogue.txtの最初のコメントは其の小さな版です。

35.10 動かす

今まで通りビルドし、プロジェクトのルートから./build/games/rpg/rpgを動かします(Visual Studioではrpgのプロジェクトを開始します。作業ディレクトリは既にルートです)。
言語を選び、村長(大通りの南の広場の井戸のそばに立っています)の所まで歩いてスペースを押して下さい。
遊んでいる間、端末には35.6の記録が出るので、台本が何をしたかを見るのに便利です。

台本とアイテムは起動時に1回読むので、dialogue.txtを直したらゲームを再起動します。
ビルドし直す必要はありません(アトラスに無い漢字を使うなら、先に35.3節の大きなフォントに替えておきます)。
マップは第34章と同じくRで読み直し、其の時に村の人も作り直されます。

35.11 プラットフォームごとの注意

  • Windows(Visual Studio): RPGは今までのどのプログラムよりも文字列リテラルに日本語が多く(お知らせ、持ち物の題、タイトル画面)、noLineStartのchar32_tのリテラルは日本語の文字です。MSVCは/utf-8を与えられない限り、BOMの無いソースファイルをシステムのコードページで読みます。日本語のコードページ(932)ではUTF-8のバイトを読み違え、禁則の表もお知らせも間違ってしまいます。プロジェクトのトップのCMakeLists.txtがMSVCの全てのターゲットに/utf-8を渡すので、此処では何もしなくて構いません。自分でプロジェクトを作る時は足して下さい。
  • 全て: データファイルはバイトとして読み、BOM無しのUTF-8です。殆どのエディタは既定で其う保存し、今の版のWindowsのメモ帳も其うです。dialogue.txtの先頭にBOMがあると、最初の行に3バイトがくっつき、コメントとして読めなくなるので、読み込みは「最初の@labelの前の命令」として拒みます。
  • 全て: std::hashはlibstdc++(GCC、殆どのLinux)、libc++(Clang、FreeBSD)、MSVCのSTLで違います。FNV-1aなら村の人の散歩は3つ全てで同じです。ハッシュから作って再現したい物は全て同じで、ハッシュは自分で書いて下さい。
  • Linux、FreeBSD、Windows: ゲームのフォントは出来上がったPNGと.fntなので、どのプラットフォームでも同じファイルで、フォントをインストールする必要はありません。35.3節の大きな版も同じです。

35.12 本物のエンジンではどうしているか

  • 会話: 物語専用の言語です。Ink(inkle製、『80 Days』や『Heaven's Vault』で使用)とYarn Spinner(『Night in the Woods』や『A Short Hike』で使用)は、変数、条件、選択肢を持つ分岐する会話の為のスクリプト言語で、小さなバイトコードに変換され、ゲームの中のランタイムが実行します。あたし達の設計が大人になった物です。Twineは同じ種類の物語の為の見た目で操作するエディタです。多くのエンジンは会話にもゲームの処理にも単にLuaを組み込みます。大きなスタジオはarticy:draftの様なデータベースの道具を使い、書く人は会話をグラフとして編集します。
  • ローカライズ: 本物のゲームは文を台本から完全に追い出します。台本にはline elder_greeting_01と書き、言語ごとの文字列の表が文を持つので、翻訳する人は表計算やgettextの.poファイル、UnityのLocalizationパッケージ、UnrealのString Tablesの様な道具で作業します。部品から作るお知らせは番号付きの差し込み口の書式文字列({0}を手に入れた! / You found: {0}!)を使います。言語によって部品の順番が違うからです。
  • 行分割: UnicodeのUAX #14と、日本語の組版についてはW3Cの「日本語組版処理の要件」(JLReq)が禁則やもっと多くの事を決めています。ICUのBreakIteratorがUAX #14を実装し、HarfBuzzの様なテキストエンジンと其の上の配置のライブラリが残りを扱います。ピクセルフォントのゲームでは、あたし達の様な手書きの決まりも今でもよくあります。
  • NPC: ビヘイビアツリー(Unreal)、状態機械(殆どの2Dエンジン)、ユーティリティAI。散歩する村の人なら、あたし達の様なタイマーと引き綱が定番の技です。大きなオープンワールドのゲームは、其の上にNPCの日課(寝る、働く、酒場)を持たせます。
  • クエスト: 殆どのRPGは印の集まりと台本です。大きなゲームは、はっきりした段階と目的を持つクエストの仕組みを足し、日記、地図の印、会話が全て同じ状態を読む様にします。

35.13 RPGの振り返りと、此の先

3つの章で、タイルのレンダラーを小さな冒険にしました:

  • 第33章:静的な頂点バッファに入れた層付きのタイルマップ、行のカリング、押し出しの縁付きのタイルのタイルセットアトラス、固いマスに対する当たり判定付きの自由な移動、角の回り込み、主人公を追いかけてマップの端で止まるカメラ。
  • 第34章:ファイルから読んで取っておく複数のマップ、物としての扉と端の出口、フェード付きのシーンの入れ替え、そして何をWorldに残し、何をシーンと一緒に元に戻すかという中心の設計の問題。
  • 此の章:何時でも言語を切り替えられる2か国語の文字、ゲーム専用のフォントアトラス、禁則処理付きの英語と日本語の折り返し、重ねるシーンとしてのタイプライターの会話の箱、検査付きの会話の台本と小さなインタプリタ、アイテムと持ち物、どの環境でも同じ乱数の種を持つ村の人、そして印と条件付きの物で出来たクエスト。

此の内OpenGLの部分が如何に少ないかに注目して下さい。
GPUの仕事は第33章で終わっていて(静的なタイルのバッファとスプライトのバッチ)、其れからは全てデータ、状態、文字です。
此の種類のゲームでは普通の事で、先にエンジンを作った理由でもあります。
RPGはもうバッファの事を考えずに済みました。

RPGで、パート6の3つの2Dゲームが完成しました。
第36章は最後のゲーム、TPS(三人称シューティング)の為に3Dに戻ります。
2Dゲームが使わなかったパート4の全てを使います。
GLBの部品で作るレベル、シャドウマッピングとポストプロセス付きのPBRのレンダラー、キャラクターのモデル、そしてプレイヤーを追いかけて周りを回るカメラと、カメラが見ている方向を基準にした移動です。
第26章の固定ステップのループ、入力、シーン、Rngは其の儘一緒に来ます。

35.14 まとめ

  • 2か国語の文字: 表示する全ての文字列はText {ja, en}です。言語はWorldの状態で、Game::trが描く時に文字列を選ぶので、Lで全てが一度に切り替わり、開いている会話もページを折り返し直します。短い組は1行のja | en、長い物は別々のja/enの行です。
  • ゲームのフォント: あたしの生成スクリプトが会話、アイテム、マップの題名、文字列リテラルを読み、無い文字を第26章の文字に足します。603文字(554 + 49、其の内47が漢字)で、512 × 256の儘、1ビット、games/rpg/assets/fonts/にあります。共有のフォントには触りません。新しい漢字を書くなら、アセットのZIPのJIS第1水準の版(3 443文字、1024 × 1024、同じ寸法)と入れ替えます。
  • 折り返し: 文字を単位(英語の一語、空白、日本語の1文字、改行)に切り、292 pxの行に貪欲に詰めます。英語は空白で、日本語はどの文字の間でも折り返しますが、行頭に来てはいけない禁則の文字(。、!?」ー、小さいかな)は前の単位にくっつけるので、追い出しになります。ぶら下げと開き括弧の行末禁則は課題に残してあります。
  • UTF-8: タイプライターはcharCountとfirstCharsでコードポイントを数え、バイトは数えません。
  • 会話の箱: 重ねるシーンなので、マップは描かれますが止まっています。ページは1回折り返し、3行ずつのかたまりで見せます。日本語は毎秒30文字、英語は毎秒60文字で出し、決定のキーは残りを全部出す、次のかたまり、次のページの順です。▼の印と選択肢の箱があります。
  • 会話の台本: dialogue.txtの@label、name、ja/enのページ、choice、if [!]flag/item、set、clear、give、take、goto、endを、ラベルの表付きの1本の命令のvectorに変換し、起動時に全部確かめます(ファイル:行: 説明)。DialogueRunner::next()は10 000命令の上限付きでページまで命令を実行し、物語の変化を全て出力します。
  • アイテム: items.txtがアイコンと2か国語の名前・説明を持つ種類を決めます。持ち物はWorldの並んだ一覧です。アイテムは宝箱と地面から来て、コードで作る1ページのお知らせで知らせます。InventorySceneが其れを並べます。
  • 村の人: Npcはidle又はwanderの振る舞いを持つCharacterで、タイマー1つで動き、家への引き綱があり、全てにぶつかり、話しかけるとこちらを向きます。NPCはシーンの状態です(入り直すと元に戻ります)。各マップのRngの種はマップの名前のFNV-1aのハッシュで、std::hashは標準ライブラリごとに違うからです。
  • クエスト: 3つの印と持ち物を台本のifが調べます(一番進んだ状態から)。if=/unless=付きの物は印と一緒に現れたり消えたりするので、set gate_openで門が無くなります。

35.15 課題

  1. ★ 門が開いた後のお母さんの台詞を足して下さい。@motherの最初の行にif flag gate_open mother_gateを入れ、nameとページ付きの新しい@mother_gateのブロックを作ります。コンパイルし直さずに(ゲームを再起動するだけで)、門が開いた後のお母さんは新しい台詞を言い、其の前は今まで通りのはずです。アトラスに無い漢字を使うと、コンソールにcharacter not in the fontの警告が1回出て、箱には?が出るはずです。35.3節のJIS第1水準のpixel12に替えると、其の漢字も出るはずです。
  2. ★ DialogueSceneに、Tで切り替える文字の速さの設定(遅い:速さを半分、普通、一瞬)を足して下さい。「一瞬」では全てのページが最初のフレームで全部出るので、スペースを押す度に次のページへ進むはずです。「遅い」では、村長の44文字のページは日本語で出し終わるのに約2.9秒かかるはずです。
  3. ★★ ぶら下げを実装して下さい。wrapTextで、入らない単位が禁則の文字で終わり、はみ出しが1文字分の幅以下なら、今の行に残します。村長の「お礼にこの古い鍵をやろう。野原の庭の門の鍵じゃよ。」は300 pxの1行に収まり、「。」は292 pxの余白から8 pxはみ出して其のマスはx = 314、丁度箱の右の縁で終わり、2行目は無くなるはずです。
  4. ★★ 行末禁則を足して下さい。開き括弧「『(は行の終わりに来てはいけないので、後ろの単位にくっつけます。「あ」23文字の後に「村長の家」を続けて試して下さい。今は1行目が「「」で終わります(24文字、288 px)。直した後は23文字の「あ」(276 px)の後で終わり、2行目が「「村長の家」」で始まるはずです。
  5. ★★ 起動時にアイテムの名前を確かめて下さい。命令を順に見て、items.findが知らない名前のgive、take、if itemを全てファイル:行: 説明で報告するbool DialogueScript::checkItems(const std::string &path, const ItemTable &items) constを足し、両方のファイルを読んだ後でmainから呼びます。本物の台本は通るはずです。41行目をgive keyyにしたコピーでは、ゲームはgames/rpg/assets/dialogue.txt:41: … keyyで始まるのを拒むはずです。おまけとして、Worldがマップを読む時に、宝箱と落ちている物のitem=も同じ様に確かめて下さい。
  6. ★★ 村の人に場所を覚えさせて下さい。MapScene::exit()で各NPCの足元の箱をWorldに(map/nameをキーにして)しまい、setUp()でマップのファイルの位置の代わりに使います。野原から戻ると、ミナは置いて来た所に立っていて、散歩は今まで通り家の場所から32 px以内に収まるはずです。
  7. ★★★ 持ち物からアイテムを使える様にして下さい。選んだアイテムの上でスペースを押すと、台本に@use_<id>があれば(DialogueScript::has)其の会話を持ち物の画面の上に重ねて動かします。take appleと「おいしい!」/「Delicious!」のページを持つ@use_appleを足します。りんごを使うとお知らせが出て、記録にtake appleが出て、箱を閉じると一覧からりんごが消えているはずです。@use_のブロックの無いアイテムでは何も起きないはずです。

DIFFをダウンロード

プロジェクトをダウンロード(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)

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