123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- cc.Class({
- extends: cc.Component,
- // properties: {
- //
- // },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.totalNum = 2000; //boss的血量
- this.myBlood = 2000; //玩家的血量
- },
- start () {
- //获取boss的进度条bar
- this.bossBarNode = cc.find("Canvas/BloodProgress/bar").getComponent(cc.Sprite);
- //获取EffectLayer组件
- this.effNum = cc.find("Canvas/GameScene/EffectLayer").getComponent("EffectLayer");
- //获取currentNums的Label的值
- this.currentNum = this.effNum.currentNums.getComponent(cc.Label).string;
- //获取已使用的总步数
- this.stepSurplus = this.effNum.stepTotal;
- //获取关卡数据
- this.levelNum = this.effNum.curLevelNum;
- //获取boss图片
- this.bossImg = cc.find("Canvas/BloodProgress/boss");
- //获取攻击武器的节点
- this.bossAttackNode = cc.find("Canvas/BloodProgress/bossAttackEffect")
- //获取玩家的血量节点
- this.myBloodNode = cc.find("Canvas/BloodProgress/myBar").getComponent(cc.Sprite);
- },
- // update (dt) {
- // // console.log("this.bossBarNode.fillRange:",this.bossBarNode.fillRange)
- // // console.log("this.myBloodNode.fillRange:",this.myBloodNode.fillRange)
- // },
- //boss受到攻击
- bossProgress(){
- //boss进度条的血量
- let per = (this.currentNum / this.totalNum).toFixed(2);
- per = (per > 1) ? 1 : per;
- this.progressBarFillRange = 1 - per; // 1 - per 表示倒计时
- // console.log("this.progressBarFillRange:",this.progressBarFillRange)
- //更新进度条的值
- this.bossBarNode.fillRange = this.progressBarFillRange;
- //boss被攻击后的动画效果
- let rotateRight = cc.rotateBy(0.06, 30);
- let rotateLeft = cc.rotateBy(0.12, -60);
- let sequence = cc.sequence(rotateRight, rotateLeft, rotateRight);
- this.bossImg.runAction(sequence);
- // console.log("完成一个动画");
- //判断是否闯关成功
- if (this.bossBarNode.fillRange == 0 && this.myBloodNode.fillRange > 0){
- // console.log("闯关成功")
- // console.log("this.levelNum2:",this.levelNum)
- //闯关成功,获取弹出层
- let resultMask = cc.find("Canvas/Result")
- //展示关卡
- resultMask.getChildByName("Title").getComponent(cc.Label).string = `第${this.levelNum}关完成`;
- //展示当前分数
- resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = this.currentNum;
- //展示金币
- resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 20;
- //展示星星
- resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 20;
- //显示弹出层
- resultMask.active = true;
- //通关后,关卡+1
- this.effNum.curLevelNum++;
- //如果关卡大于2,剩余步数设为28,否则为20
- // if (this.curLevelNum > 2){
- // this.surplusStepNums.string = 28;
- // }else {
- // this.surplusStepNums.string = 20;
- // }
- //重置
- this.bossBarNode.fillRange = 1; //通关后boss血条进度设为1
- this.myBloodNode.fillRange = 1; //通关后玩家血条进度设为1
- this.effNum.stepTotal = 0; //通关后步数清零
- this.effNum.currentNums.getComponent(cc.Label).string = 0; //通关后当前分数设为0
- this.stepSurplus = 0; //已消耗的步数设为0
- cc.find("Canvas/TopResult").active = false; //顶部区域不显示
- cc.find("Canvas/BloodProgress").active = false; //血条不显示
- }
- },
- //boss攻击玩家
- bossAttack(){
- //获取攻击武器的节点设置为显示状态
- this.bossAttackNode.active = true;
- //设置攻击武器的起始位置
- this.bossAttackNode.x = 70;
- //设置攻击武器移动向右移动
- let right = cc.moveTo(0.3,cc.v2(220,-70));
- //移动动作完成后的回调
- let finished = cc.callFunc(function (){
- // console.log("动作完成回调");
- //获取攻击武器的节点
- this.bossAttackNode = cc.find("Canvas/BloodProgress/bossAttackEffect")
- //获取攻击武器的节点设置为隐藏示状态
- this.bossAttackNode.active = false;
- //获取玩家血量的节点
- this.myBloodNode = cc.find("Canvas/BloodProgress/myBar").getComponent(cc.Sprite);
- //玩家的血量
- let per = (this.stepSurplus * 80 / this.myBlood).toFixed(2);
- per = (per > 1) ? 1 : per;
- this.myBloodNodeFillRange = 1 - per; // 1 - per 表示倒计时
- // console.log("this.myBloodNodeFillRange:",this.myBloodNodeFillRange)
- //更新进度条的值
- this.myBloodNode.fillRange = this.myBloodNodeFillRange;
- },this);
- //定义一个序列动画
- let sequence = cc.sequence(right,finished);
- this.bossAttackNode.runAction(sequence);
- //是否闯关失败的判断
- if (this.bossBarNode.fillRange > 0 && this.myBloodNode.fillRange <= (80 / this.myBlood)) {
- //闯关失败,获取弹出层
- let resultMask = cc.find("Canvas/Result")
- //展示关卡
- resultMask.getChildByName("Title").getComponent(cc.Label).string = "差一点点就成功了哦";
- //展示当前分数
- resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = this.currentNum;
- //展示金币
- resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 0;
- //展示星星
- resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 0;
- //显示弹出层
- resultMask.active = true;
- //闯关失败,不展示去动物园按钮
- let zoom = cc.find("Canvas/Result/BtnLayout/ToZoom")
- zoom.active = false;
- //如果关卡大于2,剩余步数设为28,否则为20
- // if (this.curLevelNum > 2){
- // this.surplusStepNums.string = 28;
- // }else {
- // this.surplusStepNums.string = 20;
- // }
- //重置
- this.bossBarNode.fillRange = 1; //boss血条进度设为1
- this.myBloodNode.fillRange = 1; //玩家血条进度设为1
- this.effNum.stepTotal = 0; //步数清零
- this.effNum.currentNums.getComponent(cc.Label).string = 0; //当前分数设为0
- this.stepSurplus = 0; //已消耗步数设为0
- cc.find("Canvas/TopResult").active = false; //顶部区域不显示
- cc.find("Canvas/BloodProgress").active = false; //血条不显示
- }
- // console.log("boss攻击了玩家");
- },
- });
|