diff --git a/src/main-scene.js b/src/main-scene.js index 324d1c6..8bb4255 100644 --- a/src/main-scene.js +++ b/src/main-scene.js @@ -138,6 +138,7 @@ var MainSceneLayer = cc.Layer.extend({ if(this.second_ < 0) { // リザルト状態へ移行 this.state_ = MainSceneLayer.GameState["RESULT"]; + this.onResult(); } } }, @@ -198,7 +199,35 @@ var MainSceneLayer = cc.Layer.extend({ this.removeFruit(fruit); this.score_ += 1; this.scoreLabel_.setString(cc.formatStr("%d", this.score_)); - } + }, + + onResult: function() { + this.state_ = MainSceneLayer.GameState["RESULT"]; + var winSize = cc.director.getWinSize(); + + // 「もう一度遊ぶ」ボタン + var replayButton = new cc.MenuItemImage(res.replayButton, + res.replayButtonPressed, + function() { + var scene = new MainScene(); + cc.director.runScene(scene); + }); + + // 「タイトルへ戻る」ボタン + var titleButton = new cc.MenuItemImage(res.titleButton, + res.titleButtonPressed, + function() { + // 「タイトルへ戻る」ボタンを押したときの処理 + // いまは何も実装していない + }); + + // 2つのボタンからメニューを作成する + var menu = new cc.Menu(replayButton, titleButton); + // ボタンを縦に並べる + menu.alignItemsVerticallyWithPadding(15); // ボタンを縦に並べる + menu.setPosition(cc.p(winSize.width / 2.0, winSize.height / 2.0)); + this.addChild(menu); + }, }); MainSceneLayer.FruitType = [ "APPLE", diff --git a/src/resource.js b/src/resource.js index 9428ada..0e6de63 100644 --- a/src/resource.js +++ b/src/resource.js @@ -7,7 +7,11 @@ var res = { "res/images/fruit2.png", "res/images/fruit3.png", "res/images/fruit4.png" - ] + ], + replayButton: "res/images/replay_button.png", + replayButtonPressed: "res/images/replay_button_pressed.png", + titleButton: "res/images/title_button.png", + titleButtonPressed: "res/images/title_button_pressed.png" }; var g_resources = [];