您的位置:首页 > 其它

三消游戏(二)

2016-07-19 18:52 232 查看
做好了三消消除掉落之后,并且消除之后保存在数组之中

rrayIndexArr = this.filterDelSame(specilArr,arrayIndexArr)
if(cell) cell.setToSpecial()
//清除同颜色的块儿  并且二维数组中的位置置为null
for(var index in arrayIndexArr){
var arrayIndex = arrayIndexArr[index]

var moveBy = cc.moveTo(1,cc.p(cc.winSize.width*(1+Math.random()*2), cc.winSize.height*(1+Math.random()*2)));
//var moveBy = cc.moveBy(3, cc.pRotate(cc.p(500, 0), cc.pNormalize(Math.random()-0.5, Math.random()-0.5)));
this.cellArr[arrayIndex.x][arrayIndex.y].runAction(cc.sequence(moveBy, cc.callFunc(this.removeBullet, this)));

cc.eventManager.dispatchCustomEvent(GameEvent.GAME_MAEK);
//this.cellArr[arrayIndex.x][arrayIndex.y].removeFromParent(true)// 消除三个相同色块
this.cellArr[arrayIndex.x][arrayIndex.y] = null      //把移除的位置置为null
}


然后掉落的方块儿掉落,消除之后一直往上递增,并且也更新下标

//消除之后一直往上遍历
for(var i = 0;i < GameData.W_NUM;i++){
for(var j = GameData.H_NUM - 1;j >= 0;j--){
if(this.cellArr[i][j] == null){
continue
}
//记录有多少个空的块
var tempAdd = 0
for(var k = j;k < GameData.H_NUM;k++){
if(this.cellArr[i][k] == null)  tempAdd++  //每有一个空块就加1
}
this.cellArr[i][j].fallDownNum = tempAdd
}
}
//检测最后一行,有空的就往下掉落
for(var i = 0;i < GameData.W_NUM;i++){
for(var j = GameData.H_NUM - 1;j >= 0;j--){
this.updateCellFallDownNum(this.cellArr[i][j])
}
}
//--------补缺
this.scheduleOnce(this.fillEmpty.bind(this),0.51)
},


方块掉落方法:

fallDown : function(){
this.arrayIndex.y += this.fallDownNum
this.runAction(cc.moveBy(0.5,cc.p(0,-60*this.fallDownNum)))
this.updateIndex();
},


往下掉落了之后,还要更新方块,最上面掉落

//更新 新的块
fillEmpty : function(){
for(var i = 0;i<GameData.W_NUM;i++){
for(var j = 0;j < GameData.H_NUM;j++){
if(this.cellArr[i][j] == null){
var cell = new Cell()
cell.setArrIndex(i,j)    //设置下标
cell.setPosition(100 + i*60,cc.winSize.height - 240 - j*60)
this.addChild(cell)
this.cellArr[i][j] = cell
}
}
}
var end = this.check3Same()
if(end.length == 0){
cc.log('进入稳定状态  停止')
this.toucher = false
this.endCheck = new CheckEnd()  //检查死循环
this.endCheck.setCellArr(this.cellArr)
}else {
this.scheduleOnce(function(){
this.cellFallDown(end)
},0.51)
}
},


setArrIndex是我们写的把传来的下标显示在图片的右下角

setArrIndex:function(i,j){
this.arrayIndex = cc.p(i, j)
var lable = new cc.LabelTTF(i+","+j,'',10)
lable.enableStroke(cc.color(0,0,0,255),1)
lable.setPosition(10,10)
this.addChild(lable)
this.indexlable = lable
},
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: