Cocos2d-js06-添加分数和死亡判断

Cocos2d-js06-添加分数和死亡判断

1、添加分数,代码:

//添加分数 score = new cc.LabelTTF("分数:0", "Arial", 50);
score.setPosition(cc.p(winSize.width/2,winSize.height - 130));
this.addChild(score,4);

 

//添加分数 this.m_score += 100;
score.setString("分数:"+this.m_score);
 
2、死亡判断,代码:

//走出边界,游戏结束
if(this._head.now_col < 0 || this._head.now_row < 0 || this._head.now_col >= 10 || this._head.now_row >= 10){
    this.onGameOver();
}

//蛇头碰到蛇尾,游戏结束
if(SNAKE_BODY.length != 0){
    for(var i = SNAKE_BODY.length - 1; i >= 0; i--){
        if(this._head.now_col== SNAKE_BODY[i].now_col&& this._head.now_row== SNAKE_BODY[i].now_row){
            this.onGameOver();
        }
    }
}

 

3、onGameOver方法:

onGameOver:function(){
    director.pause();
    var gameOver= new cc.LabelTTF("GameOver!", "Arial", 50);
    var over = new cc.MenuItemLabel(gameOver,function(){
        window.location.href = "http://h5.9miao.com";
    });
    over.setPosition(cc.p(size.width/2,size.height/2));
    var menu = new cc.Menu(over);
    menu.x = 0;
    menu.y = 0;
    this.addChild(menu, 5);

},


视频地址:http://www.9miaoketang.com/course/37
课程讨论帖地址:http://www.9miao.com/thread-64587-1-1.html
源码地址:https://store.cocos.com/stuff/show/128289.html
QQ交流群:83459374
后期也会把该源码传在群里面去,欢迎大家加入讨论!

 

你可能感兴趣的:(html5,cocos2d,H5,cocos2d-x,cocos2d-js)