Skip to content

Commit

Permalink
Merge branch '4.4.2'
Browse files Browse the repository at this point in the history
refs #15
  • Loading branch information
niku committed Feb 28, 2015
2 parents 4c775c2 + 43e0e1f commit a81fa20
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/main-scene.js
Expand Up @@ -60,8 +60,42 @@ var MainSceneLayer = cc.Layer.extend({
this.player_.setPosition(cc.pClamp(newPosition, cc.p(0, position.y), cc.p(winSize.width, position.y)));
}.bind(this)
}, this);
},

addFruit: function() {
// 画面サイズを取り出す
var winSize = cc.director.getWinSize();


// フルーツの種類の数を上限としたランダムな整数を取得する
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Math/random
// の「min から max までの乱整数を返す関数」を参考にした
var randomFruitNumber = Math.floor(cc.random0To1() * (MainSceneLayer.FruitType.length));
// フルーツを作成する
var fruitName = cc.formatStr("fruit%d", randomFruitNumber);
var fruit = new cc.Sprite(res[fruitName]);
fruit.setTag(randomFruitNumber); // フルーツの種類をタグとして指定する

var fruitSize = fruit.getContentSize(); // フルーツのサイズを取り出す
var fruitXPos = Math.floor(cc.random0To1() * (winSize.width)); // X軸のランダムな位置を選択する

fruit.setPosition(cc.p(fruitXPos,
winSize.height - MainSceneLayer.FRUIT_TOP_MARGIN - fruitSize.height / 2.0));
this.addChild(fruit);
this.fruits_.push(fruit);

return fruit;
}
});
MainSceneLayer.FruitType = [
"APPLE",
"GRAPE",
"ORANGE",
"BANANA",
"CHERRY"
];
// フルーツの画面上端からのマージン(px)
MainSceneLayer.FRUIT_TOP_MARGIN = 40;

// http://www.cocos2d-x.org/reference/html5-js/V3.2/symbols/cc.Scene.html
var MainScene = cc.Scene.extend({
Expand Down
7 changes: 6 additions & 1 deletion src/resource.js
@@ -1,6 +1,11 @@
var res = {
background: "res/images/background.png",
player: "res/images/player.png"
player: "res/images/player.png",
fruit0: "res/images/fruit0.png",
fruit1: "res/images/fruit1.png",
fruit2: "res/images/fruit2.png",
fruit3: "res/images/fruit3.png",
fruit4: "res/images/fruit4.png"
};

var g_resources = [];
Expand Down

0 comments on commit a81fa20

Please sign in to comment.