$(document).ready(function(){ logger = new SwitchApps.Logger(SwitchApps.app.id, null); /*ログの設定*/ LOG_switch = logger.addHeader('スイッチ入力'); LOG_bearkick = logger.addHeader('クマがキック'); LOG_bearstop = logger.addHeader('クマが止める'); LOG_mykick = logger.addHeader('自分がキック'); LOG_mystop = logger.addHeader('自分が止める'); /*必要なオプションの状態はオブジェクトで宣言*/ HIT_COUNT = {set:1}; BACK = {set:1}; BALL_SPEED ={set:1}; BALL_MOVE ={set:1}; createSettingBox("背景","back_ground",BACK,12,"草","くろ","しろ"); createSettingBox("ボールの軌道","ball_move",BALL_MOVE,13,"曲線","直線","ランダム"); createSettingBox("熊たちの動く速さ","ball_speed",BALL_SPEED,15,"ふつう","おそい"); }); var _DIR_ = SwitchApps.scriptDir(); var logger = null; enchant(); var SCREEN_W = 900; var SCREEN_H = 1200; var KUMA_HAD =_DIR_ + "/images/kuma_had.png"; var KUMA_BODY = _DIR_ + "/images/kuma_body.png"; var KUMA_L_ARM = _DIR_ + "/images/kuma_L_arm.png"; var KUMA_L_LEG = _DIR_ + "/images/kuma_L_leg.png"; var KUMA_R_ARM = _DIR_ + "/images/kuma_R_arm.png"; var KUMA_R_LEG = _DIR_ + "/images/kuma_R_leg.png"; var KUMA_W_HAD =_DIR_ + "/images/kuma_w_had.png"; var KUMA_W_BODY = _DIR_ + "/images/kuma_w_body.png"; var KUMA_L_W_ARM = _DIR_ + "/images/kuma_L_w_arm.png"; var KUMA_L_W_LEG = _DIR_ + "/images/kuma_L_w_leg.png"; var KUMA_R_W_ARM = _DIR_ + "/images/kuma_R_w_arm.png"; var KUMA_R_W_LEG = _DIR_ + "/images/kuma_R_w_leg.png"; var BALL = _DIR_ + "/images/s_ball.png"; var KUSA = _DIR_ + "/images/kusa.png"; var KAGE = _DIR_ + "/images/kage_1.png"; var BGM_FALLING1 =_DIR_ + "/sounds/falling1.mp3"; //ボールのスピード普通 var BGM_FALLING2 = _DIR_ + "/sounds/falling1-2.mp3"; //ボールのスピード遅い var BGM_BALL = _DIR_ + "/sounds/soccer-ball1.mp3"; //ボールを受ける var ASSETS = [KUMA_HAD,KUMA_BODY,KUMA_L_ARM,KUMA_L_LEG,KUMA_R_ARM,KUMA_R_LEG, KUMA_W_HAD,KUMA_W_BODY,KUMA_L_W_ARM,KUMA_L_W_LEG,KUMA_R_W_ARM,KUMA_R_W_LEG,BALL,KUSA,KAGE, BGM_FALLING1,BGM_BALL,BGM_FALLING2]; var game =null; var time = 0; var f1=0; var f2=0; var had_y = 1; var time1 = 60/2; var time2 = 80/2; var time3 = 140/2; var time_max = 200/2; var time_max_2 = time_max+140; var time_max_3 = 140; var time_max_4 = 183; var KUMA_X = 450; var KUMA_Y = -20; var x=0,y=0; var tt=0; var t=0; var v0=4.5; var g=9.8; var s=0; var y1=0.7; var y2=0.7; var y3=0.7; var y4=0.7; var y5=0.7; var y6=0.7; var y7=0.7; var ball_x; var ball_y; var kg2; var ff = 0; //キーバインド設定 var keyset = function(key){ game.keybind(key, 'a'); //aボタン(「z」キー)を押した時のイベント処理 game.currentScene.onabuttondown = function() { var ev = new Event('touchstart'); // 発火! game.currentScene.dispatchEvent(ev); }; }; var randfloat = function(min, max) { return Math.random()*(max-min)+min; }; var b = randfloat(1,2); 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 fps = game.fps; var fps_now = BALL_SPEED.set; var move_now =BALL_MOVE.set; //初期設定// if(BALL_MOVE.set ==1){ ball_move = 1; move_now = BALL_MOVE.set; } else if(BALL_MOVE.set == 2){ ball_move = 2; move_now=BALL_MOVE.set; } else if(BALL_MOVE.set == 3){ ball_move =kg2; move_now=BALL_MOVE.set; } if(BALL_SPEED.set == 1){ game.fps = 60; fps_now = BALL_SPEED.set; } else if (BALL_SPEED.set ==2){ game.fps = 30; fps_now = BALL_SPEED.set; } this.onenterframe = function(){ if(BALL_SPEED.set != fps_now){ if(BALL_SPEED.set == 1){ game.fps = 60; fps_now = BALL_SPEED.set; } else if (BALL_SPEED.set ==2){ game.fps = 30; fps_now = BALL_SPEED.set; } } }; var scene = game.rootScene; var scene_now = BACK.set; //背景 //熊の画像を表示 var kusa = new Sprite(900,1200); kusa.image =game.assets[KUSA]; if(BACK.set==2){ scene.removeChild(kusa); scene.backgroundColor = "black"; scene_now = BACK.set; } else if(BACK.set==1){ scene.addChild(kusa); scene_now = BACK.set; } else if (BACK.set == 3){ scene.removeChild(kusa); scene.backgroundColor = "white"; scene_now = BACK.set; } var RA = new R_A(); var RL = new R_L(); var had = new Had(); var body = new Body(); var LL = new L_L(); var LA = new L_A(); var S_BALL = new s_BALL(); var KG = new K_G(); var KG2 = new K_G_2(); scene.addChild(KG2); scene.addChild(KG); scene.addChild(RA); scene.addChild(RL); scene.addChild(body); scene.addChild(had); scene.addChild(LL); scene.addChild(LA); scene.addChild(S_BALL); scene.onenterframe = function() { if(BACK.set != scene_now){ if(BACK.set==1){ scene.addChild(kusa); scene_now = BACK.set; scene.addChild(KG2); scene.addChild(KG); scene.addChild(RA); scene.addChild(RL); scene.addChild(body); scene.addChild(had); scene.addChild(LL); scene.addChild(LA); scene.addChild(S_BALL); }else if(BACK.set == 2){ scene.removeChild(kusa); scene.backgroundColor = "black"; scene_now = BACK.set; scene.addChild(KG2); scene.addChild(KG); scene.addChild(RA); scene.addChild(RL); scene.addChild(body); scene.addChild(had); scene.addChild(LL); scene.addChild(LA); scene.addChild(S_BALL); }else if(BACK.set == 3){ scene.removeChild(kusa); scene.backgroundColor = "white"; scene_now = BACK.set; scene.addChild(KG2); scene.addChild(KG); scene.addChild(RA); scene.addChild(RL); scene.addChild(body); scene.addChild(had); scene.addChild(LL); scene.addChild(LA); scene.addChild(S_BALL); } } if(BALL_MOVE.set ==1){ ball_move = 1; move_now = BALL_MOVE.set; } else if(BALL_MOVE.set == 2){ ball_move = 2; move_now=BALL_MOVE.set; } else if(BALL_MOVE.set == 3){ ball_move = kg2; move_now=BALL_MOVE.set; } };    //シーン更新時の処理 scene.ontouchstart = function(){ LOG_switch(); f1=1; f2=1; if(f1==1 && s==0){ this.onenterframe = function () { time++; if(time == time_max_2){ LOG_mystop(); time = 0; f1 = 0; t=0; s=1; game.assets[BGM_BALL].play(); this.onenterframe = null; scene.onenterframe = function() { if(BACK.set != scene_now){ if(BACK.set==1){ scene.addChild(kusa); scene_now = BACK.set; scene.addChild(KG2); scene.addChild(KG); scene.addChild(RA); scene.addChild(RL); scene.addChild(body); scene.addChild(had); scene.addChild(LL); scene.addChild(LA); scene.addChild(S_BALL); }else if(BACK.set == 2){ scene.removeChild(kusa); scene.backgroundColor = "black"; scene_now = BACK.set; scene.addChild(KG2); scene.addChild(KG); scene.addChild(RA); scene.addChild(RL); scene.addChild(body); scene.addChild(had); scene.addChild(LL); scene.addChild(LA); scene.addChild(S_BALL); }else if(BACK.set == 3){ scene.removeChild(kusa); scene.backgroundColor = "white"; scene_now = BACK.set; scene.addChild(KG2); scene.addChild(KG); scene.addChild(RA); scene.addChild(RL); scene.addChild(body); scene.addChild(had); scene.addChild(LL); scene.addChild(LA); scene.addChild(S_BALL); } } if(BALL_MOVE.set ==1){ ball_move = 1; move_now = BALL_MOVE.set; } else if(BALL_MOVE.set == 2){ ball_move = 2; move_now=BALL_MOVE.set; } else if(BALL_MOVE.set == 3){ ball_move = kg2; move_now=BALL_MOVE.set; } }; //this.ontouchstart = null; } }; } else if(f1==1&&s==1){ f2=0; this.onenterframe = function(){ time++; if(time == time_max_4){ f1 = 0; time = 0; s=0; t=0; scene.removeChild(S_BALL); scene.addChild(S_BALL); game.assets[BGM_BALL].play(); this.onenterframe = null; scene.onenterframe = function() { if(BACK.set != scene_now){ if(BACK.set==1){ scene.addChild(kusa); scene_now = BACK.set; scene.addChild(KG2); scene.addChild(KG); scene.addChild(RA); scene.addChild(RL); scene.addChild(body); scene.addChild(had); scene.addChild(LL); scene.addChild(LA); scene.addChild(S_BALL); } else if(BACK.set == 2){ scene.removeChild(kusa); scene.backgroundColor = "black"; scene_now = BACK.set; scene.addChild(KG2); scene.addChild(KG); scene.addChild(RA); scene.addChild(RL); scene.addChild(body); scene.addChild(had); scene.addChild(LL); scene.addChild(LA); scene.addChild(S_BALL); } else if(BACK.set == 3){ scene.removeChild(kusa); scene.backgroundColor = "white"; scene_now = BACK.set; scene.addChild(KG2); scene.addChild(KG); scene.addChild(RA); scene.addChild(RL); scene.addChild(body); scene.addChild(had); scene.addChild(LL); scene.addChild(LA); scene.addChild(S_BALL); } } if(BALL_MOVE.set ==1){ ball_move = 1; move_now = BALL_MOVE.set; } else if(BALL_MOVE.set == 2){ ball_move = 2; move_now=BALL_MOVE.set; } else if(BALL_MOVE.set == 3){ ball_move = kg2; move_now=BALL_MOVE.set; } }; } }; } }; }; game.start(); }; //熊クラス////////////////////////////////////////////// //右腕 var R_A = Class.create(Sprite,{ initialize: function(){ Sprite.call(this,120,500); if(BACK.set==2) this.image = game.assets[KUMA_R_W_ARM]; else this.image = game.assets[KUMA_R_ARM]; this.scale(0.5,0.5); this.moveTo(KUMA_X+125,KUMA_Y+30); this.update =this.move; }, move: function(){ if(s==0){ if(f1 == 1 && time < time1){ this.rotate(2); this.moveBy(0.2,0.05); } else if(f1 == 1 &&time >= time1 && time < time2) this.rotate(0); else if (f1 ==1 && time >= time2 && time = time3 && time < time_max) this.rotate(2); } if(f1==0){ //if(this.y<=40){ //yy=0.2; this.moveBy(0,y1); //} if(this.y>=KUMA_Y+50){ y1=-0.7; this.moveBy(0,y1); this.rotate(10); } if(this.y<=KUMA_Y+30){ y1=0.7; this.rotate(-10); } } }, //更新処理 onenterframe: function(){ this.update(); if(BACK.set==2) this.image = game.assets[KUMA_R_W_ARM]; else this.image = game.assets[KUMA_R_ARM]; }, ontouchstart: function(){ }, }); //右足 var R_L = Class.create(Sprite,{ initialize: function(){ Sprite.call(this,140,450); this.image = game.assets[KUMA_R_LEG]; this.moveTo(KUMA_X+120,KUMA_Y+160); this.scale(0.5,0.5); this.update =this.move; }, move: function(){ if(s==0){ if(f1 == 1 && time < time1) this.rotate(-1); else if(time >=time1 && time < time2) this.rotate(0); else if (time >= time2 && time < time3) this. rotate(2); else if ( time >= time3 && time < time_max){ this.rotate(-1); f2=0; } } if(f1==0){ this.moveBy(0,y2); if(this.y>=KUMA_Y+180){ y2=-0.7; this.moveBy(0,y2); this.rotate(-10); } if(this.y<=KUMA_Y+160){ y2=0.7; this.rotate(10); } } }, //更新処理 onenterframe: function(){ this.update(); if(BACK.set==2) this.image=game.assets[KUMA_R_W_LEG]; else this.image=game.assets[KUMA_R_LEG]; }, ontouchstart: function(){ }, }); //胴体 var Body = Class.create(Sprite,{ initialize: function(){ Sprite.call(this,500,667); this.image = game.assets[KUMA_BODY]; this.moveTo(KUMA_X,KUMA_Y); this.scale(0.5,0.5); this.update =this.move; }, move: function(){ if(s==0){ if(f1 == 1 && time < time1) this.rotate(0.25); else if(time >=time1 && time < time2) this.rotate(0); else if (time >= time2 && time < time3) this. rotate(-0.5); else if ( time >= time3 && time < time_max) this.rotate(0.25); } if(f1==0){ this.moveBy(0,y3); if(this.y>=KUMA_Y+20){ y3=-0.7; this.moveBy(0,y3); this.rotate(5); } if(this.y<=KUMA_Y){ y3=0.7; this.rotate(-5); } } }, //更新処理 onenterframe: function(){ this.update(); if(BACK.set==2) this.image=game.assets[KUMA_W_BODY]; else this.image=game.assets[KUMA_BODY]; }, ontouchstart: function(){ }, }); //頭 var Had = Class.create(Sprite,{ initialize: function(){ Sprite.call(this,500,667); this.image = game.assets[KUMA_HAD]; this.moveTo(KUMA_X,KUMA_Y); this.scale(0.5,0.5); this.update =this.move; }, move: function(){ if(s==0){ if(f1 == 1 && time < time1) this.rotate(0.25); else if(time >=time1 && time < time2) this.rotate(0); else if (time >= time2 && time < time3) this. rotate(-0.5); else if ( time >= time3 && time < time_max) this.rotate(0.25); } if(f1==0){ this.moveBy(0,y4); if(this.y>=KUMA_Y+20){ y4=-0.7; this.moveBy(0,y4); this.rotate(5); kg2=2; } if(this.y<=KUMA_Y){ kg2=1; y4=0.7; this.rotate(-5); } } }, //更新処理 onenterframe: function(){ this.update(); if(BACK.set==2) this.image=game.assets[KUMA_W_HAD]; else this.image=game.assets[KUMA_HAD]; }, ontouchstart: function(){ }, }); //左足 var L_L = Class.create(Sprite,{ initialize: function(){ Sprite.call(this,164,496); this.image = game.assets[KUMA_L_LEG]; this.moveTo(KUMA_X+190,KUMA_Y+150); this.scale(0.5,0.5); this.update =this.move; }, move: function(){ if(s==0){ if(f1 == 1 && time < time1) this.rotate(0.5); else if(time >=time1 && time < time2) this.rotate(0); else if (time >= time2 && time < time3) this. rotate(-0.5); else if ( time >= time3 && time < time_max) this.rotate(0); } if(f1==0){ this.moveBy(0,y5); if(this.y>=KUMA_Y+170){ y5=-0.7; this.moveBy(0,y5); this.rotate(10); } if(this.y<=KUMA_Y+150){ y5=0.7; this.rotate(-10); } } }, //更新処理 onenterframe: function(){ this.update(); if(BACK.set==2) this.image=game.assets[KUMA_L_W_LEG]; else this.image=game.assets[KUMA_L_LEG]; }, ontouchstart: function(){ }, }); //左腕 var L_A = Class.create(Sprite,{ initialize: function(){ Sprite.call(this,112,496); this.image = game.assets[KUMA_L_ARM]; this.moveTo(KUMA_X+230,KUMA_Y+40); this.scale(0.5,0.5); this.update =this.move; }, move: function(){ if(s==0){ if(f1 == 1 && time < time1){ this.rotate(-1); //this.moveBy(0.2,0.2); } else if(time >=time1 && time < time2) this.rotate(0); else if (time >= time2 && time < time3){ this. rotate(2); //this.moveBy(-0.4,-0.2); } else if ( time >= time3 && time < time_max){ //this.moveBy(0.2,0); this.rotate(-1); } } if(f1==0){ this.moveBy(0,y6); if(this.y>=40){ y6=-0.7; this.moveBy(0,y6); this.rotate(-10); } if(this.y<=20){ y6=0.7; this.rotate(10); } } }, //更新処理 onenterframe: function(){ this.update(); if(BACK.set==2) this.image=game.assets[KUMA_L_W_ARM]; else this.image=game.assets[KUMA_L_ARM]; }, ontouchstart: function(){ }, }); //ボール var s_BALL = Class.create(Sprite,{ initialize: function(){ Sprite.call(this,300,300); this.image = game.assets[BALL]; this.moveTo(KUMA_X-10,KUMA_Y+300); this.scale(0.4,0.4); this.update =this.move; ball_x=this.x+65; ball_y=this.y+195; }, move: function(){ ///動作1 ball_x=this.x+65; ball_y=this.y+199; if (f1 == 1 && s==0 && time >= time3-15 && time < time_max_2-1 && ball_move == 1){ if(ff == 0){ LOG_bearkick(); if(BALL_SPEED.set == 1) game.assets[BGM_FALLING1].play(); else game.assets[BGM_FALLING2].play(); ff = 1; } t++; x=v0*Math.cos(60*(Math.PI/180))*t; y=v0*Math.sin(60*(Math.PI/180))*t*1.5-(1/2*g*t*t)/100; this.moveTo(440-x,300-y); this.rotate(-5); this.scale(1006/1000); t_y=this.y; t_x=this.x; } else if (f1 == 1 && s == 1 && time < time_max_4-1 && ball_move ==1){ if(ff == 1){   LOG_mykick(); if(BALL_SPEED.set == 1){ game.assets[BGM_FALLING1].stop(); game.assets[BGM_FALLING1].play(); } else {game.assets[BGM_FALLING2].stop(); game.assets[BGM_FALLING2].play();} } t++; ff=0; x=v0*Math.cos(120*(Math.PI/180))*t; y=v0*Math.sin(100*(Math.PI/180))*t*2.8-(1/2*g*t*t)/100; this.moveTo(t_x-x,t_y-y); this.rotate(6); this.scale(1000/1006); } else if (time == time_max_4-1 && ball_move==1){ this.moveTo(KUMA_X-10,KUMA_Y+300); this.scale(1000/1006); ball_x=this.x+65; ball_y=this.y+199; LOG_bearstop(); game.assets[BGM_BALL].play(); } ///動作2 if(f1== 1 && s==0 && time >=time3-15 && time < time_max_2-1 && ball_move == 2){ if(ff == 0){ LOG_bearkick(); game.assets[BGM_FALLING1].play(); ff = 1; } t++; this.moveBy(-2.2,3.2); this.rotate(10); this.scale(1006/1000); if(this.y>=900) this.moveBy(2,-3); } else if (f1 == 1 && s == 1 && time < time_max_4-1 && ball_move==2){ if(ff == 1){ LOG_mykick(); game.assets[BGM_FALLING1].stop(); game.assets[BGM_FALLING1].play(); } ff=0; t++; this.moveBy(2.2,-3.2); this.rotate(-10); this.scale(1000/1006); } else if (f1 == 1 && s == 1 && time == time_max_4-1 && ball_move==2){ this.moveTo(KUMA_X-10,KUMA_Y+300); this.scale(1000/1006); ball_x=this.x+65; ball_y=this.y+199; LOG_bearstop(); game.assets[BGM_BALL].play(); } }, //更新処理 onenterframe: function(){ this.update(); }, ontouchstart: function(){ }, }); //影(ボール) var K_G = Class.create(Sprite,{ initialize: function(){ Sprite.call(this,222,30); this.image = game.assets[KAGE]; //this.moveTo(ball_x,ball_y+300); this.scale(1/2,14/10); this.update = this.move; this.moveTo(ball_x,ball_y); }, move: function(){ if (f1 == 1 && s==0 && time >= time3-15 && time < time_max_2 && ball_move == 1){ this.scale(1006/1000,1009/1000); this.moveBy(-2.2,3.3); } else if (f1 == 1 && s == 1 && time < time_max_4-1 && ball_move ==1){ this.moveBy(2.2,-3.3); this.scale(1000/1006,1000/1009); } else if (time == time_max_4-1 && ball_move==1){ this.moveTo(ball_x,ball_y); this.scale(1000/1006,1000/1008); } if(f1== 1 && s==0 && time >=time3-15 && time < time_max_2 && ball_move == 2){ this.scale(1006/1000,1009/1000); this.moveTo(ball_x,ball_y); } else if (f1 == 1 && s == 1 && time < time_max_4-1 && ball_move==2){ this.scale(1000/1006,1000/1009); this.moveTo(ball_x,ball_y); } else if (f1 == 1 && s == 1 && time == time_max_4-1 && ball_move==2){ this.moveTo(ball_x,ball_y); this.scale(1000/1006,1000/1009); } }, onenterframe: function(){ this.update(); }, }); //影(本体) var K_G_2 = Class.create(Sprite,{ initialize: function(){ Sprite.call(this,222,30); this.image = game.assets[KAGE]; this.moveTo(KUMA_X+120,KUMA_Y+500); this.scale(2/3,14/10); this.update = this.move; }, move: function(){ /*if(f1==0){ if(kg2==0){ this.scale(1006/1000); } if(kg2==1){ this.scale(1000/1005.9); } }*/ }, onenterframe: function(){ this.update(); }, });