Skip to content

Commit

Permalink
Merge pull request #107 from java-women/feature/issue68
Browse files Browse the repository at this point in the history
issue#68 の対応
  • Loading branch information
erk5 authored Jul 23, 2016
2 parents 89bbcbb + 0c7e84f commit d81519c
Showing 1 changed file with 146 additions and 6 deletions.
152 changes: 146 additions & 6 deletions JavajoTeachingForKids/src/main/resources/static/js/coordinate002.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
enchant();;

var score;
const MAX_TIME = 15;
var bear ;
var scene ;

window.onload = function() {

core = new Core(320, 320);
Expand All @@ -12,27 +17,68 @@ window.onload = function() {

// ゲーム本体の描画
core.onload = function() {
document.getElementById('location-x').value=1;
document.getElementById('location-y').value=1;
core.replaceScene(createGameScene());

core.replaceScene(createStartScene());
};

core.start();
};

//タイトルシーンカスタマイズ
function createStartScene(){

var scene = new Scene();
scene.backgroundColor = '#3cb371';
var startImage = new Sprite(236, 48);
startImage.image = core.assets['start.png'];
startImage.x = 42;
startImage.y = 136;
scene.addChild(startImage);

var subTitle = new Label('【あそびかた】');
subTitle.textAlign = 'center';
subTitle.y = 190;
subTitle.font = '14px sans-serif';
scene.addChild(subTitle);

var line1 = new Label('マウスをつかってりんごをあつめよう!');
line1.textAlign = 'center';
line1.y = 210;
line1.font = '14px sans-serif';
scene.addChild(line1);

startImage.addEventListener(Event.TOUCH_START, function(e) {
core.replaceScene(createGameScene());
});

return scene;
}

/**
* ゲームシーン
*/
function createGameScene() {
// 初期値設定
score = 0;
document.getElementById('location-x').value=1;
document.getElementById('location-y').value=1;


/* キャラクター初期表示 */
var scene = new Scene();
var bear = new Sprite(32, 32);
scene = new Scene();

scene.addChild(drawGrid());

bear = new Sprite(32, 32);
bear.image = core.assets['chara1.png'];

scene.addChild(bear);

// りんご生成
for (i = 0; i < 10; i++) {
scene.addChild(new Fruits(15,bear));
}

// シーンにタッチ移動時イベントを登録
var isTouch = false;
var targetX = 0;
Expand Down Expand Up @@ -66,10 +112,104 @@ function createGameScene() {
document.getElementById('location-y').value=Math.round((bear.y+16)/16+1);
//移動
bear.moveBy(moveX, moveY);

}
});

scene.addChild(drawGrid());
// スコアとタイマー
scene.addChild(new Score());
scene.addChild(new Timer());

return scene;
}

//フルーツクラス
Fruits = Class.create(Sprite,
{
initialize: function(frame,bear) {
Sprite.call(this, 16, 16);
this.image = core.assets['icon0.png'];

// ランダムな場所にフルーツを表示する
this.x = Math.round(Math.random() * 19) * 16;
this.y = Math.round(Math.random() * 19) * 16;
this.frame = frame;

},

onenterframe: function(){

if (this.within(bear)) {
// 自分自身(フルーツ)を画面から消す
scene.removeChild(this);
score++;
}
}
});

/**
* タイマークラス
*/
var Timer = Class.create(Label, {

// 初期化
initialize: function() {
Label.call(this);

core.frame = 0;
this.moveTo(5, 5);
this.color = 'white';
this.font = "15px 'Consolas', 'Monaco', 'MS ゴシック'";
this.text = 'Timer:';
},

// カウントダウン
countdown: function() {
var time = MAX_TIME - Math.floor(core.frame/core.fps);
this.text = 'Timer:' + time;

// ゲームオーバー
if (time == 0) {
core.replaceScene(createGameoverScene());
}
},

// 更新処理
onenterframe: function(){
this.countdown();
}
});


/**
* スコアクラス
*/
var Score = Class.create(Label, {

// 初期化
initialize: function() {
Label.call(this);

this.moveTo(5, 300);
this.color = 'white';
this.font = "15px 'Consolas', 'Monaco', 'MS ゴシック'";
this.text = score + ' ポイント';
},

// カウント
scoreCount: function() {
this.text = score + ' ポイント';

// ゲームクリア
if (score == 10) {
core.replaceScene(createGameclearScene());
}
},

// 更新処理
onenterframe: function(){
this.scoreCount();
}
});


0 comments on commit d81519c

Please sign in to comment.