// Learn cc.Class: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html // Learn Attribute: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { // foo: { // // ATTRIBUTES: // default: null, // The default value will be used only when the component attaching // // to a node for the first time // type: cc.SpriteFrame, // optional, default is typeof default // serializable: true, // optional, default is true // }, // bar: { // get () { // return this._bar; // }, // set (value) { // this._bar = value; // } // }, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start() { cc.log("数据是啥",RootNode); this.NewsSprite = UtilsPrefabs.getNode("NewsSprite", this.node); this.NewsSprite.active = false; // this.captureScreenshot(); let bgmove = UtilsPrefabs.getNode("bgmove", this.node); let nodeMove = this.nodeMove = UtilsPrefabs.getNode("move", bgmove); let slider = this.sliderNode = UtilsPrefabs.getNode("slider", this.node); let Skeleton = this.spine = UtilsPrefabs.getNode("spine", this.node); let strikeNode = this.strikeNode = UtilsPrefabs.getNode("strikeNode", this.node); let dragon = this.dragon = UtilsPrefabs.getNode("dragon", this.node); let FallingStar = this.FallingStar = UtilsPrefabs.getNode("FallingStar", dragon); let earth = this.earth = UtilsPrefabs.getNode("earth", this.node); let fast = this.fast = UtilsPrefabs.getNode("fast", earth); let esurient = this.esurient = UtilsPrefabs.getNode("esurient", this.node); //游戏界面 打击次数 路程 等 let gamelayout = this.gamelayout = UtilsPrefabs.getNode("gamelayout", this.node); this.star = UtilsPrefabs.getNode("star", this.node); let starlist = this.starlist = this.node.getChildByName("starlist"); let FlyPastStarNameTip = this.FlyPastStarNameTip = starlist.getChildByName("FlyPastStarNameTip"); let FlyTipName = this.FlyTipName = FlyPastStarNameTip.getChildByName("FlyTipName"); this.FlyPastStarName = FlyTipName.getChildByName("FlyPastStarName"); this.FlyTipName.active = false; this.LastTag = -1; this.StarNames = [ "月球", "火星", "木星", "土星", "天王星", "海王星", "黑洞"] this.speedP = [ 12, 6, 3 ] this._init(); utils.isMobile(function () { Manager.main = this; esurient.active = true; Manager.sceneType = 1; }.bind(this)); GameData.gameStartTime = new Date().getTime() this.strikeNode.getComponent("strike").setOnRestClick(function () { this.myinit(); }.bind(this)); Global.gameover = false; let earthdragon = this.earthdragon = UtilsPrefabs.getNode("earthdragon", earth); let Animations = this.Animations= utils.dragonBonesGet(earthdragon); this.myAnimationsstart = []; //地球启动 this.myAnimationsstart.push(Animations[0]); this.myAnimationsstart.push(Animations[3]); this.myAnimationsstart.push(Animations[6]); this.myAnimations = []; //飞行 this.myAnimations.push(Animations[1]); this.myAnimations.push(Animations[4]); this.myAnimations.push(Animations[7]); this.myAnimationsend = []; //地球停止 this.myAnimationsend.push(Animations[2]); this.myAnimationsend.push(Animations[5]); this.myAnimationsend.push(Animations[8]); //地球 默认播放 // utils.dragonBonesPlay(earthdragon, Animations[1], 0); utils.dragonBonesPlay(earthdragon, "01", 0); //默认 龙骨背景 停止 this.myinit(); // console.log("都是啥", this.myAnimations); //初始化 停下来 路过的 星球 this.initStar(); }, initStar: function () { // 星星 当前索引 this.currtag = 0; this.stars = []; let starlist = UtilsPrefabs.getNode("starlist", this.node); this.stars.push(UtilsPrefabs.getNode("s1", starlist));//月亮 this.stars.push(UtilsPrefabs.getNode("s2", starlist));//火星 this.stars.push(UtilsPrefabs.getNode("s3", starlist));//木星 this.stars.push(UtilsPrefabs.getNode("s4", starlist));//土星 this.stars.push(UtilsPrefabs.getNode("s5", starlist));//天王星 this.stars.push(UtilsPrefabs.getNode("s6", starlist));//海王星 this.stars.push(UtilsPrefabs.getNode("s7", starlist));//黑洞 this.stars.push(UtilsPrefabs.getNode("s8", starlist));//多余的 this.starsaname = []; this.starsaname.push("smove1"); this.starsaname.push("smove2"); this.starsaname.push("smove3"); this.starsaname.push("smove4"); this.starsaname.push("smove5"); this.starsaname.push("smove6"); this.starsaname.push("smove7"); this.starsaname.push("smove8"); }, checkKmForStar : function(km){ if (km > 0.1&& km<=0.2) { this.currtag = 0; } else if (km > 0.2&& km<=0.3) { this.currtag = 1; } else if (km > 0.3&& km<=0.4) { this.currtag = 2; } else if (km > 0.4&& km<=0.5) { this.currtag = 3; } else if (km > 0.5&& km<=0.6) { this.currtag = 4; } else if (km > 0.6&& km<=0.7) { this.currtag = 5; } else if (km > 0.7&& km<=0.8) { this.currtag = 6; } else if (km > 0.8&& km<=0.9) { this.currtag = 7; } else if (km > 0.9&& km<1) { // 穿越 太阳系 this.currtag = 99; }else if (km>=1){ //银河系 this.currtag = 100; } }, checkScoreForStar : function(Score){ if (Score >= 0 && Score <= 210000) { //月球 this.currtag = 0; } else if (Score > 210000 && Score <= 420222) { //火星 this.currtag = 1; } else if (Score > 420222 && Score <= 630333) { //木星 this.currtag = 2; } else if (Score > 630333 && Score <= 672355) { //土星 this.currtag = 3; } else if (Score > 672355 && Score <= 714377) { //天王星 this.currtag = 4; } else if (Score > 714377 && Score <= 756400) { //海王星 this.currtag = 5; } else if (Score > 756400 && Score <= 798422) { //黑洞 this.currtag = 6; } else if (Score > 798422 && Score <= 1199999) { //太阳系 this.currtag = 99; } else if (Score > 1199999) { //银河系 this.currtag = 100; } }, myinit: function () { this.dragon.getComponent("dragonManager").setTimeScale(0.05); this.FallingStar.active = false; // this.setFastAnim(0); // this.sliderNode.getComponent(cc.Slider).progress = 0; }, _init: function () { // this.myinit(); // console.log("进度条", this.sliderNode.getComponent(cc.Slider)); this.nodeMoveAnimation = this.nodeMove.getComponent(cc.Animation); this.Skeleton = this.spine.getComponent(sp.Skeleton); // console.log("当前的动画组件",this.nodeMoveAnimation); this.slider = this.sliderNode.getComponent(cc.Slider); this.moveState = this.nodeMoveAnimation.getAnimationState('move'); this.moveState.speed = this.slider.progress; this.setStartTimeScale(0); // console.log("滑动条组件",this.slider); this.slider.node.on('slide', this.callbackslide, this); //每次打击 的回调 this.strikeNode.getComponent("strike").setOnPowerCallBackforMain(function (speed, p) { // this.moveState.speed =1+speed*1.5; // this.Skeleton.timeScale =1+speed*1.5; // console.log("每次打得", speed, p); //设置地球 的动画 this.setFastAnim(p); this.p = p; // this.fast this.gamelayout.getComponent("gamelayoutManager").setPowcount(function () { console.log("打完了"); utils.getShareData(function (data) { UserInfo.args = data; // console.log("游戏产生数据" + UserInfo.args); console.log("游戏成绩" + JSON.stringify(UserInfo.args.setResult)); // // console.log("游戏数据是" + UserInfo.PlayerGameData); // console.log("游戏数据是 json" + JSON.stringify(UserInfo)); // console.log("游戏数据是 args" + JSON.stringify(UserInfo.args)); // console.log("假装 获得到的排行榜数据 json" + JSON.stringify(RankingListData)); utils.isMobile(function () { Manager.chengji(); //真的数据来了 就注释此行 // this.showRankingList(); }.bind(this)); }.bind(this)); }.bind(this)); this.ChangeCallBack(speed); // console.log("回调的 速度",speed); }.bind(this)); }, setStartTimeScale: function (speed) { this.star.getComponent(cc.Animation).getAnimationState("starta").speed = speed; }, getStartTimeScale: function () { return this.star.getComponent(cc.Animation).getAnimationState("starta").speed; }, ChangeCallBack: function (CurrentMoney) { // cc.log("********CurrentMoney*****"+CurrentMoney); //money:进度条的百分比 this.CurrentMoney = CurrentMoney; let LastMoney = this.LastMoney = this.gamelayout.getComponent("gamelayoutManager").getFlyKM(); let Diff = this.Diff = CurrentMoney - LastMoney; let InitMoneyNum = this.InitMoneyNum = LastMoney; let AnimTimes = this.AnimTimes = 0; let Times = this.Times = 200; let GrowUp = this.GrowUp = 1; //b初始值,c变化量,d持续时间 t 正数 增 负数 减 this.b = this.LastMoney, this.c = this.Diff, this.d = this.Times, this.dt = this.Times / 2, this.t = 0; console.log("相差", CurrentMoney, LastMoney); this.unschedule(this.timeschedule); if (this.time1 != null) { clearTimeout(this.time1) } if (this.time2 != null) { clearTimeout(this.time2) } this.schedule(this.timeschedule, 0.01, Times); cc.log(Times); // this.schedule(function () { // var ss = Tween.Expo.easeOut(this.t, b, c, d); // console.log("我们那个", ss); // this.t++; // }.bind(this), 0.01, d); }, timeschedule: function () { // cc.log("*********cstest1111111111**********"); // if (this.AnimTimes>=0 && this.AnimTimes<30) { // this.GrowUp = 0.5; // }else if (this.AnimTimes>=30 && this.AnimTimes<50) { // this.GrowUp = 2; // }else{ // this.GrowUp = 0.6; // } // console.log("我们那个", this.t, this.b, this.c, this.d); var ss = Tween.Expo.easeOut(this.t, this.b, this.c, this.d); var speed = Tween.Expo.easeOut(this.t, 0, this.c, this.dt); // if (this.Diff > 0) { // this.InitMoneyNum += parseFloat((this.CurrentMoney - this.LastMoney) / this.Times * this.GrowUp); // } else { // this.InitMoneyNum -= parseFloat((this.CurrentMoney - this.LastMoney) / this.Times * this.GrowUp); // } // let result = this.InitMoneyNum; // console.log("我们那个 ss", ss); let speedt = speed * this.speedP[this.p]; if (this.t == this.Times) { // cc.log("*********cstest222222222**********"); // console.log("停下来了CurrentMoney"+ this.CurrentMoney); // this.setStarTimeScale(0); // Global.gameover // this.checkKmForStar(ss); //测试数据 月亮 210000 火星 420222 木星 630333 土星 672355 天王星 714377 海王星 756400 黑洞 798422 太阳系 1199999 银河系 1200000 // this.checkScoreForStar(210000); this.checkScoreForStar(UserInfo.PlayerGameData.power); // console.log("流浪地球 checkScoreForStar ,,,power is "+UserInfo.PlayerGameData.power); // console.log("停下来了currtag"+ this.currtag); if (this.currtag == 99 || this.currtag == 100) { // cc.log("*********cstest44444444444444**********"); if (!Global.gameover) { this.endSpeed99_100(); return; } this.time1 = setTimeout(function () { // cc.log("*********cstest5555555555555**********"); if (Global.gameover) { // cc.log("*********cstest666666666666666**********"); this.maingameover(); // if (this.CurrentMoney == 1) { // // 穿越 银河系 // this.perfectEnding(); // } else { // //穿越 太阳系 // this.perfecttaiyang(); // } if (this.currtag == 100) { // 穿越 银河系 this.perfectEnding(); } else { //穿越 太阳系 this.perfecttaiyang(); } } }.bind(this),2000); }else{ this.endSpeed(); } // console.log("快结束 停了", ss,"多少呢",this.currtag); return; } else if (this.t < 150) { speedt*=4; }else if (this.t >= 150) { speedt*=2; } // console.log("现在是设置多少呢", speedt); this.dragon.getComponent("dragonManager").setTimeScale(1+speedt); //地球飞行的时候才播放流星asd if(this.FallingStar.active == false){ this.FallingStar.active = true; } if (this.stars[this.currtag]!=null) { if (this.stars[this.currtag].active) { // this.setStarTimeScale(speedt); this.setStarTimeScale(1); // console.log("******什么情况2222222*****"); if(this.LastTag != this.currtag){ this.LastTag = this.currtag; let anim = this.FlyTipName.getComponent(cc.Animation); anim.play('FlyPastStarNameTip2'); } } } this.gamelayout.getComponent("gamelayoutManager").setFlyKM(ss); // console.log("速度",speed); // this.setStartTimeScale(speedt); // this.AnimTimes++; // console.log("变化",ss); this.t++; }, endSpeed : function () { // cc.log("*********cstest777777777777777**********"); this.gamelayout.getComponent("gamelayoutManager").setFlyKM(this.CurrentMoney); utils.dragonBonesPlay(this.earthdragon, this.checkAnimationsend(this.p), 0); // this.inching(CurrentMoney); this.dragon.getComponent("dragonManager").setTimeScale(1); // this.setStartTimeScale(0); utils.dragonBonesPlay(this.earthdragon, this.myAnimationsend[this.p], 1); setTimeout(function () { // cc.log("*********cstest33333333333**********"); // utils.dragonBonesPlay(this.earthdragon, this.Animations[1], 0); utils.dragonBonesPlay(this.earthdragon, "01", 0); }.bind(this),200); this.stars[this.currtag].active = true; if (this.stars[this.currtag].active) { // cc.log("*********cstest8888888888888**********"); // this.setStarTimeScale(speedt); this.time1 = setTimeout(function () { // cc.log("*********cstest9999999999999**********"); // console.log("进来吗",this.currtag); this.setStarTimeScale(0); // console.log("******什么情况*****"); this.dragon.getComponent("dragonManager").setTimeScale(0.05); this.FallingStar.active=false; this.time2 = setTimeout(function () { // cc.log("*********cstestaaaaaaaaaaaaaa**********"); if (Global.gameover) { // cc.log("*********cstestbbbbbbbbbbbbb**********"); this.maingameover(); Global.layoutManager.setGameOver(); } }.bind(this),2000); // console.log("******星球停下来了*****"); if(this.currtag>=0 && this.currtag<=6 && this.currtag!=this.LastTag){ // cc.log("*********cstestcccccccccccccccc**********"); // console.log("流浪地球 飞过什么星球"+this.StarNames[this.currtag]); this.FlyPastStarName.getComponent(cc.Label).string = this.StarNames[this.currtag]; this.FlyTipName.active = true; this.FlyTipName.opacity = 255; let anim = this.FlyTipName.getComponent(cc.Animation); anim.play('FlyPastStarNameTip'); } }.bind(this),860);//这个数值越大,球越往后 } }, endSpeed99_100 : function () { // cc.log("*********cstest777777777777777**********"); this.gamelayout.getComponent("gamelayoutManager").setFlyKM(this.CurrentMoney); utils.dragonBonesPlay(this.earthdragon, this.checkAnimationsend(this.p), 0); // this.inching(CurrentMoney); this.dragon.getComponent("dragonManager").setTimeScale(1); // this.setStartTimeScale(0); utils.dragonBonesPlay(this.earthdragon, this.myAnimationsend[this.p], 1); setTimeout(function () { // cc.log("*********cstest33333333333**********"); // utils.dragonBonesPlay(this.earthdragon, this.Animations[1], 0); utils.dragonBonesPlay(this.earthdragon, "01", 0); }.bind(this),200); }, maingameover : function(){ this.p = 0; Global.gameover = false; // for (var i = 0; i < this.stars.length; i++) { // this.stars[i].active = false; // } UtilsPrefabs.getNode("liuxing", this.node).active = false; // console.log("飞过什么星球了",this.currtag); UserInfo.PlayerGameData.currtag = this.currtag; utils.getShareData(function (data) { }.bind(this)); }, setStarTimeScale : function(speedt){ // console.log("判断1",this.stars[this.currtag]); if (this.stars[this.currtag] != null) { if (this.stars[this.currtag].getComponent(cc.Animation).getAnimationState(this.starsaname[0]) != null) { this.stars[this.currtag].getComponent(cc.Animation).getAnimationState(this.starsaname[0]).speed = speedt; } } }, inching: function (CurrentMoney) { let LastMoney = this.gamelayout.getComponent("gamelayoutManager").getFlyKM(); let Diff = CurrentMoney - LastMoney; let InitMoneyNum = LastMoney; let AnimTimes = 0; let Times = 100; this.schedule(function () { if (Diff > 0) { InitMoneyNum += parseFloat((CurrentMoney - LastMoney) / Times); } else { InitMoneyNum -= parseFloat((CurrentMoney - LastMoney) / Times); } let result = InitMoneyNum; if (AnimTimes == Times - 1) { this.gamelayout.getComponent("gamelayoutManager").setFlyKM(CurrentMoney); this.inching(); return; } this.gamelayout.getComponent("gamelayoutManager").setFlyKM(result); AnimTimes++; }, 0.01, Times); }, setFastAnim: function (type) { // console.log("改变动画名字", this.fast); let Animation = this.fast.getComponent(cc.Animation); Animation.play(Animation.getClips()[type].name); // console.log("改变动画名字fast", this.myAnimations); utils.dragonBonesPlay(this.earthdragon, this.myAnimations[type], 0); utils.dragonBonesPlay(this.earthdragon, this.myAnimationsstart[type], 1); setTimeout(function () { utils.dragonBonesPlay(this.earthdragon, this.myAnimations[type], 0); }.bind(this),200); }, callbackslide: function (slider) { // console.log("滑动条组件回调",slider); // this.moveState.speed =slider.progress; // this.Skeleton.timeScale =slider.progress; this.dragon.getComponent("dragonManager").setTimeScale(1 + slider.progress * 1.5); }, //完美结局 perfectEnding: function () { // UtilsPrefabs.getNode("score", this.node).active = false; let gamelayout = UtilsPrefabs.getNode("gamelayout", this.node); let progressBar = UtilsPrefabs.getNode("progressBar", gamelayout); let powcountlayout = UtilsPrefabs.getNode("powcountlayout", gamelayout); progressBar.active = false; powcountlayout.active = false; let perfectEnding = UtilsPrefabs.getNode("perfectEnding", this.node); perfectEnding.active = true; let performermove = UtilsPrefabs.getNode("performermove", this.node); performermove.active = true; let performer = UtilsPrefabs.getNode("performer", performermove); // performer.active = true; this.fast.active = false; this.earthdragon.active = false; let bg = UtilsPrefabs.getNode("bg", this.node); bg.active = false; let bgb = UtilsPrefabs.getNode("bgb", this.node); bgb.active = true; this.dragon.active = false; setTimeout(function () { perfectEnding.active = false; performermove.active = false; let yinhexi = UtilsPrefabs.getNode("yinhexi", this.node); yinhexi.active = true; let performeryinhexi = UtilsPrefabs.getNode("performeryinhexi", this.node); performeryinhexi.active = true; bg.active = true; bgb.active = false; setTimeout(function () { Global.layoutManager.setGameOver(); }.bind(this), 4000);//这个数字是银河系动画的时间 }.bind(this), 2000);//这个数字是黑洞动画的时间 }, //穿越太阳系 perfecttaiyang: function () { // UtilsPrefabs.getNode("score", this.node).active = false; let gamelayout = UtilsPrefabs.getNode("gamelayout", this.node); let progressBar = UtilsPrefabs.getNode("progressBar", gamelayout); let powcountlayout = UtilsPrefabs.getNode("powcountlayout", gamelayout); progressBar.active = false; powcountlayout.active = false; let perfectEnding = UtilsPrefabs.getNode("perfectEnding", this.node); perfectEnding.active = true; let performermove = UtilsPrefabs.getNode("performermove", this.node); performermove.active = true; let performer = UtilsPrefabs.getNode("performer", performermove); // performer.active = true; this.fast.active = false; this.earthdragon.active = false; let bg = UtilsPrefabs.getNode("bg", this.node); bg.active = false; let bgb = UtilsPrefabs.getNode("bgb", this.node); bgb.active = true; this.dragon.active = false; setTimeout(function () { perfectEnding.active = false; performermove.active = false; let taiyangxi = UtilsPrefabs.getNode("taiyangxi", this.node); taiyangxi.active = true; let performer1 = UtilsPrefabs.getNode("performer1", this.node); performer1.active = true; bg.active = true; bgb.active = false; setTimeout(function () { Global.layoutManager.setGameOver(); }.bind(this), 4000);//这个数字是太阳系动画的时间 }.bind(this), 2000);//这个数字是黑洞动画的时间 }, checkAnimationsend: function (type) { return this.myAnimationsend[type]; } // update (dt) {}, });