スクリプト実例集

このページでは、コピペで使える実例を紹介します。

共通処理

場所を指定しての梯子・階段移動

場所を指定して移動するには以下の方法があります。

方法1 - デフォルトの Up, Down タイルを使用

  1. メニュー > データベース > タイルの設定を開く... を選択
  2. デフォルトで左から4番目にあるDown タイルをクリックして選択
  3. スクリプトの種類で個別に記述を選択
  4. 共通クリプトを以下のように書き換え
    var yes = yesno(StringTable.get("Stairs down --- Take them?"));
    if (yes) {
    	setLocation(-1);
    }
  5. 同様のことを Up タイルにも設定
  6. OK を押下してダイアログを閉じる
  7. イベントレイヤーを選択、先ほど設定したDown タイルを選択
  8. 任意の位置にイベントを作成しイベントエディタを開く
  9. スクリプトに以下を記述、OK を押下してダイアログを閉じる
    if (yes) {
    	setLocation(0, 10, 10, Direction.SOUTH); // 10, 10 の位置に移動して向いている方向は南にする。
    }

方法2 - 任意の上り下り階段タイルを使用

  1. メニュー > データベース > タイルの設定を開く... を選択
  2. 下り階段に使用したい下りタイルをクリックして選択
  3. スクリプトの種類で個別に記述を選択
  4. 共通クリプトを以下のように書き換え
    function down(x, y, direction) {
    	if (yesno(StringTable.get("Stairs down --- Take them?"))) {
    		setLocation(-1, x, y, direction);
    	}
    }
  5. 同様のことを 上りタイルにも設定
  6. OK を押下してダイアログを閉じる
  7. イベントレイヤーを選択、先ほど設定した下りタイルを選択
  8. 任意の位置にイベントを作成しイベントエディタを開く
  9. スクリプトに以下を記述、OK を押下してダイアログを閉じる
    down(10, 10, 0);  // 10, 10 の位置に移動して向いている方向は変更しない。
特定のアイテム所持でピットを防ぐ

タイルの設定でピットにしたいタイルを選択、以下のスクリプトを共通スクリプトに設定してください。

function centerMsg(text: String) {
	var fontSize = 10 * WIN_RATIO;
	var margin = 16 * WIN_RATIO;
	var w = margin + text.length() * fontSize;
	var h = margin + fontSize;
	var x = (Renderer.getWidth() - w) / 2;
	var y = (Renderer.getHeight()- h) / 2;
	msg(text.toFullWidth(), x, y, w, h);
}

function onPit() {
	if (Player.hasItem("ふゆうせき")) {
		centerMsg(StringTable.get("ふゆうしている"));
	} else {
		centerMsg(StringTable.get("A Pit!"));
		pit();
	}
}
onPit();
鍵のかかった扉

タイルの設定で鍵付き扉にしたいタイルを選択、以下のスクリプトを共通スクリプトに設定してください。

function tryToOpenLockedDoor(itemId: String)
{
	if (hasItem(itemId)) {
		Player.goForward();
		Audio.playSound("door.wav");
	} else {
		msg(StringTable.get("The door is locked"));
	}
}

// 使用例
// tryToOpenLockedDoor("せいどうのかぎ");

図を参考に、当たり判定、扉の方向、トリガーを設定してください。

鍵のかかった扉編集画面
エレベーター

タイルの設定でエレベーターにしたいタイルを選択、以下のスクリプトを共通スクリプトに設定してください。

function elevator(floors)
{
	msg(MessageTable.get("壁にいくつかのボタンがある"));

	//var array = ["【A】", "【B】", "【C】", "(X)" + StringTable.get("Close") ];
	var array = new Array();
	for (var i = 0; i < floors.length(); ++i) {
		array.push("【" + String.fromCharCode('A' + i) + "】");
	}
	array.push("(X)" + StringTable.get("Close"));
	//
	var i = menu(array.join("\n"));
	if (i >= 0 && i < floors.length()){
		StringTable.set("[choice]", array[i]);
		msg(StringTable.get("[choice] を押した"));
		if (floors[i] != 0)
			Player.setLocation(floors[i]);
	}
}
// 使用例
// elevator([0, -1, -2]);

その他

