Cocos2d-js06-添加分数和死亡判断
//添加分数 @H_502_13@score = @H_502_13@new cc.@H_502_13@LabelTTF(@H_502_13@"分数:0",@H_502_13@"Arial",50); @H_502_13@score.setPosition(@H_502_13@cc.p(@H_502_13@winSize.@H_502_13@width/2,@H_502_13@winSize.@H_502_13@height - 130)); @H_502_13@this.addChild(@H_502_13@score,4);
//添加分数 @H_502_13@this.@H_502_13@m_score += 100; @H_502_13@score.setString(@H_502_13@"分数:"+@H_502_13@this.@H_502_13@m_score);
2、死亡判断,代码:
//走出边界,游戏结束
@H_502_13@if(@H_502_13@this._head.@H_502_13@now_col < 0 || @H_502_13@this._head.@H_502_13@now_row < 0 || @H_502_13@this._head.@H_502_13@now_col >= 10 || @H_502_13@this._head.@H_502_13@now_row >= 10){
@H_502_13@this.onGameOver();
}
//蛇头碰到蛇尾,游戏结束
@H_502_13@if(@H_502_13@SNAKE_BODY.@H_502_13@length != 0){
@H_502_13@for(@H_502_13@var i = @H_502_13@SNAKE_BODY.@H_502_13@length - 1; i >= 0; i--){
@H_502_13@if(@H_502_13@this.@H_502_13@_head.@H_502_13@now_col== @H_502_13@SNAKE_BODY[i].@H_502_13@now_col&& @H_502_13@this.@H_502_13@_head.@H_502_13@now_row== @H_502_13@SNAKE_BODY[i].@H_502_13@now_row){
@H_502_13@this.onGameOver();
}
}
}
3、onGameOver方法:
onGameOver:@H_502_13@function(){
@H_502_13@director.pause();
@H_502_13@var gameOver= @H_502_13@new cc.@H_502_13@LabelTTF(@H_502_13@"GameOver!", 50);
@H_502_13@var over = @H_502_13@new cc.@H_502_13@MenuItemLabel(gameOver,@H_502_13@function(){
@H_502_13@window.@H_502_13@location.@H_502_13@href = @H_502_13@"http://h5.9miao.com";
});
over.setPosition(@H_502_13@cc.p(@H_502_13@size.@H_502_13@width/2,@H_502_13@size.@H_502_13@height/2));
@H_502_13@var menu = @H_502_13@new cc.@H_502_13@Menu(over);
menu.@H_502_13@x = 0;
menu.@H_502_13@y = 0;
@H_502_13@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 后期也会把该源码传在群里面去,欢迎大家加入讨论!