/* * おまじない */ enchant(); window.focus(); var _DIR_ = SwitchApps.scriptDir(); /* * 定数 */ // パラメータ var SCREEN_W = window.screen.width; //スクリーンの幅 var SCREEN_H = window.screen.height; //スクリーンの高さ if(window.navigator.platform == "iPad") { var SCREEN_W = $(window).width(); //スクリーンの幅 var SCREEN_H = $(window).height()-44; //スクリーンの高さ } var RECT_W = SCREEN_W/15; //四角形の幅 var RECT_H = SCREEN_H/15; //四角形の高さ // SE var CHANGE_SE1 = _DIR_ + "/sounds/change_se.mp3";//ぶにっ!! var CHANGE_SE2 = _DIR_ + "/sounds/mokyu.mp3";//もきゅっ!! //以下ドレミサウンド var PIANO1 = _DIR_ + "/sounds/piano1.mp3"; var PIANO2 = _DIR_ + "/sounds/piano2.mp3"; var PIANO3 = _DIR_ + "/sounds/piano3.mp3"; var PIANO4 = _DIR_ + "/sounds/piano4.mp3"; var PIANO5 = _DIR_ + "/sounds/piano5.mp3"; var PIANO6 = _DIR_ + "/sounds/piano6.mp3"; var PIANO7 = _DIR_ + "/sounds/piano7.mp3"; var PIANO8 = _DIR_ + "/sounds/piano8.mp3"; //var BGM1 = "game/app001/sounds/bgm.mp3"; // アセットリスト var ASSETS = [ CHANGE_SE1,//,BGM1 CHANGE_SE2, PIANO1, PIANO2, PIANO3, PIANO4, PIANO5, PIANO6, PIANO7, PIANO8, ]; var TIME=0; /* * グローバル変数 */ var game = null; var logger = null; /* * オプション項目の設定 */ $(document).ready(function(){ logger = new SwitchApps.Logger(SwitchApps.app.id, null); /*ログの設定*/ LOG_switch = logger.addHeader('スイッチ入力'); LOG_color = logger.addHeader('色変化'); /*グローバル変数の宣言*/ ANIM_SPEED = {set:2},//色の変わるスピード SOUND_TYPE = {set:1}, createSettingBox("アニメーションの速さ","anim_speed",ANIM_SPEED,40,"ゆっくり","標準","はやい"); createSettingBox("音","sound_type",SOUND_TYPE,30,"ぴゅいっ","もきゅっ","どれみ"); }) /* * 汎用処理 */ //ランダム値生成 var randfloat = function(min, max) { return Math.random()*(max-min)+min; }; //キーバインド設定 var keyset = function(key){ game.keybind(key, 'a'); //aボタン(「z」キー)を押した時のイベント処理 game.currentScene.onabuttondown = function() { var ev = new Event('touchstart'); // 発火! game.currentScene.dispatchEvent(ev); }; }; // 四角形クラス function rect(x_pos, y_pos, x_size, y_size, r, g, b){ //コンストラクタ(もどき) this.x_pos = x_pos; // x座標 this.y_pos = y_pos; // y座標 this.x_size = x_size; // 幅 this.y_size = y_size; // 高さ this.r = r; // red値 this.g = g; // green値 this.b = b; // bule値 this.flg = 1; // 1:更新あり 0:更新なし }; /* * メイン処理 */ window.onload = function() { //ゲームオブジェクトの生成 game = new Core(SCREEN_W, SCREEN_H); // SEの読み込み game.preload(ASSETS); //ゲーム開始時の処理 game.onload = function() { var scene = game.rootScene; scene.backgroundColor = "black"; var canvas = new Sprite(SCREEN_W, SCREEN_H); canvas.surface = new Surface(SCREEN_W, SCREEN_H); canvas.image = canvas.surface; scene.addChild(canvas); canvas.context = canvas.surface.context; //効果音の保存 canvas.se1 = game.assets[CHANGE_SE1]; canvas.se2 = game.assets[CHANGE_SE2]; canvas.se3 = new Array(8); canvas.se3[0] = game.assets[PIANO1]; canvas.se3[1] = game.assets[PIANO2]; canvas.se3[2] = game.assets[PIANO3]; canvas.se3[3] = game.assets[PIANO4]; canvas.se3[4] = game.assets[PIANO5]; canvas.se3[5] = game.assets[PIANO6]; canvas.se3[6] = game.assets[PIANO7]; canvas.se3[7] = game.assets[PIANO8]; canvas.se_cnt = 0; canvas.rect = new Array(); canvas.rectnum = 0; canvas.comp = 0; /*ボタンを押したときの音の反応*/ $("[name='sound_type']").click(function(){ var num = $("[name='sound_type']").index(this)+1; switch(num){ case 1:canvas.se1.clone().play(); break; case 2:canvas.se2.clone().play(); break; case 3:canvas.se3[0].clone().play(); break; default:break; } }); canvas.ontouchstart = function() { LOG_switch(); //アニメーションのスピードを変化 switch(ANIM_SPEED.set){ case 1: RECT_W = SCREEN_W/60; //四角形の幅 RECT_H = SCREEN_H/60; break; case 2: RECT_W = SCREEN_W/30; RECT_H = SCREEN_H/30; break; case 3: RECT_W = SCREEN_W/15; RECT_H = SCREEN_H/15; break; default : break; } //ある程度配列が大きくなったらいらなくなった更新がないものを解放する if(this.rectnum==20){ var save = new Array(); for(var i=0; i i; i++){ if(this.rect[i].flg == 1) { this.rect[i].x_size += RECT_W//サイズの更新 this.rect[i].y_size += RECT_H; this.rect[i].x_pos = (SCREEN_W-this.rect[i].x_size)/2; this.rect[i].y_pos = (SCREEN_H-this.rect[i].y_size)/2; // console.log("update") if(SCREEN_W <= this.rect[i].x_size || SCREEN_H <= this.rect[i].y_size){//定めたサイズまで大きくなったら this.comp=i;//最後に更新必要なくなった要素の保存 //console.log("in2") this.rect[i].flg = 0;//更新をなくす game.rootScene.backgroundColor = 'rgba('+this.rect[i].r+','+this.rect[i].g+','+this.rect[i].b+', 1)'; } } } } canvas.onenterframe = function() { // 描画 this.context.clearRect(0, 0, SCREEN_W, SCREEN_H); for(var i = 0, n = this.rect.length; n > i; i++){ if(this.rect[i].flg == 1) { canvas.context.beginPath(); canvas.context.fillStyle = 'rgba('+this.rect[i].r+','+this.rect[i].g+','+this.rect[i].b+', 1)'; canvas.context.fillRect(this.rect[i].x_pos, this.rect[i].y_pos, this.rect[i].x_size, this.rect[i].y_size); } } canvas.update(); } //キーバインドの設定 game.keybind(49, 'a'); game.keybind(51, 'a'); game.keybind(32, 'a'); game.keybind(10, 'a'); game.keybind(13, 'a'); game.keybind(123, 'a'); var switchInput = function() { var ev = new Event('touchstart'); // 発火!s canvas.dispatchEvent(ev); //scene.removeEventListener('abuttondown', switchInput); } scene.addEventListener('abuttondown', switchInput); scene.onabuttonup = function() { //scene.addEventListener('abuttondown', switchInput); } }; game.start(); };