画像の表示・非表示
var image = new Image();
image.load("Graphics/Images/town.jpg");       // 画像を読み込む
image.setBounds(0, 0, Renderer.getWidth(), Renderer.getHeight()); // 画像が画面全体に表示されるように設定
image.setColorKey(0x00ff00); // 透過色を緑色に設定
Renderer.addObject(image);   // 描画対象を追加
msg("画像表示確認");
Renderer.removeObject(image);// 描画対象を取り除く
msg("画像非表示確認");
お金を取り除く
if (Player.removeGold(100)) {
	msg("100 G.P has been removed!");
} else {
	msg("You don't have enough G.P!");
}
経験値を獲得する
// PC に経験値を分配する
function DistributeExp(exp, type)
{
	var pcs = Player.getPlayerCharacters();
	// 分配するPCがいないなら終了
	if (pcs.length() == 0)
		return 0;
	// タイプに応じて分配方法を変更
	if (type == 1) {
		// パーティ全体で経験値を分配する場合
		exp = exp / pcs.length();
	}
	else if (type == 2) {
		// 生存PCに経験値を分配する場合
		var survivingCharacterCount = 0;
		for (var i = 0; i < pcs.length(); ++i) {
			var pc = pcs[i];
			if (pc.isAlive())
				++survivingCharacterCount;
		}
		if (survivingCharacterCount == 0)
			return 0;
		exp = exp / survivingCharacterCount;
	}

	// 経験値を分配
	for (var i = 0; i < pcs.length(); ++i) {
		var pc = pcs[i];
		if (type == 2) {
			if (pc.isDead())
				continue;
		}
		pc.gainExp(exp);
	}
	return exp;
}

msg("Each character gains " + DistributeExp(10000, 0) + " EXP");
msg("Each character gains " + DistributeExp(10000, 1) + " EXP");
msg("Each surviving character gains " + DistributeExp(10000, 2) + " EXP");
文字入力後にワープ
var title = StringTable.get("暗号は?");
var answer = SceneManager.riddle(title);
if (answer == "あんごう") {
	msg("正解!ワープします!");
	warp(0, 0);
} else if (!answer.isEmpty()) {
	msg("違います!");
}
ダメージ床
var array: Array = Player.getPlayerCharacters();
for (var i = 0; i < array.length; ++i) {
    var pc: PlayerCharacter = array[i];
    pc.setHP(pc.getHP()-1);
}

コンフィグ画面の作成

Game.txt 内で使用している Config.txt 作成手順について解説します。
Config.txt を開き、内容を全て削除した状態で始めてください。

Game.txt 内で使用される関数を定義
// Config.txt に以下の内容を記述してください
// 毎フレーム Game.txt から使用される ConfigScene 関数を定義する
function ConfigScene(g: Graphics)
{
	// 何も記述していないので、真っ暗な画面が表示され、キー入力も受け付けない状態です
}
キャンセルボタン押下でタイトル画面に戻れるようにする
// Config.txt に以下の内容を記述してください
// 毎フレーム Game.txt から使用される ConfigScene 関数を定義する
function ConfigScene(g: Graphics)
{
	// キャンセルボタンでタイトル画面に戻る処理
	if (Key.isCancelKeyTyped()) {
		SceneManager.changeScene("Title");
	}
}
ヘルプを描画
// Config.txt に以下の内容を記述してください
// 毎フレーム Game.txt から使用される ConfigScene 関数を定義する
function ConfigScene(g: Graphics)
{
	// キャンセルボタンでタイトル画面に戻る処理
	if (Key.isCancelKeyTyped()) {
		SceneManager.changeScene("Title");
	}
	
	// ヘルプを画面下部中央に表示
	var titleText = 
		"Press [A] to change. Press [B] to cancel\n"
		"\n"
		"Press [START] to exit                   ";
	g.setTextAlign(TextAlign.CENTER); // テキストを中央寄せに設定
	g.setFontSize(Graphics.getDefaultFontSize()*0.8);
	g.drawString(titleText, Renderer.getWidth()/2, Renderer.getHeight()-Graphics.getDefaultFontSize()*6);
}
上下キー入力で項目を選択
// Config.txt に以下の内容を記述してください
var cursorY = 0; // 上下入力で変更されるカーソル位置

