三消游戏(二)
2016-07-19 18:52
232 查看
做好了三消消除掉落之后,并且消除之后保存在数组之中
然后掉落的方块儿掉落,消除之后一直往上递增,并且也更新下标
方块掉落方法:
往下掉落了之后,还要更新方块,最上面掉落
setArrIndex是我们写的把传来的下标显示在图片的右下角
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 },
相关文章推荐
- Linux进程间通信——使用命名管道
- C#开发学习笔记:编写自定义Button控件的自定义事件
- 函数与指针
- 关于kali开机自动启动ssh服务的方法以及配置kalissh的一些基本操作
- 求Sn=a+a*a+a*a*a+a*a*a*a的和,其中a是一个数字。
- OSX Eclipse Neon无法添加Tomcat 8.5.3运行环境的解决办法
- Java远程访问SQL Server 2008R2数据库
- Linux进程间通信——使用消息队列
- Java集合知识点整理
- WPF中的简单打印
- "/**"快捷键生成注释的内容修改
- HTML 字符实体 < >: &等
- 有些东西不是你想了努力了就能有的
- Touch事件 移动端touch触摸事件
- beyond reality face 人脸检测
- Ant打包时遇到bin/res/crunch错误时解决方案
- BC,HDU 5719
- 输入函数input()和raw_input()的区别
- apache thrift
- 1.如何避免野指针2.获取字符串的两种方法。以及malloc,calloc,ralloc的使用注意点3.二维三维数组4.数组和函数的区别