モジュールを作っていく過程で問題が発生していったので書き換えた。
!!novel.setSE();
setSE: function( sound, ms ) {
::this.action.push( this.ACTION_SOUND_EFFECT );
::this.action.push( [ new Audio( sound ), ms ] );
::},
::サウンドを引数に入れることでそれを流すことができる。
::二個目の引数は鳴動中の操作無効時間(ms)となる。
!!novel.setText
::novel.setText("");
::("")内に文字を書き込むことによって文字を出力。
!!novel.setPageBreak
novel.setPageBreak();
::ページを新たに読み込む
!!novel.setChoice
novel.setChoice(1,
::"",
::"",
::"",
::"",
::"",
::core.selectChoice);
::最初の引数でidを設定し上から""内の文字を出力し、その文字を選択することによって上から1から4までのselect番号をあたえ、core.selectChoiceでその返答を出力する関数に遷移する。
!!core.selectChoice
core.selectChoice = function(id, select) {
::switch (id) {
::case 1:
::switch (select) {
::case 1:
::・・・・・・・・
::break;
::case 2:
::・・・・・・・・・
::break;
::case 3:
::・・・・・・・・・
::break;
::case 4:
::・・・・・・・・・
::break;
::default:
::break;
::}
break;
::}
渡されたid、selectに応じた条件分岐
::
!!core.currentScene.ontouchstart
core.currentScene.ontouchstart = function() {
::novel.next();
::}
::画面タッチで次へ行くように読み込んでいる。
!!!novel.enchant.jsの変更・追加プログラム
!!text5の追加
/**
::* 選択肢の設定.
::* @param {Number} id
::* @param {String} text1
::* @param {String} text2
::* @param {String} text3
::* @param {String} text4
::* @param {String} text5
::* @param {Function} callback 選択時のコールバック関数.
::*/
::setChoice: function( id, text1, text2, text3, text4, text5, callback ) {
::this.action.push( this.ACTION_CHOICE );
::this.action.push( [ 1, text1 ] );
::this.action.push( [ 2, text2 ] );
::this.action.push( [ 3, text3 ] );
::this.action.push( [ 4, text4 ] );
::this.action.push( [ 5, text5 ] );
::this.action.push( this.ACTION_SELECT );
::this.action.push( [ id, callback ] );
::}
::text5を追加することにより今までより多くの条件分岐を可能とした。
!!+540
for ( var i = 0 ; i < this.parentNode.lineMax ; i++ ) { ::// 何行目をタッチされたか.
::if ( this.parentNode.lines[ i ].y + 540 > evt.y ) {
::lineTouch=i;
::// タッチされた行数.
::break;
::}
::}
::文字を表示するときにy座標が540の位置からスタートするため条件分岐を選択するときの選択肢のy座標に540を加えなければならないためそれを加えた。
!!novel.setIMG();
::this.ACTION_IMG= "ACTION CODE : Img !!!";
::・・・・・・・・・・・・・
::setIMG: function( IMG ) {
::this.action.push( this.ACTION_IMG );
::this.action.push( [ IMG ] );
::},
::・・・・・・・・・・・・・
::if ( this.ACTION_IMG == action ) {
::this.actionNow = this.ACTION_IMG;
::action = this.action.shift(); ::// アクションの取出し
::Others.Background.create(action[0]);
:://入れ替え
::return;
::}
::novel.setIMG("A");
Aの中に画像を入れることで別ファイルから関数を呼び出し画像をセットする関数をnovel.enchant.jsで定義した。こうすることにより第13回で述べた問題を解決し文字を流している時に画像の遷移を可能とした。
!!novel.setIMG();のさらなる追加
::if ( this.ACTION_IMG == action ) {
::this.actionNow = this.ACTION_IMG;
::action = this.action.shift();// アクションの取出し
::SpriteIMG[k] = Others.Background.create(action[0]);
::let core = enchant.Core.instance;
::core.currentScene.removeChild(action[2]);
::core.currentScene.insertBefore(SpriteIMG[k], action[1]);
::k++;
::return;
::}
::novel.setIMG("A,bgspace,Sprite[k-1]");
::前に説明したものに加えて、bgspaceつまりノベルを表示するテキストボックスとAを入れ替えて、もともと貼ってあった背景画像Sprite[k-1]を削除するプログラムを作った。
!!novel.setIMG_C();
::if ( this.ACTION_IMG_C == action ) {
::this.actionNow = this.ACTION_IMG_C;
::action = this.action.shift();// アクションの取出し
::let core = enchant.Core.instance;
::CharaIMG[action[5]] = ::Others.Image.create(action[0],action[1],action[2],action[3],action[4]);
::core.currentScene.insertBefore(CharaIMG[action[5]], action[6]);
::return;
::}
::novel.setIMG_C(IMG,x座標,y座標,画像の横サイズk,画像の縦サイズ,任意番号,bgspace);
::引数の最初にキャラクタの画像を挿入し、2つ目、3つ目にそれを表示する位置を設定する。4つ目、5つ目には画像のサイズを挿入し、その画像に任意で番号をつける。その番号は次のREMOVEで使用する。最後にテキストボックスとキャラクタの画像を入れ替えるためbgspaceを入れ込む。
!!novel.setREMOVE();
::if ( this.ACTION_REMOVE == action ) {
::this.actionNow = this.ACTION_REMOVE;
::action = this.action.shift();// アクションの取出し
::let core = enchant.Core.instance;
::core.currentScene.removeChild(CharaIMG[action[0]]);
::return;
::}
::引数に前のIMG_Cで設定した任意番号を入れることでその画像を削除することができる。
!!novel.setFUNC(func);
::if ( this.ACTION_FUNC == action ) {
::this.actionNow = this.ACTION_FUNC;
::action = this.action.shift();// アクションの取出し
::(action[0])();
::return;
::}
::novel.setFUNC(関数);
::引数に関数を宣言することで引数の中身の関数を画面をタッチしたタイミングで実行を可能とする。
!!novel.setREMOVE();の変更
::core.currentScene.removeChild(CharaIMG[action[0]]);
::core.currentScene.removeChild(CharaIMG[action[1]]);
::core.currentScene.removeChild(CharaIMG[action[2]]);
::引数を追加し、一度に3枚までの画像を削除することを実現した。
!!!裏ポイント
::var saki_point = 0;
::var sayaka_point = 0;
::var barbie_point = 0;
条件分岐の答えに足して上の変数を変化させることによって裏ポイントを設定。ミニゲーム時にも値は変化する。最後のミニゲームにこのポイントは使用。
!!hikiwake
hikiwake = 1の場合、さきの告白が成功。
::hikiwake = 2の場合、さやかの告白が成功。
::この2つの場合は結婚式のシーンに遷移する。
::hikiwake = 0の場合、告白に失敗。
::失敗後のストーリーに遷移する。
::hikiwakeの値はミニゲームの結果で決まる。