// 毎フレーム Game.txt から使用される ConfigScene 関数を定義する
function ConfigScene(g: Graphics)
{
	// キャンセルボタンでタイトル画面に戻る処理
	if (Key.isCancelKeyTyped()) {
		SceneManager.changeScene("Title");
	}

	// 上下入力で cursorY を変更
	if (Key.isTyped(Key.UP)) {
		cursorY--;
	}
	else if (Key.isTyped(Key.DOWN)) {
		cursorY++;
	}

	// 選択項目を表示
	var fontSize = Graphics.getDefaultFontSize();
	var x = fontSize;
	var y = fontSize;
	g.setTextAlign(TextAlign.LEFT); // テキストを左寄せに設定
	g.setFontSize(fontSize);
	g.drawString("・", x-fontSize, y + cursorY*fontSize); // カーソルを描画
	g.drawString("Item 1", x, y);
	g.drawString("Item 2", x, y+fontSize);
	g.drawString("Item 3", x, y+fontSize*2);

	// ヘルプを画面下部中央に表示
	var titleText = 
		"Press [A] to change. Press [B] to cancel\n"
		"\n"
		"Press [START] to exit                   ";
	g.setTextAlign(TextAlign.CENTER); // テキストを中央寄せに設定
	g.setFontSize(Graphics.getDefaultFontSize()*0.8);
	g.drawString(titleText, Renderer.getWidth()/2, Renderer.getHeight()-Graphics.getDefaultFontSize()*6);
}
選択項目を配列で定義、項目外にカーソル位置が出ないようにする
// Config.txt に以下の内容を記述してください
var cursorY = 0; // 上下入力で変更されるカーソル位置
var configTitles = ["Language", "Credits", "Resolution" ]; // 選択項目を配列で定義

// 毎フレーム Game.txt から使用される ConfigScene 関数を定義する
function ConfigScene(g: Graphics)
{
	// キャンセルボタンでタイトル画面に戻る処理
	if (Key.isCancelKeyTyped()) {
		SceneManager.changeScene("Title");
	}
	// 上下入力で cursorY を変更
	if (Key.isTyped(Key.UP)) {
		cursorY--;
		if (cursorY < 0)
			cursorY = configTitles.length() - 1;
	}
	else if (Key.isTyped(Key.DOWN)) {
		cursorY++;
		if (cursorY > configTitles.length() - 1)
			cursorY = 0;
	}
	
	// 選択項目を表示
	var fontSize = Graphics.getDefaultFontSize();
	var x = fontSize;
	var y = fontSize;
	g.setTextAlign(TextAlign.LEFT); // テキストを左寄せに設定
	g.setFontSize(fontSize);
	g.drawString("・", x-fontSize, y + cursorY*fontSize); // カーソルを描画
	for (var i = 0; i < configTitles.length(); ++i) {
		g.drawString(configTitles[i], x, y);
		y += fontSize;
	}
	
	// ヘルプを画面下部中央に表示
	var titleText = 
		"Press [A] to change. Press [B] to cancel\n"
		"\n"
		"Press [START] to exit                   ";
	g.setTextAlign(TextAlign.CENTER); // テキストを中央寄せに設定
	g.setFontSize(fontSize*0.8);
	g.drawString(titleText, Renderer.getWidth()/2, Renderer.getHeight()-fontSize*6);
}
それぞれの処理を関数に分割
// Config.txt に以下の内容を記述してください
var cursorY = 0; // 上下入力で変更されるカーソル位置
var configTitles = ["Language", "Credits", "Resolution" ]; // 選択項目を配列で定義

function ConfigScene(g: Graphics)
{
	ConfigUpdate();
	ConfigDraw(g);
}

// 毎フレームのキー入力処理
function ConfigUpdate()
{
	// キャンセルボタンでタイトル画面に戻る処理
	if (Key.isCancelKeyTyped()) {
		SceneManager.changeScene("Title");
	}
	// 上下入力で cursorY を変更
	if (Key.isTyped(Key.UP)) {
		cursorY--;
		if (cursorY < 0)
			cursorY = configTitles.length() - 1;
	}
	else if (Key.isTyped(Key.DOWN)) {
		cursorY++;
		if (cursorY > configTitles.length() - 1)
			cursorY = 0;
	}
}

