从零开始的泡泡龙游戏
-
来玩泡泡龙
花了一小时,做了准备工作
发射泡泡
按下屏幕可以发射泡泡,泡泡碰撞后,粘在上面
泡泡粘贴的位置
根据角度计算
var radian = Math.atan2(pointB.y - pointA.y, pointB.x - pointA.x ) var angle = 180 / Math.PI * radian console.log("angle=", angle) if(angle>=45 && angle<=90){ //右下角 } else if(angle>90 && angle<=135){ //左下角 } else if(angle<45 && angle>=-45){ //右 } else if(angle<-45 && angle >= -90){ //右上角 } else if(angle<-90 && angle >= -135){ //左上角 } else{ //左 }
消除计算
每个发射球周围有六个球,依次计算他们是否跟发射球颜色相同,如果相同,再次递归,直到找不到相同颜色球
function checkSameTypeSize(newI, newJ, tempType){ console.log("checkSameTypeSize ", newI, newJ, tempType) var hasSize = 0 var flag = newI%2 var len = flag==0?9:10 var otherLen = flag==1?9:10 var tempPoint = new Array //左侧泡泡 if(newJ-1>=0){ if(level.arrays[newI][newJ-1] == tempType){ tempPoint.push(Qt.point(newI, newJ-1)) } } //右侧泡泡 if(newJ+1<=len-1){ if(level.arrays[newI][newJ+1] == tempType){ tempPoint.push(Qt.point(newI, newJ+1)) } } //上侧 if(newI-1>=0){ if(flag==0){ //上层是偶数行 if(newJ>=0){ //上左侧泡泡 //上左侧 存在 if(level.arrays[newI-1][newJ] == tempType){ tempPoint.push(Qt.point(newI-1, newJ)) } } //上右侧泡泡 if(newJ+1<=otherLen-1){ //存在 if(level.arrays[newI-1][newJ+1] == tempType){ tempPoint.push(Qt.point(newI-1, newJ+1)) } } } else{ //上层是奇数行 if(newJ-1>=0){ //上左侧泡泡 //上左侧 存在 if(level.arrays[newI-1][newJ-1] == tempType){ tempPoint.push(Qt.point(newI-1, newJ-1)) } } //上右侧泡泡 if(newJ<=otherLen-1){ //存在 if(level.arrays[newI-1][newJ] == tempType){ tempPoint.push(Qt.point(newI-1, newJ)) } } } } //下侧 if(newI+1<level.arrays){ if(flag==0){ //下层是偶数行 if(newJ>=0){ //下左侧泡泡 //下左侧 存在 if(level.arrays[newI+1][newJ] == tempType){ tempPoint.push(Qt.point(newI+1, newJ)) } } //下右侧泡泡 if(newJ+1<=otherLen-1){ //存在 if(level.arrays[newI+1][newJ+1] == tempType){ tempPoint.push(Qt.point(newI+1, newJ+1)) } } } else{ //下层是奇数行 if(newJ-1>=0){ //下左侧泡泡 //下左侧 存在 if(level.arrays[newI+1][newJ-1] == tempType){ tempPoint.push(Qt.point(newI+1, newJ-1)) } } //上右侧泡泡 if(newJ<=otherLen-1){ //存在 if(level.arrays[newI+1][newJ] == tempType){ tempPoint.push(Qt.point(newI+1, newJ)) } } } } var tempArrayFunc = new Array for(var p=0 in tempPoint){ var pp = tempPoint[p] if(tempArray[pp.x][pp.y]==1){ //已经采集过这个点 } else{ tempArray[pp.x][pp.y] = 1 tempArrayCaiji++ tempArrayFunc.push(Qt.point(pp.x, pp.y)) } } //递归采集 for(var p=0 in tempArrayFunc){ var pp = tempArrayFunc[p] console.log("============pp", pp) checkSameTypeSize(pp.x, pp.y, tempType) } }
粘贴位置优化
六个方向每个角度为60
边界碰撞优化
碰撞边界后不超出边界,强制设置x,y坐标
function checkScreen(x, y){ var w = Screen.width var h = Screen.height var radian = Math.PI/180 * moveAngle var point = Qt.point(x,y) if(x<=2/* && moveAngle<-90*/){ moveAngle = -(180+moveAngle) point.x = 2 point.y = (fireBall.x-2)*Math.tan(radian) + fireBall.y } else if(x+ballRadius*2+2>=w /*&& moveAngle>-90*/){ moveAngle = 180-moveAngle point.x = w-ballRadius*2-2 point.y = (w-fireBall.x-ballRadius*2-2)*Math.tan(radian) + fireBall.y } return point }
球与球碰撞优化
碰撞前不移动发射球,检测到预碰撞后,下次坐标直接设置为正确的点位置
分数
//计分 score += ballScore
泡泡破碎
破碎优化
菜单与关卡
未完待续
-
这种游戏难吗
难在哪里
-
@大黄老鼠 第一次做,难在计算消除的算法
-
也是哦,消除算法第一眼可能看不出来怎么做的。还是有些难度的。:face_with_stuck-out_tongue_closed_eyes: :face_with_stuck-out_tongue_closed_eyes:
-
程序设计来说,算法还是挺重要的,然后呢,一些精美的图片,也会带来很棒的视觉效果。我喜欢这样的游戏。
-
再来一个顶!支持一波