enchant();
window.focus();
var _DIR_ = SwitchApps.scriptDir();
var logger = null;
/*
*オプション項目の設定
*/
$(document).ready(function(){
logger = new SwitchApps.Logger(SwitchApps.app.id, null);
/*ログの設定*/
LOG_switch = logger.addHeader('スイッチ入力');
LOG_shoot = logger.addHeader('ボールをシュート');
LOG_hit = logger.addHeader('キーパーに当たった');
LOG_hit2 = logger.addHeader('キーパー:%s');
LOG_goal = logger.addHeader('ゴールした');
LOG_point = logger.addHeader('得点:%d');
LOG_ouen = logger.addHeader('応援');
/*グローバル変数の宣言*/
PENGIN_NUM = {set:2,targetname:["pengin_pog"],targetvalue:[1,]};//1:1匹 2:2匹
PENGIN_POG = {set:1};//
PENGIN_SPEED = {set:2};//1:おそい 2:ふつう 3:はやい
// CLEAR_NUM ={set:10}//クリア得点マックス30
// GAME_MODE = {set:1};
/* BALL_MDOE={set:1,targetname:["ball_auto"],targetvalue:[2,]};
BALL_SPEED={set:2};
BALL_DISTANCE={set:1};*/
SHOOT_SPEED = {set:2};
PENGIN_DISTANCE={set:2};
PENGIN_MOVE ={set:1};
//ラジオボタン生成//
//createSettingBoxException1("目標得点","clear_num",CLEAR_NUM,50,1,20);
createSettingBox("ペンギンの数","pengin_num",PENGIN_NUM,38,"1匹","2匹");
createSettingBox("ペンギンの位置","pengin_pog",PENGIN_POG,45,"ボール側","ゴール側");
createSettingBox("シュートの速さ","shoot_speed",SHOOT_SPEED,49,"おそい","標準","速い");
//createSettingBox("ゲームモード","game_mode",GAME_MODE,40,"ペンギン移動","ボール 移動");
// createSettingBox("ペンギン移動モード","pengin_move",PENGIN_MOVE,51,"オートスキャン","ステップスキャン")
// createSettingBox("ボール移動モード","ball_mode",BALL_MDOE,41,"オート スキャン","ステップスキャン");
// createSettingBox("ボールの移動速度","ball_speed",BALL_SPEED,43,"おそい","標準","はやい");
// createSettingBox("ボールの移動幅","ball_distance",BALL_DISTANCE,44,"せまい","標準","広い");
createSettingBox("ペンギンの速さ","pengin_speed",PENGIN_SPEED,39,"おそい","標準","はやい");
createSettingBox("ペンギンの移動幅","pengin_distance",PENGIN_DISTANCE,42,"せまい","標準","広い");
//項目のグループ化
//$("#pengin_speed,#pengin_distance,#pengin_move").wrapAll("")//ペンギンモード
// $("#ball_mode,#ball_speed,#ball_distance").wrapAll("");//ボールモード
// $("#ball_speed,#ball_distance").wrapAll("")
})
var game = null;
var SCREEN_W = 320; //スクリーンの幅
var SCREEN_H = 320; //スクリーンの高さ
var TIME=0;
window.onload = function(){
//ゲームオブジェクトの作成
game = new Core(SCREEN_W,SCREEN_H);
//fpsの指定
game.fps = 16;
//画像の読み込み
game.preload(
_DIR_ + '/images/penguin.png', //ペンギン
_DIR_ + '/images/ball.gif', //ボール
_DIR_ + '/images/goal.png', //ゴール
_DIR_ + '/images/field.png', //フィールド
_DIR_ + '/images/man.png', //人
_DIR_ + '/images/go-ru.png', //ゴールポスト
_DIR_ + '/sounds/ball.mp3', //ボール音
_DIR_ + '/sounds/hit.mp3', //ペンギンにぶつかる音
_DIR_ + '/sounds/goal.mp3', //ゴール音
_DIR_ + '/sounds/blowoff.mp3', //ペンギンが飛ぶ音
_DIR_ + '/sounds/man.mp3'); //応援
//ロード時に呼ばれる
game.onload = function(){
num = 0;//応援の数
var bg = new Sprite(320,400);//背景の生成
bg.image = game.assets[_DIR_ + '/images/field.png'];//フィールド
bg.y = -50;
game.rootScene.addChild(bg);
var goal = new Sprite(268,160);//ゴールの描画
goal.image = game.assets[_DIR_ + '/images/go-ru.png'];
goal.x = 28;
goal.y = -52;
goal_scaleX = 0.95;
game.rootScene.addChild(goal);
//ディフェンス熊生成
bear1 = new Kuma(240,80,5,3);
bear2 = new Kuma(140,180,8,2);
game.rootScene.addChild(bear1);
game.rootScene.addChild(bear2);
//ボール生成
ball = new Ball();
game.rootScene.addChild(ball);
//ラジオボタンの変
/*不明要素
var ball_t = new Sprite(64,64);
ball_t.x = 128;
ball_t.y = SCREEN_W-64;
game.rootScene.addChild(ball_t);*/
//スコア関連のグループ
var score = new Group();
//背景
var score_Tbg = new Sprite(72,20);
score_Tbg.backgroundColor = '#d1d1ff';
score_Tbg.x = SCREEN_W-74;
score_Tbg.y = SCREEN_W-60;
score.addChild(score_Tbg);
//とくてん
var score_Txt = new Label("とくてん");
score_Txt.font = "18px Tagoma";
score_Txt.x = SCREEN_W-75;
score_Txt.y = SCREEN_W-60;
score.addChild(score_Txt);
var score_x = 0;
//得点の表示
var score_bg = new Sprite(48,40);
score_bg.backgroundColor = 'yellow';
score_bg.x = SCREEN_W-54;
score_bg.y = SCREEN_W-40;
score.addChild(score_bg);
var score_num = new Label("0");
score_num.font = "40px Tahoma";
score_num.x=SCREEN_W-30;
score_num.y=SCREEN_W-40;
score.addChild(score_num);
//スコアグループの描画
game.rootScene.addChild(score);
//応援
aid = new Aid();
game.rootScene.addChild(aid);
/*応援メッセージ
var aid_txt = new Label("がんばれ!!");
*/
//パワーメーター関連
var power = new Group();
var power_bg = new Sprite(50,140);
power_bg.backgroundColor = 'blue';
power_bg.y = 30;
power.addChild(power_bg);
var power_N_bg = new Sprite(70,30);
power_N_bg.backgroundColor = 'white';
power.addChild(power_N_bg);
var power_meter = new Sprite(35,20);
power_meter.backgroundColor ='yellow';
power_meter.x = 8;
power_meter.y = 145;
power.addChild(power_meter);
var power_txt = new Label("Power");
power_txt.font = "25px Tahoma";
power_txt.color = 'red';
power.addChild(power_txt);
//パワー関連描画
game.rootScene.addChild(power);
//ゴール時のメッセージ
var goal_mes = new Goal_Mes()
game.rootScene.addChild(goal_mes);
//キーバインド設定
game.keybind(49,'a');
game.keybind(32,'a');
//応援
game.addEventListener('abuttondown',function(){
LOG_switch();
LOG_ouen();
game.assets[_DIR_ + '/sounds/man.mp3'].clone().play();
aid.flg = 1;
if(aid.num < 5){//応援の数は5回でマックス
aid.num++;
ball.sp_weight = aid.num;
power.childNodes[2].scaleY += 1;
power.childNodes[2].y -= 10;
}
})
//シュート
game.keybind(51,'b');
game.keybind(13,'b');
game.keybind(123,'b');
game.addEventListener('bbuttondown',function(){
var ev = new Event('touchstart');
game.currentScene.dispatchEvent(ev);
});
game.rootScene.ontouchstart = function(){
LOG_switch();
if(ball.flg === 0){
ball.flg = 1;
LOG_shoot();
ball.move(aid.num);
game.assets[_DIR_ + '/sounds/ball.mp3'].clone().play();
}
};
/*
*シーン更新処理
*/
game.rootScene.onenterframe = function(){
//ボールが熊1に当たる
if(ball.within(bear1, 32)){
LOG_hit();
//熊の左にあたる
if(bear1.x >= ball.x && bear1.flg === 0){
LOG_hit2('左');
bear1.HIT_L();
aid.HIT();
}
//熊の右にあたる
else if(bear1.x < ball.x && bear1.flg === 0){
LOG_hit2('右');
bear1.HIT_R();
aid.HIT();
}
}
//ボールが熊2に当たる
if(ball.within(bear2, 32)){
LOG_hit();
//熊の左にあたる
if(bear2.x >= ball.x && bear2.flg === 0){
LOG_hit2('左');
bear2.HIT_L();
aid.HIT();
}
//熊の右にあたる
else if(bear2.x < ball.x && bear2.flg === 0){
LOG_hit2('右');
bear2.HIT_R();
aid.HIT();
}
}
//ボールが画面端に到着
if(ball.y < 20){
//入ったとき
if(ball.x <= 360-120 && ball.x >= 50){
game.rootScene.removeChild(ball);
ball.flg = 2;
score_x++;
LOG_goal();
LOG_point(score_x);
if(score_x == 10) score_num.x = SCREEN_W - 50;
score_num.text = score_x;
game.assets[_DIR_ + '/sounds/goal.mp3'].clone().play();//ゴール音
goal_mes.Goal();//ゴールメッセージの表示
}
game.rootScene.removeChild(ball);
ball.x = 160-16;
ball.y = SCREEN_W-32;
game.rootScene.addChild(ball);
//console.log(ball.x)
ball.flg = 0;
aid.num = 0;
//熊1再配置
if(bear1.flg !=10){
game.rootScene.removeChild(bear1);
if(bear1.flg !==0){
bear1.y = 80;
}
bear1.flg = 0;
game.rootScene.addChild(bear1);
}
//熊2再配置
if(bear2.flg !=10){
game.rootScene.removeChild(bear2);
if(bear2.flg !==0){
bear2.y = 180;
}
game.rootScene.addChild(bear2);
bear2.flg = 0;
}
//パワーメーター初期化
game.rootScene.removeChild(power);
power.childNodes[2].scaleY = 1;
power.childNodes[2].y = 145;
game.rootScene.addChild(power);
}
}
//var old_val = 0;
$('input[name="pengin_num"]:radio').change(function(){
if(PENGIN_NUM.set==1){
if(PENGIN_POG.set == 1)
bear1.Des();
else bear2.Des();
}
else if(PENGIN_NUM.set == 2){
if(bear1.flg == 10)
bear1.Resurrection(240,80);
if(bear2.flg == 10)
bear2.Resurrection(140,180);
}
});
$('input[name="pengin_pog"]:radio').change(function(){
if(PENGIN_POG.set == 2){
bear2.Des();
if(bear1.flg == 10){
bear1.Resurrection(240,80);
}
}
else if(PENGIN_POG.set == 1){
bear1.Des();
if(bear2.flg == 10){
bear2.Resurrection(140,180);
}
}
})
}
game.start();
}
var Kuma = Class.create(Sprite,{
//初期化処理
initialize: function(x,y,diration,speed){
Sprite.call(this,50,50);
this.image = game.assets[_DIR_ + '/images/penguin.png'];
this.tick = 0;//フレームの増加カウント
this.anim = [0,1,0,2];
this.scaleX = 1.2;
this.scaleY = 1.2;
this.x = x;
this.y = y;
this.flg = 0;//タッチフラグ
this.diration = diration;//進む距離
this.speed = speed;//フレームの増加スピード
},
//更新処理
onenterframe: function(){
//ボールが接触していない
if(this.flg === 0){
//console.log(game.frame)
if((game.frame % this.speed) === 0 ) this.tick++; //画像の更新
this.frame = this.anim[this.tick % 4];
//右向きに動く
if(this.scaleX == 1.2){
this.x += this.diration*(PENGIN_SPEED.set/2);
//向き変更
if(this.x > 200+(15*(PENGIN_DISTANCE.set-1))) this.scaleX = -1.2;
}
//左向き
else if(this.scaleX == -1.2){
this.x -= this.diration*(PENGIN_SPEED.set/2);
//向きの変更
if(this.x < 85-(15*(PENGIN_DISTANCE.set-1))) this.scaleX = 1.2;
}
}
else if(this.flg ==1 && this.y>=0){
this.x -= 15;
this.y -= 10;
}
else if(this.flg == 2 && this.y>=0){
this.x += 15;
this.y -= 10;
}else game.rootScene.removeChild(this);
},
Des:function(){
game.rootScene.removeChild(this);
this.x=0;
this.y=0;
this.flg = 10;
},
Resurrection:function(x,y){
this.x = x;
this.y = y;
this.flg = 0;
game.rootScene.addChild(this);
},
HIT_L:function(){
if(aid.num >= 4){
game.assets[_DIR_ + '/sounds/blowoff.mp3'].clone().play(); //飛ぶ音
this.flg = 2;
//aid.num -= 4;
}
else {
game.assets[_DIR_ + '/sounds/hit.mp3'].clone().play(); //ぶつかる音
ball.flg = 3;
}
},
HIT_R:function(){
if(aid.num >= 4){
game.assets[_DIR_ + '/sounds/blowoff.mp3'].clone().play(); //飛ぶ音
this.flg = 1;
//aid.num -= 4;
}
else {
game.assets[_DIR_ + '/sounds/hit.mp3'].clone().play(); //ぶつかる音
ball.flg = 4;
}
}
});
var Ball = Class.create(Sprite,{
initialize:function(){
Sprite.call(this,32,32);
this.image = game.assets[_DIR_ + '/images/ball.gif'];
this.tick = 0;
this.anim = [0];
this.scaleX = 0.75;
this.scaleY = 0.75;
this.x = 144;
this.y = SCREEN_W-32;
this.flg = 0 ;//0:タッチされていない
//this.sp_weight = 0;
},
onenterframe:function(){
this.move();
},
move: function(){
//ボールが端につくまで移動
//console.log(num);
if(this.y >= 0 && this.flg == 1){
this.y -= ((4+3*SHOOT_SPEED.set) + (aid.num * 1.5));//応援の回数を重みにスピードの変化
if(this.scaleY == 0.75) this.scaleY = -0.75;
else if(this.scaleY == -0.75) this.scaleY=0.75
}
else if(this.y >= 0 && this.flg == 3){
this.x -= 15;
this.y -= (10 +(aid.num * 1.5));
}
else if(this.y >= 0 && this.flg == 4){
this.x += 15;
this.y -= (10 + (aid.num + 1.5));
}
},
});
var Aid = Class.create(Sprite,{
initialize: function(){
Sprite.call(this,350,350);
this.image = game.assets[_DIR_ + '/images/man.png'];
this.anim = [0,1];
this.scaleX = 0.3;
this.scaleY = 0.3;
this.x = -130;
this.y = 90;
this.tick = 0;
this.flg = 0;
this.num = 0;//応援された数
},
onenterframe: function(){
if(this.flg == 1){
this.tick++;
if((this.tick % 5) === 0){//5フレームでのアニメーション
this.frame = this.anim[this.tick % 2];
if(this.tick == 10){//アニメーション終了後の処理
this.flg = 0;
this.tick = 0;
}
}
}
},
HIT:function(){
this.num =0 ;
}
});
var Goal_Mes = Class.create(Sprite,{
initialize: function(){
Sprite.call(this,100,45);
this.image = game.assets[_DIR_ + '/images/goal.png'];
this.tick = 0;
this.anim = [0];
this.x = 380;
this.y = 140;
this.scaleX = 1.5;
this.scaleY = 1.25;
},
Goal: function(){
this.tl.moveX(120,10)
.moveX(120,15)
.moveX(-120,10);
},
});