function ConfigDraw(g: Graphics)
{
	// 選択項目を表示
	var fontSize = Graphics.getDefaultFontSize();
	var x = fontSize;
	var y = fontSize;
	g.setTextAlign(TextAlign.LEFT); // テキストを左寄せに設定
	g.setFontSize(fontSize);
	g.drawString("・", x-fontSize, y + cursorY*fontSize);
	for (var i = 0; i < configTitles.length(); ++i) {
		g.drawString(configTitles[i], x, y);
		y += fontSize;
	}
	
	// ヘルプを画面下部中央に表示
	var titleText = 
		"Press [A] to change. Press [B] to cancel\n"
		"\n"
		"Press [START] to exit                   ";
	g.setTextAlign(TextAlign.CENTER); // テキストを中央寄せに設定
	g.setFontSize(fontSize*0.8);
	g.drawString(titleText, Renderer.getWidth()/2, Renderer.getHeight()-fontSize*6);
}
オプションの切り替え
// Config.txt に以下の内容を記述してください
var cursorY = 0; // 上下入力で変更されるカーソル位置
var configTitles = ["Language", "Credits", "Resolution" ]; // 選択項目を配列で定義
var configOnSelections = ["Japanese", "On", "640×480" ]; // オプション1
var configOffSelections = ["English", "Off", "854×480" ];// オプション2
var configSettings = [0, 0, 0]; // オプションの値を保存

function ConfigScene(g: Graphics)
{
	ConfigUpdate();
	ConfigDraw(g);
}

// 毎フレームのキー入力処理
function ConfigUpdate()
{
	// キャンセルボタンでタイトル画面に戻る処理
	if (Key.isCancelKeyTyped()) {
		SceneManager.changeScene("Title");
	}
	// 決定ボタンで選択項目のオプションの値を切り替え
	if (Key.isOkKeyTyped()) {
		if (configSettings[cursorY] == 0)
			configSettings[cursorY] = 1;
		else
			configSettings[cursorY] = 0;
	}
	// 上下入力で cursorY を変更
	if (Key.isTyped(Key.UP)) {
		cursorY--;
		if (cursorY < 0)
			cursorY = configTitles.length() - 1;
	}
	else if (Key.isTyped(Key.DOWN)) {
		cursorY++;
		if (cursorY > configTitles.length() - 1)
			cursorY = 0;
	}
}

