//おまじない enchant(); var _DIR_ = SwitchApps.scriptDir(); var logger = null; //スクリーン幅 var SCREEN_W = 1800; //スクリーン高 var SCREEN_H = 1000; var game = null; var degree = 90; var radiusX = 600; var radiusY = 120; var stop = 0; var hayai = 10; var CYMBALwaitMax = 7; var SUZUwaitMax = 4; var HUEwaitMax = 6; var TAIKOwaitMax = 4; var CYMBALwaitCount = 0; var SUZUwaitCount = 0; var HUEwaitCount = 0; var TAIKOwaitCount = 0; var CYMBALlimit = 0; var SUZUlimit = 0; var HUElimit = 0; var TAIKOlimit = 0; // ログ用変数 var cymbalCount = 0; var suzuCount = 0; var hueCount = 0; var taikoCount = 0; // オプション変数の設定 $(document).ready(function(){ logger = new SwitchApps.Logger(SwitchApps.app.id, null); LOG_switch = logger.addHeader('スイッチ入力'); LOG_start = logger.addHeader('回転開始'); LOG_cymbal = logger.addHeader('シンバル演奏%s回目'); LOG_suzu = logger.addHeader('鈴演奏%s回目'); LOG_hue = logger.addHeader('笛演奏%s回目'); LOG_taiko = logger.addHeader('太鼓演奏%s回目'); LOG_cymplay = logger.addHeader('シンバル演奏'); LOG_suzuplay = logger.addHeader('鈴演奏'); LOG_hueplay = logger.addHeader('笛演奏'); LOG_taiplay = logger.addHeader('太鼓演奏'); LOG_stop = logger.addHeader('止める'); COLOR = {set:1}; SPEED = {set:2}; STOP = {set:1}; createSettingBox("いろ", "color", COLOR , 10 , "しろ" , "くろ" , "きん"); createSettingBox("はやさ", "speed", SPEED , 11 , "おそい" , "ふつう" , "はやい"); createSettingBox("とめかた", "stop", STOP , 12 , "じぶんで", "じどう"); }); //回す方の画像 var createCYMBALScene = function() { var CYMBALScene = new Scene(); CYMBALScene.onabuttondown = function() { var ev = new Event('touchstart'); game.currentScene.dispatchEvent(ev); }; CYMBALScene.onenterframe = function() { //背景色 if(COLOR.set == 1) { CYMBALScene.backgroundColor = "#ffffff"; } else if(COLOR.set == 2) { CYMBALScene.backgroundColor = "#000000"; } else if(COLOR.set == 3) { CYMBALScene.backgroundColor = "#ffd700"; } }; var cymb = new Sprite(250, 200); cymb.frame=1; cymb.image = game.assets[_DIR_ + '/images/cymbal.png']; cymb.originX = 0; cymb.originY = 0; cymb.scaleX = 2.0; cymb.scaleY = 2.0; cymb.x = SCREEN_W / 2; cymb.y = SCREEN_H / 2; CYMBALScene.addChild(cymb); CYMBALScene.addEventListener("enterframe", function() { if(STOP.set == 2) { if(CYMBALlimit >= 12) { CYMBALlimit = 0; game.popScene(CYMBALScene); LOG_stop(); } } if(CYMBALwaitCount >= CYMBALwaitMax) { CYMBALwaitCount = 0; cymb.frame++; CYMBALlimit++; game.assets[_DIR_ + "/sounds/cymbal.mp3"].play(true); } else { CYMBALwaitCount++; } }); if(STOP.set == 1) { CYMBALScene.addEventListener("touchstart", function(e) { LOG_switch(); degree = 90; stop = 0; if(!isNaN(game.assets[_DIR_ + "/sounds/cymbal.mp3"].currentTime)) { game.assets[_DIR_ + "/sounds/cymbal.mp3"].stop(); } game.popScene(CYMBALScene); LOG_stop(); }); } return CYMBALScene; }; var createSUZUScene = function() { var SUZUScene = new Scene(); SUZUScene.onabuttondown = function() { var ev = new Event('touchstart'); game.currentScene.dispatchEvent(ev); }; SUZUScene.onenterframe = function() { //背景色 if(COLOR.set == 1) { SUZUScene.backgroundColor = "#ffffff"; } else if(COLOR.set == 2) { SUZUScene.backgroundColor = "#000000"; } else if(COLOR.set == 3) { SUZUScene.backgroundColor = "#ffd700"; } }; var bell = new Sprite(350, 250); bell.image = game.assets[_DIR_ + '/images/suzu.png']; bell.originX = 0; bell.originY = 0; bell.scaleX = 1.9; bell.scaleY = 1.9; bell.x = SCREEN_W / 2; bell.y = SCREEN_H / 2; SUZUScene.addChild(bell); SUZUScene.addEventListener("enterframe", function() { if(STOP.set == 2) { if(SUZUlimit >= 12) { SUZUlimit = 0; game.popScene(SUZUScene); LOG_stop(); } } if(SUZUwaitCount >= SUZUwaitMax) { SUZUwaitCount = 0; bell.frame++; SUZUlimit++; game.assets[_DIR_ + "/sounds/suzu.mp3"].play(true); } else { SUZUwaitCount++; } }); if(STOP.set == 1) { SUZUScene.addEventListener("touchstart", function(e) { LOG_switch(); degree = 90; stop = 0; if(!isNaN(game.assets[_DIR_ + "/sounds/suzu.mp3"].currentTime)) { game.assets[_DIR_ + "/sounds/suzu.mp3"].stop(); } game.popScene(SUZUScene); LOG_stop(); }); } return SUZUScene; }; var createHUEScene = function() { var HUEScene = new Scene(); HUEScene.onabuttondown = function() { var ev = new Event('touchstart'); game.currentScene.dispatchEvent(ev); }; HUEScene.onenterframe = function() { //背景色 if(COLOR.set == 1) { HUEScene.backgroundColor = "#ffffff"; } else if(COLOR.set == 2) { HUEScene.backgroundColor = "#000000"; } else if(COLOR.set == 3) { HUEScene.backgroundColor = "#ffd700"; } }; var pipe = new Sprite(300, 250); pipe.image = game.assets[_DIR_ + '/images/hue.png']; pipe.originX = 0; pipe.originY = 0; pipe.scaleX = 1.8; pipe.scaleY = 1.8; pipe.x = SCREEN_W / 2; pipe.y = SCREEN_H / 2; HUEScene.addChild(pipe); HUEScene.addEventListener("enterframe", function() { if(STOP.set == 2) { if(HUElimit >= 12) { HUElimit = 0; game.popScene(HUEScene); LOG_stop(); } } if(HUEwaitCount >= HUEwaitMax) { HUEwaitCount = 0; pipe.frame++; HUElimit++; game.assets[_DIR_ + "/sounds/hue.wav"].play(true); } else { HUEwaitCount++; } }); if(STOP.set == 1) { HUEScene.addEventListener("touchstart", function(e) { LOG_switch(); degree = 90; stop = 0; if(!isNaN(game.assets[_DIR_ + "/sounds/hue.wav"].currentTime)) { game.assets[_DIR_ + "/sounds/hue.wav"].stop(); } game.popScene(HUEScene); LOG_stop(); }); } return HUEScene; }; var createTAIKOScene = function() { var TAIKOScene = new Scene(); TAIKOScene.onabuttondown = function() { var ev = new Event('touchstart'); game.currentScene.dispatchEvent(ev); }; TAIKOScene.onenterframe = function() { //背景色 if(COLOR.set == 1) { TAIKOScene.backgroundColor = "#ffffff"; } else if(COLOR.set == 2) { TAIKOScene.backgroundColor = "#000000"; } else if(COLOR.set == 3) { TAIKOScene.backgroundColor = "#ffd700"; } }; var drum = new Sprite(400, 350); drum.image = game.assets[_DIR_ + '/images/taiko.png']; drum.frame = 1; drum.originX = 0; drum.originY = 0; drum.scaleX = 1.0; drum.scaleY = 1.0; drum.x = SCREEN_W / 2; drum.y = SCREEN_H / 2; TAIKOScene.addChild(drum); TAIKOScene.addEventListener("enterframe", function() { if(STOP.set == 2) { if(TAIKOlimit >= 12) { TAIKOlimit = 0; game.popScene(TAIKOScene); LOG_stop(); } } if(TAIKOwaitCount >= TAIKOwaitMax) { TAIKOwaitCount = 0; drum.frame++; TAIKOlimit++; if(drum.frame % 4 == 2) game.assets[_DIR_ + "/sounds/taiko.mp3"].play(true); } else { TAIKOwaitCount++; } }); if(STOP.set == 1) { TAIKOScene.addEventListener("touchstart", function(e) { LOG_switch(); degree = 90; stop = 0; if(!isNaN(game.assets[_DIR_ + "/sounds/taiko.mp3"].currentTime)) { game.assets[_DIR_ + "/sounds/taiko.mp3"].stop(); } game.popScene(TAIKOScene); LOG_stop(); }); } return TAIKOScene; }; window.onload = function() { //ゲームオブジェクト game = new Core(SCREEN_W, SCREEN_H); //キーバインドの設定 game.keybind(49, 'a'); game.keybind(51, 'a'); game.keybind(32, 'a'); game.keybind(10, 'a'); game.keybind(13, 'a'); game.keybind(123, 'a'); //fps game.fps = 8; //画像読み込み game.preload ( _DIR_ + "/sounds/taiko.mp3", _DIR_ + "/sounds/suzu.mp3", _DIR_ + "/sounds/cymbal.mp3", _DIR_ + "/sounds/hue.wav", _DIR_ + "/images/pcymbal.png", _DIR_ + "/images/psuzu.png", _DIR_ + "/images/phue.png", _DIR_ + "/images/ptaiko.png", _DIR_ + "/images/cymbal.png", _DIR_ + "/images/suzu.png", _DIR_ + "/images/hue.png", _DIR_ + "/images/taiko.png", _DIR_ + "/images/startImg.png", _DIR_ + "/images/excymbal.png", _DIR_ + "/images/exsuzu.png", _DIR_ + "/images/exhue.png", _DIR_ + "/images/extaiko.png" ); //ロード時処理 game.onload = function() { var createstart = function() { var start = new Scene(); start.backgroundColor = '#ffffff'; var startImg = new Sprite(650, 350); startImg.image = game.assets[_DIR_ + '/images/startImg.png']; startImg.x = 100; startImg.y = 40; startImg.originX = 0; startImg.originY = 0; startImg.scaleX = 2; startImg.scaleY = 2; start.addChild(startImg); var ex1 = new Sprite(350, 250); ex1.image = game.assets[_DIR_ + '/images/excymbal.png']; ex1.x = 0; ex1.y = 700; start.addChild(ex1); var ex2 = new Sprite(350, 250); ex2.image = game.assets[_DIR_ + '/images/exsuzu.png']; ex2.x = 400; ex2.y = 700; start.addChild(ex2); var ex3 = new Sprite(350, 250); ex3.image = game.assets[_DIR_ + '/images/exhue.png']; ex3.x = 800; ex3.y = 700; start.addChild(ex3); var ex4 = new Sprite(350, 250); ex4.image = game.assets[_DIR_ + '/images/extaiko.png']; ex4.x = 1200; ex4.y = 700; start.addChild(ex4); ex1.addEventListener("touchstart", function(e) { LOG_switch(); cymbalCount++; LOG_cymbal(cymbalCount); LOG_cymplay(); game.replaceScene(createCYMBALScene2()); }); start.onabuttondown = function() { var ev = new Event('touchstart'); startImg.dispatchEvent(ev); }; var createCYMBALScene2 = function() { var CYMBALScene = new Scene(); CYMBALScene.onabuttondown = function() { var ev = new Event('touchstart'); game.currentScene.dispatchEvent(ev); }; CYMBALScene.onenterframe = function() { //背景色 if(COLOR.set == 1) { CYMBALScene.backgroundColor = "#ffffff"; } else if(COLOR.set == 2) { CYMBALScene.backgroundColor = "#000000"; } else if(COLOR.set == 3) { CYMBALScene.backgroundColor = "#ffd700"; } }; var cymb = new Sprite(250, 200); cymb.image = game.assets[_DIR_ + '/images/cymbal.png']; cymb.frame = 1; cymb.originX = 0; cymb.originY = 0; cymb.scaleX = 1.8; cymb.scaleY = 1.8; cymb.x = SCREEN_W / 2; cymb.y = SCREEN_H / 2; CYMBALScene.addChild(cymb); CYMBALScene.addEventListener("enterframe", function() { if(CYMBALwaitCount >= CYMBALwaitMax) { CYMBALwaitCount = 0; cymb.frame++; game.assets[_DIR_ + "/sounds/cymbal.mp3"].play(true); } else { CYMBALwaitCount++; } }); CYMBALScene.addEventListener("touchstart", function() { LOG_switch(); game.replaceScene(createstart()); LOG_stop(); }); return CYMBALScene; } ex2.addEventListener("touchstart", function(e) { LOG_switch(); suzuCount++; LOG_suzu(suzuCount); LOG_suzuplay(); game.replaceScene(createSUZUScene2()); }); var createSUZUScene2 = function() { var SUZUScene = new Scene(); SUZUScene.onabuttondown = function() { var ev = new Event('touchstart'); game.currentScene.dispatchEvent(ev); }; SUZUScene.onenterframe = function() { //背景色 if(COLOR.set == 1) { SUZUScene.backgroundColor = "#ffffff"; } else if(COLOR.set == 2) { SUZUScene.backgroundColor = "#000000"; } else if(COLOR.set == 3) { SUZUScene.backgroundColor = "#ffd700"; } }; var bell = new Sprite(350, 250); bell.image = game.assets[_DIR_ + '/images/suzu.png']; bell.originX = 0; bell.originY = 0; bell.scaleX = 1.8; bell.scaleY = 1.8; bell.x = SCREEN_W / 2; bell.y = SCREEN_H / 2; SUZUScene.addChild(bell); SUZUScene.addEventListener("enterframe", function() { if(SUZUwaitCount >= SUZUwaitMax) { SUZUwaitCount = 0; bell.frame++; game.assets[_DIR_ + "/sounds/suzu.mp3"].play(true); } else { SUZUwaitCount++; } }); SUZUScene.addEventListener("touchstart", function() { LOG_switch(); game.replaceScene(createstart()); LOG_stop(); }); return SUZUScene; } ex3.addEventListener("touchstart", function(e) { LOG_switch(); hueCount++; LOG_hue(hueCount); LOG_hueplay(); game.replaceScene(createHUEScene2()); }); var createHUEScene2 = function() { var HUEScene = new Scene(); HUEScene.onabuttondown = function() { var ev = new Event('touchstart'); game.currentScene.dispatchEvent(ev); }; HUEScene.onenterframe = function() { //背景色 if(COLOR.set == 1) { HUEScene.backgroundColor = "#ffffff"; } else if(COLOR.set == 2) { HUEScene.backgroundColor = "#000000"; } else if(COLOR.set == 3) { HUEScene.backgroundColor = "#ffd700"; } }; var pipe = new Sprite(300, 250); pipe.image = game.assets[_DIR_ + '/images/hue.png']; pipe.originX = 0; pipe.originY = 0; pipe.scaleX = 1.8; pipe.scaleY = 1.8; pipe.x = SCREEN_W / 2; pipe.y = SCREEN_H / 2; HUEScene.addChild(pipe); HUEScene.addEventListener("enterframe", function() { if(HUEwaitCount >= HUEwaitMax) { HUEwaitCount = 0; pipe.frame++; game.assets[_DIR_ + "/sounds/hue.wav"].play(true); } else { HUEwaitCount++; } }); HUEScene.addEventListener("touchstart", function(e) { LOG_switch(); game.replaceScene(createstart()); LOG_stop(); }); return HUEScene; }; ex4.addEventListener("touchstart", function(e) { LOG_switch(); taikoCount++; LOG_taiko(taikoCount); LOG_taiplay(); game.replaceScene(createTAIKOScene2()); }); var createTAIKOScene2 = function() { var TAIKOScene = new Scene(); TAIKOScene.onabuttondown = function() { var ev = new Event('touchstart'); game.currentScene.dispatchEvent(ev); }; TAIKOScene.onenterframe = function() { //背景色 if(COLOR.set == 1) { TAIKOScene.backgroundColor = "#ffffff"; } else if(COLOR.set == 2) { TAIKOScene.backgroundColor = "#000000"; } else if(COLOR.set == 3) { TAIKOScene.backgroundColor = "#ffd700"; } }; var drum = new Sprite(400, 350); drum.image = game.assets[_DIR_ + '/images/taiko.png']; drum.frame = 1; drum.originX = 0; drum.originY = 0; drum.scaleX = 1.3; drum.scaleY = 1.3; drum.x = SCREEN_W / 2; drum.y = SCREEN_H / 2; TAIKOScene.addChild(drum); TAIKOScene.addEventListener("enterframe", function() { //console.log(drum.frame); if(TAIKOwaitCount >= TAIKOwaitMax) { TAIKOwaitCount = 1; drum.frame++; if(drum.frame % 4 == 2) game.assets[_DIR_ + "/sounds/taiko.mp3"].play(true); } else { TAIKOwaitCount++; } }); TAIKOScene.addEventListener("touchstart", function(e) { LOG_switch(); degree = 90; stop = 0; game.replaceScene(createstart()); LOG_stop(); }); return TAIKOScene; }; startImg.addEventListener("touchstart", function(e) { LOG_switch(); degree = 90; stop = 0; game.popScene(start); LOG_start(); }); return start; }; game.pushScene(createstart()); game.rootScene.onabuttondown = function() { var ev = new Event('touchstart'); game.rootScene.dispatchEvent(ev); }; game.rootScene.addEventListener("touchstart", function(e) { LOG_switch(); if(degree > 0 && degree <= 90) { cymbalCount++; LOG_cymbal(cymbalCount); LOG_cymplay(); game.replaceScene(createCYMBALScene()); } else if(degree > 90 && degree <= 180) { taikoCount++; LOG_taiko(taikoCount); LOG_taiplay(); game.replaceScene(createTAIKOScene()); } else if(degree > 180 && degree <= 270) { hueCount++; LOG_hue(hueCount); LOG_hueplay(); game.replaceScene(createHUEScene()); } else if(degree > 270 && degree <= 360 || degree == 0) { suzuCount++; LOG_suzu(suzuCount); LOG_suzuplay(); game.replaceScene(createSUZUScene()); } }); //回す方のオブジェクト //シンバルオブジェクト var pcymbal = new Sprite(399, 350); //画像指定 pcymbal.image = game.assets[_DIR_ + '/images/pcymbal.png']; //拡大縮小地点指定 pcymbal.originX = 0; pcymbal.originY = 0; pcymbal.onenterframe = function() { var rad = degree * Math.PI / 180; pcymbal.x = radiusX * Math.cos(rad)+(SCREEN_W / 3); pcymbal.y = radiusY * Math.sin(rad)+(SCREEN_H / 2); //拡大縮小倍率指定 pcymbal.scaleX = (Math.abs(pcymbal.y)/500); pcymbal.scaleY = (Math.abs(pcymbal.y)/500); pcymbal.opacity = (pcymbal.y -300) / 300; } game.rootScene.addChild(pcymbal); //鈴オブジェクト var psuzu = new Sprite(374, 272); //画像指定 psuzu.image = game.assets[_DIR_ + '/images/psuzu.png']; //棒座標 psuzu.x = 250; psuzu.y = 100; //拡大縮小地点指定 psuzu.originX = 0; psuzu.originY = 0; psuzu.onenterframe = function() { var rad = (90 + degree) * Math.PI / 180; psuzu.x = (radiusX * Math.cos(rad)+(SCREEN_W / 3))-100; psuzu.y = radiusY * Math.sin(rad)+(SCREEN_H / 2) + 50; //拡大縮小倍率指定 psuzu.scaleX = 0.9 * (Math.abs(psuzu.y)/500); psuzu.scaleY = 0.9 * (Math.abs(psuzu.y)/500); psuzu.opacity = (psuzu.y -300) / 300; } game.rootScene.addChild(psuzu); //笛オブジェクト var phue = new Sprite(500, 500); //画像指定 phue.image = game.assets[_DIR_ + '/images/phue.png']; //拡大縮小地点指定 phue.originX = 0; phue.originY = 0; phue.onenterframe = function() { var rad = (180 + degree) * Math.PI / 180; phue.x = radiusX * Math.cos(rad)+(SCREEN_W / 3)-50; phue.y = radiusY * Math.sin(rad)+(SCREEN_H / 2); //拡大縮小倍率指定 phue.scaleX = 0.65 * (Math.abs(phue.y)/500); phue.scaleY = 0.65 * (Math.abs(phue.y)/500); phue.opacity = (phue.y -300) / 300; } game.rootScene.addChild(phue); //太鼓オブジェクト var ptaiko = new Sprite(399, 350); //画像指定 ptaiko.image = game.assets[_DIR_ + '/images/ptaiko.png']; //拡大縮小地点指定 ptaiko.originX = 0; ptaiko.originY = 0; //拡大縮小倍率指定 ptaiko.scaleX = 0.83; ptaiko.scaleY = 0.83; ptaiko.onenterframe = function() { var rad = (270 + degree) * Math.PI / 180; ptaiko.x = radiusX * Math.cos(rad)+(SCREEN_W / 3); ptaiko.y = (radiusY * Math.sin(rad)+(SCREEN_H / 2))+50; //拡大縮小倍率指定 ptaiko.scaleX = 0.8 * (Math.abs(ptaiko.y)/500); ptaiko.scaleY = 0.8 * (Math.abs(ptaiko.y)/500); ptaiko.opacity = (ptaiko.y -300) / 300; } game.rootScene.addChild(ptaiko); //回転 game.onenterframe = function() { //背景色 if(COLOR.set == 1) { game.rootScene.backgroundColor = "#ffffff"; } else if(COLOR.set == 2) { game.rootScene.backgroundColor = "#000000"; } else if(COLOR.set == 3) { game.rootScene.backgroundColor = "#ffd700"; } $('input[name="speed"]:radio').change(function(){ if(SPEED.set == 1) { hayai = 6; } else if(SPEED.set == 2) { hayai = 10; } else if(SPEED.set == 3) { hayai = 15; } degree -= degree % hayai; }); if(degree % 90 == 0) { stop ++; if(stop >= 4) { degree -= hayai; stop = 0; } } else degree -= hayai; //角度リフレッシュ if(degree < 0) { degree += 360; } } } game.start(); };