- 增加难度条件,实现积分达到条件后进入新关卡的逻辑
onLoop():void{
//检测碰撞
for(var i:number = this.roleBox.numChildren-1;i>-1;i--){
//获取角色对象1
var role1:Role = this.roleBox.getChildAt(i) as Role;
if(role1.hp<1)continue;
for(var j:number = i-1;j>-1;j--){
//如果角色已经死亡,则忽略
if(!role1.visible)continue;
//获取角色对象2
var role2:Role = this.roleBox.getChildAt(j) as Role;
//如果角色未死亡,并且阵营不同才能进行碰撞
if(role2.hp>0 && role1.camp != role2.camp){
//计算碰撞区域
var hitRadius:number = role1.hitRadius + role2.hitRadius;
//根据距离判断是否碰撞
if(Math.abs(role1.x - role2.x) < hitRadius && Math.abs(role1.y - role2.y) < hitRadius){
//碰撞之后掉血
this.lostHp(role1,1);
this.lostHp(role2,1);
//每掉一滴血,积分+1
this.score ++;
//在UI上显示积分
this.gameInfo.score(this.score);
//积分大于升级积分,则升级
if(this.score > this.levelUpScore){
//升级关卡
this.level ++;
//在UI上显示等级
this.gameInfo.level(this.level);
//提高下一级的升级难度
this.levelUpScore+=this.level * 5;
}
}
}
}
}
}
- 关卡难度提升后,实现敌方血量,数量,速度提升的逻辑
//关卡越高,创建敌机间隔越短
var cutTime:number = this.level < 30 ? this.level * 2 : 60;
//关卡越高,敌机飞行速度越快
var speedUp:number = Math.floor(this.level / 6);
//关卡越高,敌机血量越高
var hpUp:number = Math.floor(this.level / 8);
//关卡越高,敌机数量越多
var numUp:number = Math.floor(this.level / 10);
//生成小飞机
if(Laya.timer.currFrame % (80 - cutTime ) === 0){
this.createEnemy(0,2+numUp,3+speedUp,1);
}
//生成中型飞机
if(Laya.timer.currFrame % (150 - cutTime * 4) === 0){
this.createEnemy(1,1+numUp,2+speedUp,2+hpUp*2);
}
//生成boss
if(Laya.timer.currFrame % (900 - cutTime * 4) === 0){
this.createEnemy(2,1,1+speedUp,10+hpUp *6);
//播放boss出场声音
Laya.SoundManager.playSound("res/sound/enemy3_out.mp3");
}