function ConfigDraw(g: Graphics)
{
	// 選択項目を表示
	var fontSize = Graphics.getDefaultFontSize();
	var x = fontSize;
	var y = fontSize;
	g.setTextAlign(TextAlign.LEFT); // テキストを左寄せに設定
	g.setFontSize(fontSize);
	g.drawString("・", x-fontSize, y + cursorY*fontSize);
	for (var i = 0; i < configTitles.length(); ++i) {
		g.setTextColor(#fff);
		g.drawString(configTitles[i], x, y);
		// オプションを表示
		if (configSettings[i] == 0) {
			g.setTextColor(#f00);
			g.drawString(configOnSelections[i], x + fontSize*10, y);
			g.setTextColor(#fff);
			g.drawString(configOffSelections[i], x + fontSize*17, y);
		}
		else {
			g.drawString(configOnSelections[i], x + fontSize*10, y);
			g.setTextColor(#f00);
			g.drawString(configOffSelections[i], x + fontSize*17, y);
		}
		y += fontSize;
	}
	
	// ヘルプを画面下部中央に表示
	var titleText = 
		"Press [A] to change. Press [B] to cancel\n"
		"\n"
		"Press [START] to exit                   ";
	g.setTextColor(#fff);
	g.setTextAlign(TextAlign.CENTER); // テキストを中央寄せに設定
	g.setFontSize(fontSize*0.8);
	g.drawString(titleText, Renderer.getWidth()/2, Renderer.getHeight()-fontSize*6);
}
言語の切り替えとキャンセル処理
// Config.txt に以下の内容を記述してください
var cursorY = 0; // 上下入力で変更されるカーソル位置
var configTitles = ["Language", "Credits", "Resolution" ]; // 選択項目を配列で定義
var configOnSelections = ["Japanese", "On", "640×480" ]; // オプション1
var configOffSelections = ["English", "Off", "854×480" ];// オプション2
var configSettings = [System.isLanguagePrimary(), 0, 0]; // オプションの値を保存、キャンセルした場合に元の値に戻せるようにする

function ConfigScene(g: Graphics)
{
	ConfigUpdate();
	ConfigDraw(g);
}

// 選択肢の位置「index」に応じてオプション1がオンの場合に true を返す
function ConfigIsOn(index)
{
	if (index == 0) return System.isLanguagePrimary();
	if (index == 1) return configSettings[index] == 0;
	if (index == 2) return configSettings[index] == 0;
	return false;
}

// 選択肢の位置「index」に応じてオプションの値を切り替える
function ConfigSwitch(index)
{
	if (index == 0) {
		// 設定言語を第一言語「0」と第二言語「1」を切り替える
		System.toggleLanguages();
	}
	else if (index == 1) {
		if (configSettings[index] == 0)
			configSettings[index] = 1;
		else
			configSettings[index] = 0;
	}
	else if (index == 2) {
		if (configSettings[index] == 0)
			configSettings[index] = 1;
		else
			configSettings[index] = 0;
	}
}

// キャンセルした場合、設定した値を元に戻し、タイトル画面に戻る
function ConfigCancel()
{
	if (configSettings[0] != System.isLanguagePrimary())
		System.toggleLanguages();
	SceneManager.changeScene("Title");
}

// 毎フレームのキー入力処理
function ConfigUpdate()
{
	// キャンセルボタンでタイトル画面に戻る処理
	if (Key.isCancelKeyTyped()) {
		ConfigCancel();
	}
	// 決定ボタンで選択項目のオプションを切り替え
	if (Key.isOkKeyTyped()) {
		ConfigSwitch(cursorY);
	}
	// 上下入力で cursorY を変更
	if (Key.isTyped(Key.UP)) {
		cursorY--;
		if (cursorY < 0)
			cursorY = configTitles.length() - 1;
	}
	else if (Key.isTyped(Key.DOWN)) {
		cursorY++;
		if (cursorY > configTitles.length() - 1)
			cursorY = 0;
	}
}

function ConfigDraw(g: Graphics)
{
	// 選択項目を表示
	var fontSize = Graphics.getDefaultFontSize();
	var x = fontSize;
	var y = fontSize;
	g.setTextAlign(TextAlign.LEFT); // テキストを左寄せに設定
	g.setFontSize(fontSize);
	g.drawString("・", x-fontSize, y + cursorY*fontSize);
	for (var i = 0; i < configTitles.length(); ++i) {
		g.setTextColor(#fff);
		g.drawString(StringTable.get(configTitles[i]), x, y); // StringTable.get() で設定言語に応じた文字列を取得
		// オプションを表示
		if (ConfigIsOn(i)) {
			g.setTextColor(#f00);
			g.drawString(StringTable.get(configOnSelections[i]), x + fontSize*10, y);
			g.setTextColor(#fff);
			g.drawString(StringTable.get(configOffSelections[i]), x + fontSize*17, y);
		}
		else {
			g.drawString(StringTable.get(configOnSelections[i]), x + fontSize*10, y);
			g.setTextColor(#f00);
			g.drawString(StringTable.get(configOffSelections[i]), x + fontSize*17, y);
		}
		y += fontSize;
	}
	
	// ヘルプを画面下部中央に表示
	var titleText = 
		"Press [A] to change. Press [B] to cancel\n"
		"\n"
		"Press [START] to exit                   ";
	g.setTextColor(#fff);
	g.setTextAlign(TextAlign.CENTER); // テキストを中央寄せに設定
	g.setFontSize(fontSize*0.8);
	g.drawString(titleText, Renderer.getWidth()/2, Renderer.getHeight()-fontSize*6);
}
設定内容を保存して終了
// Config.txt に以下の内容を記述してください
var cursorY = 0; // 上下入力で変更されるカーソル位置
var configTitles = ["Language", "Credits", "Resolution" ]; // 選択項目を配列で定義
var configOnSelections = ["Japanese", "On", "640×480" ]; // オプション1
var configOffSelections = ["English", "Off", "854×480" ];// オプション2
var configSettings = [System.isLanguagePrimary(), 0, 0]; // オプションの値を保存

function ConfigScene(g: Graphics)
{
	ConfigUpdate();
	ConfigDraw(g);
}

// 選択肢の位置「index」に応じてオプション1がオンの場合に true を返す
function ConfigIsOn(index)
{
	if (index == 0) return System.isLanguagePrimary();
	if (index == 1) return configSettings[index] == 0;
	if (index == 2) return configSettings[index] == 0;
	return false;
}

// 選択肢の位置「index」に応じてオプションの値を切り替える
function ConfigSwitch(index)
{
	if (index == 0) {
		// 設定言語を第一言語「0」と第二言語「1」を切り替える
		System.toggleLanguages();
	}
	else if (index == 1) {
		if (configSettings[index] == 0)
			configSettings[index] = 1;
		else
			configSettings[index] = 0;
	}
	else if (index == 2) {
		if (configSettings[index] == 0)
			configSettings[index] = 1;
		else
			configSettings[index] = 0;
	}
}

// 設定した値を保存する
function ConfigOK()
{
	System.save();
	SceneManager.changeScene("Title");
}

// キャンセルした場合、設定した値を元に戻し、タイトル画面に戻る
function ConfigCancel()
{
	if (configSettings[0] != System.isLanguagePrimary())
		System.toggleLanguages();
	SceneManager.changeScene("Title");
}

// 毎フレームのキー入力処理
function ConfigUpdate()
{
	if (Key.isCancelKeyTyped()) {
		// キャンセルボタンでタイトル画面に戻る処理
		ConfigCancel();
	}
	else if (Key.isTyped(Key.START)) {
		// 決定ボタンの処理
		ConfigOK();
	}
	else if (Key.isOkKeyTyped()) {
		// 決定ボタンの処理
		if (cursorY == configTitles.length()) {
			// 選択項目外の場合は設定内容を保存して終了
			ConfigOK();
		}
		else {
			// 選択項目のオプションを切り替え
			ConfigSwitch(cursorY);
		}
	}
	// 上下入力で cursorY を変更
	if (Key.isTyped(Key.UP)) {
		cursorY--;
		if (cursorY < 0)
			cursorY = configTitles.length();
	}
	else if (Key.isTyped(Key.DOWN)) {
		cursorY++;
		if (cursorY > configTitles.length())
			cursorY = 0;
	}
}

function ConfigDraw(g: Graphics)
{
	// 選択項目を表示
	var fontSize = Graphics.getDefaultFontSize();
	var x = fontSize;
	var y = fontSize;
	g.setTextAlign(TextAlign.LEFT); // テキストを左寄せに設定
	g.setFontSize(fontSize);
	g.drawString("・", x-fontSize, y + cursorY*fontSize);
	for (var i = 0; i < configTitles.length(); ++i) {
		g.setTextColor(#fff);
		g.drawString(StringTable.get(configTitles[i]), x, y); // StringTable.get() で設定言語に応じた文字列を取得
		// オプションを表示
		if (ConfigIsOn(i)) {
			g.setTextColor(#f00);
			g.drawString(StringTable.get(configOnSelections[i]), x + fontSize*10, y);
			g.setTextColor(#fff);
			g.drawString(StringTable.get(configOffSelections[i]), x + fontSize*17, y);
		}
		else {
			g.drawString(StringTable.get(configOnSelections[i]), x + fontSize*10, y);
			g.setTextColor(#f00);
			g.drawString(StringTable.get(configOffSelections[i]), x + fontSize*17, y);
		}
		y += fontSize;
	}
	
	// タイトル画面に戻る選択肢を表示
	g.setTextColor(#fff);
	g.drawString(StringTable.get("Return to Title"), x, y);
	
	// ヘルプを画面下部中央に表示
	var titleText = 
		"Press [A] to change. Press [B] to cancel\n"
		"\n"
		"Press [START] to exit                   ";
	g.setTextColor(#fff);
	g.setTextAlign(TextAlign.CENTER); // テキストを中央寄せに設定
	g.setFontSize(fontSize*0.8);
	g.drawString(titleText, Renderer.getWidth()/2, Renderer.getHeight()-fontSize*6);
}
完成した Config.txt
var configTitles = ["Language", "Credits", "Resolution" ];
var configOnSelections = ["Japanese", "On", "640×480" ];
var configOffSelections = ["English", "Off", "854×480" ];
var configSettings = [ System.isLanguagePrimary(), getFlag("Credit"), [Renderer.getWidth(), Renderer.getHeight()] ];
var cursorX = 0;
var cursorY = 0;

function ConfigIsOn(index)
{
	if (index == 0) return System.isLanguagePrimary();
	if (index == 1) return !getFlag("Credit");
	if (index == 2) return Renderer.getWidth() == 640 && Renderer.getHeight() == 480;
	return false;
}

function ConfigSwitch(index)
{
	if (index == 0) {
		System.toggleLanguages();
	}
	if (index == 1) {
		setFlag("Credit", ConfigIsOn(index));
	}
	if (index == 2) {
		if (ConfigIsOn(index))
			GameSettings.setResolution(854, 480);
		else
			GameSettings.setResolution(640, 480);
	}
}

function ConfigOK()
{
	//sceneFunction = TitleScene;
	save();
	changeScene("Title");
}

function ConfigCancel()
{
	if (configSettings[0] != System.isLanguagePrimary())
		System.toggleLanguages();
	setFlag("Credit", configSettings[1]);
	GameSettings.setResolution(configSettings[2][0], configSettings[2][1]);
	changeScene("Title");
}

// Game.txt の onEnterFrame() で毎フレームごとにする処理
function ConfigScene(g: Graphics)
{
	ConfigUpdate();
	ConfigDraw(g);
}

function ConfigUpdate()
{
	if (Key.isTyped(Key.RIGHT)) {
		cursorX++;
	}
	else if (Key.isTyped(Key.LEFT)) {
		cursorX--;
	}
	else if (Key.isTyped(Key.UP)) {
		cursorY--;
		if (cursorY < 0)
			cursorY = configTitles.length();
	}
	else if (Key.isTyped(Key.DOWN)) {
		cursorY++;
		if (cursorY > configTitles.length())
			cursorY = 0;
	}
	else if (Key.isCancelKeyTyped()) {
		ConfigCancel();
	}
	else if (Key.isTyped(Key.START)) {
		ConfigOK();
	}
	else if (Key.isOkKeyTyped()) {
		ConfigSwitch(cursorY);
		if (cursorY == configTitles.length()) {
			ConfigOK();
		}
	}
}

function ConfigDraw(g: Graphics)
{
	// GameSettings.setResolution() でサイズが変更された場合はリサイズ
	if (g.getWidth() != Renderer.getWidth() || g.getHeight() != Renderer.getHeight()) {
		g.setSize(Renderer.getWidth(), Renderer.getHeight());
	}
	// フォントサイズを解像度に応じて変更
	FONT_SIZE = Graphics.getDefaultFontSize();

	// draw frame
	var x = FONT_SIZE;
	var y = FONT_SIZE;
	g.drawFrame(x, y, Renderer.getWidth()-x*2, Renderer.getHeight()-y*2);

	// draw config items
	var width  = FONT_SIZE*10;
	var width2 = FONT_SIZE*7;
	var height = FONT_SIZE*1.6;
	x = (Renderer.getWidth()-width-width2*2)/2;
	y = FONT_SIZE*8;//FONT_SIZE*2;
	g.setFontSize(FONT_SIZE*1.4);
	for (var i = 0; i < configTitles.length; ++i) {
		var focused = cursorY == i;
		ConfigDrawItem(g, configTitles[i],        x,              y, width, height, true, focused);
		ConfigDrawItem(g, configOnSelections[i] , x+width,        y, width2, height, ConfigIsOn(i), focused);
		ConfigDrawItem(g, configOffSelections[i], x+width+width2, y, width2, height, !ConfigIsOn(i), focused);
		y += height;
	}
	ConfigDrawItem(g, "Return to Title", x, y, width+width2*2, height, true, cursorY == configTitles.length);

	// draw help
	var titleText = 
		"Press [A] to change. Press [B] to cancel\n"
		"\n"
		"Press [START] to exit                   ";
	g.setFontSize(FONT_SIZE*0.8);
	g.drawString(titleText, Renderer.getWidth()/2, Renderer.getHeight()-FONT_SIZE*6);
}

function ConfigDrawItem(g: Graphics, text: String, x, y, width, height, selected, focused)
{
	// draw background
	if (focused) {
		g.setFillColor(#f00);
	}
	else {
		g.setFillColor(#2d2d2d);
	}
	g.fillRect(x, y, width, height);
	text = StringTable.get(text);
	// draw text
	if (selected) {
		g.drawBorderString(text.toUpperCase(), x+width/2, y+2, #ff3, 0);
	}
	else {
		g.drawBorderString(text.toUpperCase(), x+width/2, y+2, #111, 0);
	}
	
	// draw frame
	g.drawFrame(x, y, width, height);
}