$(document).ready(function(){ logger = new SwitchApps.Logger(SwitchApps.app.id, null); /*ログの設定*/ LOG_switch = logger.addHeader('スイッチ入力'); LOG_animal1 = logger.addHeader('左の動物が演奏'); LOG_animal2 = logger.addHeader('右の動物が演奏'); /*必要なオプションの状態はオブジェクトで宣言*/ RIGTH = {set:1}; LEFT = {set:2}; BACK_R = {set:1}; BACK_L = {set:1}; createSettingBox("動物(左)","left_frame",LEFT,12,"いぬ","ペンギン","さる"); createSettingBox("動物(右)","right_frame",RIGTH,12,"いぬ","ペンギン","さる"); createSettingBox("背景(左)","backl_frame",BACK_L,12,"木","草","石","灰色","黒","白"); createSettingBox("背景(右)","backr_frame",BACK_R,12,"木","草","石","灰色","黒","白"); }); /* * おまじない */ enchant(); var _DIR_ = SwitchApps.scriptDir(); var logger = null; /* * 定数 */ // パラメータ var SCREEN_W = 1000; // スクリーンの幅 var SCREEN_H = 450; // スクリーンの高さ // 画像 var BGM1 = _DIR_ + "/sounds/guitar02.mp3"; var BGM2 = _DIR_ + "/sounds/drum01.mp3"; var BGM3 = _DIR_ + "/sounds/cym03.mp3"; var ALL = _DIR_ + "/images/all.png"; var BACK = _DIR_ + "/images/back.png"; // 音 // アセットリスト var ASSETS = [BGM1,BGM2,BGM3,ALL,BACK]; /* * グローバル変数 */ var game = null; //フレーム管理 var flag =0; var flag2 = 0; //フラグチェック var fc = 1; var fc2= 1; //待ち時間 var time = 0; var time2 = 0; // var fl = 0; var fl2 = 0; //キーバインド設定 var keyset = function(key){ game.keybind(49, 'a'); // 1 game.keybind(32, 'a'); // Space game.keybind(123, 'a'); // F12 game.keybind(51, 'b'); // 3 game.keybind(13, 'b'); // Enter //aボタンを押した時のイベント処理 game.currentScene.onabuttondown = function() { /*if(fc === 0 | flag == 1){ this.onabuttondown == null; } else*/// if(fc == 1 && flag == 0){ LOG_animal1(); fl2 = 1; LOG_switch(); //} }; game.currentScene.onbbuttondown = function() { /*if(fc2 === 0 | flag2 == 1){ this.onbbuttondown == null; } else{*/ LOG_animal2(); fl = 1; LOG_switch(); //} }; }; /* * 汎用処理 */ //ランダム値生成 var randfloat = function(min, max) { return Math.random()*(max-min)+min; }; /* * メイン処理 */ window.onload = function() { // ゲームオブジェクトの生成 game = new Game(SCREEN_W, SCREEN_H); // 画像の読み込み game.preload(ASSETS); // ゲーム開始時の処理 game.onload = function() { //キーバインドの設定 keyset(49); //1キー keyset(51); //3キー keyset(32); //spaceキー keyset(10); //Enter1 keyset(13); //Enter windows keyset(123); //F12 var scene = game.rootScene; scene.backgroundColor = "black"; var BACK_R = new back_right; var BACK_L = new back_left; var INU = new inu; var PNGN = new pngn; scene.addChild(BACK_R); scene.addChild(BACK_L); scene.addChild(INU); scene.addChild(PNGN); }; game.start(); }; //背景 var back_right = Class.create(Sprite, { // 初期化処理 initialize: function() { Sprite.call(this,500,450); this.image = game.assets[BACK]; this.moveTo(500,0); }, // 更新処理 onenterframe: function() { if(BACK_R.set == 1){ this.frame = 0; } else if(BACK_R.set == 2){ this.frame = 1; } else if(BACK_R.set == 3){ this.frame = 2; } else if(BACK_R.set == 4){ this.frame = 3; } else if(BACK_R.set == 5){ this.frame = 4; } else if(BACK_R.set == 6){ this.frame = 5; } }, // タッチ開始時処理 ontouchstart: function() { }, }); var back_left = Class.create(Sprite, { // 初期化処理 initialize: function() { Sprite.call(this,500,450); this.image = game.assets[BACK]; this.moveTo(0,0); }, // 更新処理 onenterframe: function() { if(BACK_L.set == 1){ this.frame = 0; } else if(BACK_L.set == 2){ this.frame = 1; } else if(BACK_L.set == 3){ this.frame = 2; } else if(BACK_L.set == 4){ this.frame = 3; } else if(BACK_L.set == 5){ this.frame = 4; } else if(BACK_L.set == 6){ this.frame = 5; } }, // タッチ開始時処理 ontouchstart: function() { }, }); /* * 右側 */ var inu = Class.create(Sprite, { // 初期化処理 initialize: function() { Sprite.call(this,500,450); this.image = game.assets[ALL]; this.moveTo(500,0); this.scale(1); this.frame = right_frame; this.update = this.move; this.waitcount = 0; }, // 移動処理 move: function() { if(fl == 1){ flag =1; } if(this.frame == right_frame && flag == 1){ this.frame +=1; if(RIGTH.set == 1){ // game.assets[BGM1].stop(); game.assets[BGM1].clone().play(); } else if(RIGTH.set == 2){ game.assets[BGM2].clone().play(); } else if(RIGTH.set == 3){ game.assets[BGM3].clone().play(); } } else if(flag == 0){ this.frame = right_frame; if(RIGTH.set == 1){ game.assets[BGM1].play(); game.assets[BGM1].stop(); } else if(RIGTH.set == 2){ game.assets[BGM2].play(); game.assets[BGM2].stop(); } else if(RIGTH.set == 3){ game.assets[BGM3].play(); game.assets[BGM3].stop(); } } }, // 待ち処理 wait: function() { if(flag == 1) this.waitcount++; if(this.waitcount == 10) this.frame++; if(this.waitcount == 20) this.frame--; if(this.waitcount == 40) this.frame++; if(this.waitcount == 50) this.frame--; if(this.waitcount == 60){ this.waitcount=0; fc =0; flag= 0; } if(fc === 0){ time++; if(time >= 0){ fc = 1; time= 0; fl = 0; } } }, // 更新処理 onenterframe: function() { this.update(); this.wait(); if(RIGTH.set == 1){ right_frame = 0; } else if(RIGTH.set == 2){ right_frame = 3; } else if(RIGTH.set == 3){ right_frame = 6; } }, // タッチ開始時処理 ontouchstart: function() {/* if(fc === 0 | flag == 1){ this.ontouchstart == null; } else{*/ LOG_animal2(); fl = 1; LOG_switch(); //} }, }); //左側 var pngn = Class.create(Sprite, { // 初期化処理 initialize: function() { Sprite.call(this,500,450); this.image = game.assets[ALL]; this.moveTo(0,0); this.scale(1); this.frame =left_frame; this.update = this.move; this.waitcount = 0; }, // 移動処理 move: function() { if(fl2 == 1){ flag2 =1; } if(this.frame==left_frame && flag2 == 1){ this.frame +=1; if(LEFT.set == 1){ game.assets[BGM1].clone().play(); } else if(LEFT.set == 2){ game.assets[BGM2].clone().play(); } else if(LEFT.set == 3){ game.assets[BGM3].clone().play(); } } else if(flag2 == 0){ this.frame = left_frame; if(LEFT.set == 1){ game.assets[BGM1].play(); game.assets[BGM1].stop(); } else if(LEFT.set == 2){ game.assets[BGM2].play(); game.assets[BGM2].stop(); } else if(LEFT.set == 3){ game.assets[BGM3].play(); game.assets[BGM3].stop(); } } }, // 待ち処理 wait: function() { if(flag2 == 1) this.waitcount++; if(this.waitcount == 10) this.frame++; if(this.waitcount == 20) this.frame--; if(this.waitcount == 40) this.frame++; if(this.waitcount == 50) this.frame--; if(this.waitcount == 60){ this.waitcount=0; fc2 =0; flag2= 0; } if(fc2 === 0){ time2++; if(time2 >= 0){ fc2 = 1; time2= 0; fl2 = 0; } } }, // 更新処理 onenterframe: function() { this.update(); this.wait(); if(LEFT.set == 1){ left_frame = 0; } else if(LEFT.set == 2){ left_frame = 3; } else if(LEFT.set == 3){ left_frame = 6; } }, // タッチ開始時処理 ontouchstart: function() {/* if(fc2 === 0 | flag2 == 1){ this.ontouchstart == null; } else{*/ LOG_animal1(); fl2 = 1; LOG_switch(); // } }, });