三消游戏(二)

做好了三消消除掉落之后,并且消除之后保存在数组之中

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
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值