从零开始的泡泡龙游戏

来玩泡泡龙

花了一小时,做了准备工作

0_1525269456973_QQ图片20180502215537.jpg

发射泡泡

按下屏幕可以发射泡泡,泡泡碰撞后,粘在上面

0_1525327635185_Screenshot_20180503-140700.jpg

泡泡粘贴的位置

0_1525334610207_QQ截图20180503160252.png

根据角度计算

0_1525335750992_QQ截图20180503161857.png

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

泡泡破碎

0_1525404206965_ball1.gif

破碎优化

0_1525411221012_ball3.gif

菜单与关卡

0_1525420516148_Screenshot_20180504-155437.jpg

0_1525420525652_Screenshot_20180504-155442.jpg

未完待续

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值