white-thirst/www/js/plugins/Test.js
2025-01-07 13:09:58 -06:00

445 lines
12 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*:
* @plugindesc TimingGame Plugin
* @author cube
*
* @help
* Plugin Command:
* TimingGame play a b c
*
* play以降の引数は全て数値のみ
* aはルマ値
* スコアの加算は100点固定
* スコア>=ノルマ値で終了
*
* bはミス許容値
* ミスできる回数
* ミス回数>=ミス許容値で終了
*
* cは使用する変数
* プラグインの初期化で必ず0にする
* ルマ成功は1
* ルマ失敗は2
* にする
*
* @param titleLabelSetting
* @text タイトルラベル表示設定
* @type struct<TextBox>
* @default {"word":"ゲーム","pointX":"320","pointY":"0","width":"300","height":"50","fontSize":"30"}
*
* @param scoreLabelSetting
* @text スコアラベル表示設定
* @type struct<TextBox>
* @default {"word":"スコア","pointX":"320","pointY":"100","width":"200","height":"30","fontSize":"30"}
*
* @param scoreSetting
* @text スコア表示設定
* @type struct<TextBox>
* @default {"word":"使用しません","pointX":"420","pointY":"100","width":"200","height":"30","fontSize":"30"}
*
* @param missLabelSetting
* @text ミスラベル表示設定
* @type struct<TextBox>
* @default {"word":"ミス回数","pointX":"320","pointY":"50","width":"200","height":"30","fontSize":"30"}
*
* @param missSetting
* @text ミス表示設定
* @type struct<TextBox>
* @default {"word":"使用しません","pointX":"520","pointY":"50","width":"200","height":"30","fontSize":"30"}
*
* @param frame
* @text 枠
* @desc 枠の設定
* @type struct<Resource>
* @default {"imageFile":"frame","pointX":"0","pointY":"120"}
*
* @param scale
* @text 動線
* @desc 動線の設定
* @type struct<Resource>
* @default {"imageFile":"scale","pointX":"4","pointY":"137"}
*
* @param line1
* @text 静線1
* @desc 静線1の設定
* @type struct<Resource>
* @default {"imageFile":"line","pointX":"250","pointY":"137"}
*
* @param line2
* @text 静線2
* @desc 静線2の設定
* @type struct<Resource>
* @default {"imageFile":"line","pointX":"350","pointY":"137"}
*
* @param speed
* @text 速度
* @type number
* @min 0
* @max 1000
* @default 10
*
*/
/*~struct~Resource:
* @param imageFile
* @text 画像素材
* @type file
* @require 1
* @dir img/pictures
* @default file
*
* @param pointX
* @text X座標
* @desc 素材を配置するX座標
* @type number
* @default 0
*
* @param pointY
* @text Y座標
* @desc 素材を配置するY座標
* @type number
* @default 0
*/
/*~struct~TextBox:
* @param word
* @text 表示文字列
* @desc テキストボックスに記載する文字列
* @type string
* @default
*
* @param pointX
* @text X座標
* @desc テキストボックスを配置するX座標
* @type number
* @default 0
*
* @param pointY
* @text Y座標
* @desc テキストボックスを配置するY座標
* @type number
* @default 0
*
* @param width
* @text 横幅
* @desc 作製するテキストボックスの横幅
* @type number
* @default 20
*
* @param height
* @text 高さ
* @desc 作製するテキストボックスの高さ
* @type number
* @default 20
*
* @param fontSize
* @text フォントサイズ
* @desc 表示するテキストのフォントサイズ
* @type number
* @default 10
*/
function Scene_Test() {
this.initialize.apply(this, arguments);
}
Scene_Test.prototype = Object.create(Scene_Base.prototype);
Scene_Test.prototype.constructor = Scene_Test;
Scene_Test.prototype.initialize = function () {
Scene_Base.prototype.initialize.call(this);
};
Scene_Test.prototype.create = function () {
Scene_Base.prototype.create.call(this);
};
//設定
Scene_Test.prototype.start = function () {
Scene_Base.prototype.start.call(this);
//パラメータ関連
var parameters = PluginManager.parameters("Test");
var title = JSON.parse(parameters.titleLabelSetting);
var scoreLabel = JSON.parse(parameters.scoreLabelSetting);
var score = JSON.parse(parameters.scoreSetting);
var missLabel = JSON.parse(parameters.missLabelSetting);
var miss = JSON.parse(parameters.missSetting);
var frame = JSON.parse(parameters.frame);
var scale = JSON.parse(parameters.scale);
var line1 = JSON.parse(parameters.line1);
var line2 = JSON.parse(parameters.line2);
//背景透過処理
this._backgroundSprite = new Sprite();
this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
this.addChild(this._backgroundSprite);
//画像リソース指定
this._frame_image = ImageManager.loadPicture(frame.imageFile);
this._scale_image = ImageManager.loadPicture(scale.imageFile);
this._line1_image = ImageManager.loadPicture(line1.imageFile);
this._line2_image = ImageManager.loadPicture(line2.imageFile);
//枠作製
this._frame_x = parseInt(frame.pointX);
this._frame_y = parseInt(frame.pointY);
this._frame = this.factory_frame();
//最低ライン位置
this._line1_x = parseInt(line1.pointX);
this._line1_y = parseInt(line1.pointY);
//最高ライン位置
this._line2_x = parseInt(line2.pointX);
this._line2_y = parseInt(line2.pointY);
//線作成
this.factory_line();
//ビート初期位置
this._scale_x = parseInt(scale.pointX);
this._scale_y = parseInt(scale.pointY);
//ビートの速度
this._speed = parseInt(parameters.speed);
//初期スコア
this._score = 0;
//初期ミス
this._miss = 0;
//合計期待値スコア
this._scoreMax = $gameSystem.ScoreMax;
//合計許容ミス
this._missMax = $gameSystem.MissMax;
//使用する変数
this._varNum = $gameSystem.VarNum;
//変数初期化
$gameVariables.setValue(this._varNum, 0);
//スコアの作成
this._score_text = this.factory_sprite_and_bitmap(
score.pointX,
score.pointY,
score.width,
score.height
);
this._score_text.bitmap.fontSize = score.fontSize;
this._score_text.bitmap.drawText(
this._score,
0,
0,
score.width,
score.height
);
this.addChild(this._score_text);
this._scoreSetting = score;
//スコアのラベル作成
this._score_str = this.factory_sprite_and_bitmap(
scoreLabel.pointX,
scoreLabel.pointY,
scoreLabel.width,
scoreLabel.height
);
this._score_str.bitmap.fontSize = scoreLabel.fontSize;
this._score_str.bitmap.drawText(
scoreLabel.word,
0,
0,
scoreLabel.width,
scoreLabel.height
);
this.addChild(this._score_str);
//ミスの作製
this._miss_text = this.factory_sprite_and_bitmap(
miss.pointX,
miss.pointY,
miss.width,
miss.height
);
this._miss_text.bitmap.fontSize = miss.fontSize;
this._miss_text.bitmap.drawText(this._miss, 0, 0, miss.width, miss.height);
this.addChild(this._miss_text);
this._missSetting = miss;
//ミスのラベル作成
this._miss_str = this.factory_sprite_and_bitmap(
missLabel.pointX,
missLabel.pointY,
missLabel.width,
missLabel.height
);
this._miss_str.bitmap.fontSize = missLabel.fontSize;
this._miss_str.bitmap.drawText(
missLabel.word,
0,
0,
missLabel.width,
missLabel.height
);
this.addChild(this._miss_str);
// タイトル作成
this._title_text = this.factory_sprite_and_bitmap(
title.pointX,
title.pointY,
title.width,
title.height
);
this._title_text.bitmap.fontSize = title.fontSize;
this._title_text.bitmap.drawText(title.word, 0, 0, title.width, title.height);
this.addChild(this._title_text);
};
//フレーム動作
Scene_Test.prototype.update = function () {
Scene_Base.prototype.update.call(this);
//ビート有る無し分岐
if (this._scale) {
//有れば速度分移動
this._scale.x += this._speed;
//線上限超えたらビート削除
if (this._scale.x > this._line2_x) {
this.removeChild(this._scale);
this._scale = null;
//ミス加算
this.update_miss_text(1);
}
} else {
//ビート作成
this._scale = this.factory_scale();
}
//決定ボタン押下時処理
if (Input.isTriggered("ok")) {
//ビート存在チェック
if (this._scale) {
//線内なら加点
if (this._scale.x > this._line1_x && this._scale.x < this._line2_x) {
//スコア更新
this.update_score_text(100);
} else {
//ミス加算
this.update_miss_text(1);
}
//ビート削除
this.removeChild(this._scale);
this._scale = null;
}
}
//クリア判定
this.check_clear();
};
//クリア判定関数
Scene_Test.prototype.check_clear = function () {
if (this._score >= this._scoreMax) {
//$gameMessage.add("クリア");
//変数
$gameVariables.setValue(this._varNum, 1);
SceneManager.pop();
} else if (this._miss >= this._missMax) {
//$gameMessage.add("失敗");
//変数
$gameVariables.setValue(this._varNum, 2);
SceneManager.pop();
}
};
//スコア更新関数
Scene_Test.prototype.update_score_text = function (addScore) {
this._score += Number(addScore);
this._score_text.bitmap.clear();
this._score_text.bitmap.drawText(
this._score,
0,
0,
this._scoreSetting.width,
this._scoreSetting.height
);
};
Scene_Test.prototype.update_miss_text = function (addMiss) {
this._miss += Number(addMiss);
this._miss_text.bitmap.clear();
this._miss_text.bitmap.drawText(
this._miss,
0,
0,
this._missSetting.width,
this._missSetting.height
);
};
//画面上の指定位置に作成する関数
Scene_Test.prototype.factory_sprite_and_bitmap = function (
x,
y,
width,
height
) {
var _sprite = new Sprite();
_sprite.bitmap = new Bitmap(width, height);
_sprite.x = x;
_sprite.y = y;
return _sprite;
};
//枠作成
Scene_Test.prototype.factory_frame = function () {
var _frame = new Sprite();
//使用画像、X座標、Y座標
_frame.bitmap = this._frame_image;
_frame.x = this._frame_x;
_frame.y = this._frame_y;
_frame.visible = true;
//画面上に表示
this.addChild(_frame);
return _frame;
};
//線作成
Scene_Test.prototype.factory_line = function () {
//最低ラインの作成
var _line = new Sprite();
//使用画像、X座標、Y座標
_line.bitmap = this._line1_image;
_line.x = this._line1_x;
_line.y = this._line1_y;
_line.visible = true;
//画面上に表示
this.addChild(_line);
//最高ラインの作成
var _line2 = new Sprite();
//使用画像、X座標、Y座標
_line2.bitmap = this._line2_image;
_line2.x = this._line2_x;
_line2.y = this._line2_y;
_line2.visible = true;
//画面上に表示
this.addChild(_line2);
};
//ビート作成(初期位置)
Scene_Test.prototype.factory_scale = function () {
var _scale = new Sprite();
//使用画像、X座標、Y座標
_scale.bitmap = this._scale_image;
_scale.x = this._scale_x;
_scale.y = this._scale_y;
_scale.visible = true;
//画面上に表示
this.addChild(_scale);
return _scale;
};
//実関数
(function () {
//コマンド関連
var _Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
//プラグインコマンドTestに対応
if (command === "TimingGame") {
//引数1
switch (args[0]) {
case "play":
//必須要素数
if (args.length >= 4) {
// 引数は数値のみ
if (isNaN(args[1]) || isNaN(args[2]) || isNaN(args[3])) {
break;
}
//開始
Game_System.prototype.ScoreMax = Number(args[1]);
Game_System.prototype.MissMax = Number(args[2]);
Game_System.prototype.VarNum = Number(args[3]);
SceneManager.push(Scene_Test);
}
break;
}
}
};
})();