Skip to content

Commit

Permalink
Merge branch '4.10.3'
Browse files Browse the repository at this point in the history
refs #33
  • Loading branch information
niku committed Mar 11, 2015
2 parents f8edff2 + 0d17e23 commit c49cea7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
66 changes: 54 additions & 12 deletions src/main-scene.js
Expand Up @@ -3,6 +3,7 @@ var MainSceneLayer = cc.Layer.extend({
player_: null,
fruits_: [],
score_: 0,
isCrash_: false,
second_: null,
state_: null,
scoreLabel_: null,
Expand Down Expand Up @@ -47,22 +48,24 @@ var MainSceneLayer = cc.Layer.extend({
return true;
}.bind(this),
onTouchMoved: function(touch, event) {
// タッチ中に動いたときの処理
// touch には Touch オブジェクトが渡されてくる
// http://www.cocos2d-x.org/reference/html5-js/V3.2/symbols/cc.Touch.html
if(!this.isCrash_) {
// タッチ中に動いたときの処理
// touch には Touch オブジェクトが渡されてくる
// http://www.cocos2d-x.org/reference/html5-js/V3.2/symbols/cc.Touch.html

// 前回とのタッチ位置との差をベクトルで取得する
var delta = touch.getDelta();
// 前回とのタッチ位置との差をベクトルで取得する
var delta = touch.getDelta();

// 現在のかわずたんの座標を取得する
var position = this.player_.getPosition();
// 現在のかわずたんの座標を取得する
var position = this.player_.getPosition();

// 現在座標 + 移動量を新たな座標にする
var newPosition = cc.pAdd(position, delta);
// 現在座標 + 移動量を新たな座標にする
var newPosition = cc.pAdd(position, delta);

var winSize = cc.director.getWinSize();
var winSize = cc.director.getWinSize();

this.player_.setPosition(cc.pClamp(newPosition, cc.p(0, position.y), cc.p(winSize.width, position.y)));
this.player_.setPosition(cc.pClamp(newPosition, cc.p(0, position.y), cc.p(winSize.width, position.y)));
}
}.bind(this)
}, this);

Expand Down Expand Up @@ -202,12 +205,21 @@ var MainSceneLayer = cc.Layer.extend({
},

catchFruit: function(fruit) {
// もしクラッシュしてたら,フルーツを取得できない
if(this.isCrash_) {
return;
}

var fruitType = fruit.getTag();
switch(MainSceneLayer.FruitType[fruitType]) {
case "GOLDEN":
this.score_ += MainSceneLayer.GOLDEN_FRUIT_SCORE;
cc.audioEngine.playEffect(res.catchGoldenEffect, false);
break;
case "BOMB":
this.onCatchBomb();
cc.audioEngine.playEffect(res.catchBombEffect, false);
break;
default:
this.score_ += 1;
cc.audioEngine.playEffect(res.catchFruitEffect, false);
Expand All @@ -216,6 +228,33 @@ var MainSceneLayer = cc.Layer.extend({
this.scoreLabel_.setString(cc.formatStr("%d", this.score_));
},

onCatchBomb: function() {
// クラッシュ状態にする
this.isCrash_ = true;

// アニメーションの作成
var frames = [];
var playerSize = this.player_.getContentSize();
var animationFrameCount = 3; // アニメーションのフレーム数
// アニメ用のフレームを読み込む
for(i=0; i<animationFrameCount; ++i) {
var rect = cc.rect(playerSize.width * i, 0, playerSize.width, playerSize.height);
var frame = new cc.SpriteFrame(res.playerCrash, rect);
frames.push(frame);
}

// アニメーションを作成する
var animation = new cc.Animation(frames, 10.0 / 60.0);
animation.setLoops(3); // 3回繰り返して再生する
animation.setRestoreOriginalFrame(true);
this.player_.runAction(cc.sequence(cc.animate(animation),
cc.callFunc(function() {
this.isCrash_ = false;
}, this)));
this.score_ = Math.max(0, this.score_ - MainSceneLayer.BOMB_PENALTY_SCORE); // 4点引いて0点未満になったら0点にする
cc.audioEngine.playEffect(res.crashEffect);
},

onResult: function() {
this.state_ = MainSceneLayer.GameState["RESULT"];
var winSize = cc.director.getWinSize();
Expand Down Expand Up @@ -252,10 +291,13 @@ MainSceneLayer.FruitType = [
"ORANGE",
"BANANA",
"CHERRY",
"GOLDEN"
"GOLDEN",
"BOMB"
];
// 黄金のフルーツを取ったときの点数
MainSceneLayer.GOLDEN_FRUIT_SCORE = 5;
/// 爆弾を取ったときのマイナス点
MainSceneLayer.BOMB_PENALTY_SCORE = 4;
// フルーツの画面上端からのマージン(px)
MainSceneLayer.FRUIT_TOP_MARGIN = 40;
// フルーツの出現率
Expand Down
6 changes: 5 additions & 1 deletion src/resource.js
@@ -1,13 +1,15 @@
var res = {
background: "res/images/background.png",
player: "res/images/player.png",
playerCrash: "res/images/player_crash.png",
fruits: [
"res/images/fruit0.png",
"res/images/fruit1.png",
"res/images/fruit2.png",
"res/images/fruit3.png",
"res/images/fruit4.png",
"res/images/fruit5.png"
"res/images/fruit5.png",
"res/images/fruit6.png"
],
replayButton: "res/images/replay_button.png",
replayButtonPressed: "res/images/replay_button_pressed.png",
Expand All @@ -16,6 +18,8 @@ var res = {
mainMusic: "res/bgm/main.mp3",
catchFruitEffect: "res/se/catch_fruit.mp3",
catchGoldenEffect: "res/se/catch_golden.mp3",
catchBombEffect: "res/se/catch_bomb.mp3",
crashEffect: "res/se/crash.mp3",
decideEffect: "res/se/decide.mp3"
};

Expand Down

0 comments on commit c49cea7

Please sign in to comment.