// Learn cc.Class: // - https://docs.cocos.com/creator/manual/en/scripting/class.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { mycar_runnode: cc.Node, opposite_runnode: cc.Node, endpic: cc.Node, endcarnum: 0, mylist: [], opposite_list: [], pic_toast: cc.Node, reword_number:cc.Label, }, // LIFE-CYCLE CALLBACKS: onLoad() { this.node.on('click',this.startpk,this); }, startpk() { MyAudio.PlayEffect_pkbgm(); let opposite_level = Number(Storage.Get_storage(Storage.GameMessageType.pklevel)) + 1; this.endpic.active = false; this.node.active = false; this.my_list = this.GetRandomList(Global.MaxCarLevel); this.opposite_list = this.GetRandomList(opposite_level); this.MyCarAction( this.my_list); this.OppositeCarAction(this.opposite_list); Global.CocosAnalysticCustomEvent('PK','Start') }, OppositeCarAction(randomlist) { //初始位置 let placeAction = cc.place(470, 0); let actionMove_1_1 = cc.moveTo(randomlist[0]/2, cc.v2(470, -300)); let actionMove_1_2 = cc.moveTo(randomlist[1], cc.v2(-470, 300)); let actionMove_1_3 = cc.moveTo(randomlist[2]/2, cc.v2(470, 0)); let actionMove_2_1 = cc.moveTo(randomlist[5]/2, cc.v2(470, -300)); let actionMove_2_2 = cc.moveTo(randomlist[6], cc.v2(-470, 300)); let actionMove_2_3 = cc.moveTo(randomlist[7]/2, cc.v2(470, 0)); let finish1 = cc.callFunc(this.showendpic, this); let finish2 = cc.callFunc(this.endpk, this); //下半圆转弯 let down_point0 = cc.v2(470, -300); let down_point1 = cc.v2(Math.cos(Math.PI / 8) * 470, -300 - Math.sin(Math.PI / 8) * 470); let down_point2 = cc.v2(Math.cos(Math.PI / 4) * 470, -300 - Math.sin(Math.PI / 4) * 470); let down_point3 = cc.v2(Math.cos(3 * Math.PI / 8) * 470, -300 - Math.sin(3 * Math.PI / 8) * 470); let down_point4 = cc.v2(Math.cos(Math.PI / 2) * 470, -300 - Math.sin(Math.PI / 2) * 470); let down_point5 = cc.v2(Math.cos(5 * Math.PI / 8) * 470, -300 - Math.sin(5 * Math.PI / 8) * 470); let down_point6 = cc.v2(Math.cos(6 * Math.PI / 8) * 470, -300 - Math.sin(6 * Math.PI / 8) * 470); let down_point7 = cc.v2(Math.cos(7 * Math.PI / 8) * 470, -300 - Math.sin(7 * Math.PI / 8) * 470); let down_point8 = cc.v2(- 470, -300); //上半圆 let up_point0 = cc.v2(-470, 300); let up_point1 = cc.v2(Math.cos(Math.PI / 8) * -470, 300 + Math.sin(Math.PI / 8) * 470); let up_point2 = cc.v2(Math.cos(Math.PI / 4) * -470, 300 + Math.sin(Math.PI / 4) * 470); let up_point3 = cc.v2(Math.cos(3 * Math.PI / 8) * -470, 300 + Math.sin(3 * Math.PI / 8) * 470); let up_point4 = cc.v2(Math.cos(Math.PI / 2) * -470, 300 + Math.sin(Math.PI / 2) * 470); let up_point5 = cc.v2(Math.cos(5 * Math.PI / 8) * -470, 300 + Math.sin(5 * Math.PI / 8) * 470); let up_point6 = cc.v2(Math.cos(6 * Math.PI / 8) * -470, 300 + Math.sin(6 * Math.PI / 8) * 470); let up_point7 = cc.v2(Math.cos(7 * Math.PI / 8) * -470, 300 + Math.sin(7 * Math.PI / 8) * 470); let up_point8 = cc.v2(470, 300); let actionCircle1_1 = cc.spawn(cc.cardinalSplineTo(randomlist[3]*2.22, [down_point0,down_point1,down_point2,down_point3,down_point4,down_point5,down_point6,down_point7,down_point8], 0),cc.rotateBy(randomlist[3]*2.22, 180)); let actionCircle1_2 = cc.spawn(cc.cardinalSplineTo(randomlist[4]*2.22, [up_point0,up_point1,up_point2,up_point3,up_point4,up_point5,up_point6,up_point7,up_point8], 0), cc.rotateBy(randomlist[4]*2.22, 180)); let actionCircle2_1 = cc.spawn(cc.cardinalSplineTo(randomlist[8]*2.22, [down_point0,down_point1,down_point2,down_point3,down_point4,down_point5,down_point6,down_point7,down_point8], 0),cc.rotateBy(randomlist[8]*2.22, 180)); let actionCircle2_2 = cc.spawn(cc.cardinalSplineTo(randomlist[9]*2.22, [up_point0,up_point1,up_point2,up_point3,up_point4,up_point5,up_point6,up_point7,up_point8], 0), cc.rotateBy(randomlist[9]*2.22, 180)); let ActionAll = cc.sequence(placeAction, actionMove_1_1, actionCircle1_1, actionMove_1_2, actionCircle1_2, actionMove_1_3,finish1, actionMove_2_1, actionCircle2_1,actionMove_2_2,actionCircle2_2,actionMove_2_3,finish2 ); this.opposite_runnode.runAction(ActionAll); }, MyCarAction(randomlist) { //初始位置 let placeAction = cc.place(400, 0); //直线 let actionMove_1_1 = cc.moveTo(randomlist[0]/2, cc.v2(400, -300)); let actionMove_1_2 = cc.moveTo(randomlist[1], cc.v2(-400, 300)); let actionMove_1_3 = cc.moveTo(randomlist[2]/2, cc.v2(400, 0)); let actionMove_2_1 = cc.moveTo(randomlist[5]/2, cc.v2(400, -300)); let actionMove_2_2 = cc.moveTo(randomlist[6], cc.v2(-400, 300)); let actionMove_2_3 = cc.moveTo(randomlist[7]/2, cc.v2(400, 0)); let finish1 = cc.callFunc(this.showendpic, this); let finish2 = cc.callFunc(this.endpk, this); //下半圆转弯 let down_point0 = cc.v2(400, -300); let down_point1 = cc.v2(Math.cos(Math.PI / 8) * 400, -300 - Math.sin(Math.PI / 8) * 400); let down_point2 = cc.v2(Math.cos(Math.PI / 4) * 400, -300 - Math.sin(Math.PI / 4) * 400); let down_point3 = cc.v2(Math.cos(3 * Math.PI / 8) * 400, -300 - Math.sin(3 * Math.PI / 8) * 400); let down_point4 = cc.v2(Math.cos(Math.PI / 2) * 400, -300 - Math.sin(Math.PI / 2) * 400); let down_point5 = cc.v2(Math.cos(5 * Math.PI / 8) * 400, -300 - Math.sin(5 * Math.PI / 8) * 400); let down_point6 = cc.v2(Math.cos(6 * Math.PI / 8) * 400, -300 - Math.sin(6 * Math.PI / 8) * 400); let down_point7 = cc.v2(Math.cos(7 * Math.PI / 8) * 400, -300 - Math.sin(7 * Math.PI / 8) * 400); let down_point8 = cc.v2(- 400, -300); //上半圆 let up_point0 = cc.v2(-400, 300); let up_point1 = cc.v2(Math.cos(Math.PI / 8) * -400, 300 + Math.sin(Math.PI / 8) * 400); let up_point2 = cc.v2(Math.cos(Math.PI / 4) * -400, 300 + Math.sin(Math.PI / 4) * 400); let up_point3 = cc.v2(Math.cos(3 * Math.PI / 8) * -400, 300 + Math.sin(3 * Math.PI / 8) * 400); let up_point4 = cc.v2(Math.cos(Math.PI / 2) * -400, 300 + Math.sin(Math.PI / 2) * 400); let up_point5 = cc.v2(Math.cos(5 * Math.PI / 8) * -400, 300 + Math.sin(5 * Math.PI / 8) * 400); let up_point6 = cc.v2(Math.cos(6 * Math.PI / 8) * -400, 300 + Math.sin(6 * Math.PI / 8) * 400); let up_point7 = cc.v2(Math.cos(7 * Math.PI / 8) * -400, 300 + Math.sin(7 * Math.PI / 8) * 400); let up_point8 = cc.v2(400, 300); let actionCircle1_1 = cc.spawn(cc.cardinalSplineTo(randomlist[3]*2.22, [down_point0,down_point1,down_point2,down_point3,down_point4,down_point5,down_point6,down_point7,down_point8], 0),cc.rotateBy(randomlist[3]*2.22, 180)); let actionCircle1_2 = cc.spawn(cc.cardinalSplineTo(randomlist[4]*2.22, [up_point0,up_point1,up_point2,up_point3,up_point4,up_point5,up_point6,up_point7,up_point8], 0), cc.rotateBy(randomlist[4]*2.22, 180)); let actionCircle2_1 = cc.spawn(cc.cardinalSplineTo(randomlist[8]*2.22, [down_point0,down_point1,down_point2,down_point3,down_point4,down_point5,down_point6,down_point7,down_point8], 0),cc.rotateBy(randomlist[8]*2.22, 180)); let actionCircle2_2 = cc.spawn(cc.cardinalSplineTo(randomlist[9]*2.22, [up_point0,up_point1,up_point2,up_point3,up_point4,up_point5,up_point6,up_point7,up_point8], 0), cc.rotateBy(randomlist[9]*2.22, 180)); let ActionAll = cc.sequence(placeAction, actionMove_1_1, actionCircle1_1, actionMove_1_2, actionCircle1_2, actionMove_1_3,finish1, actionMove_2_1, actionCircle2_1,actionMove_2_2,actionCircle2_2,actionMove_2_3,finish2 ); this.mycar_runnode.runAction(ActionAll); }, /* @level:汽车等级 */ GetRandomList(level) { const DEFAULT_TIME = (3 / 5); const DEFAULT_UP_DOWM = 0.05; //每个段落的时间,在默认时间上下浮动5%; //每提升一级,默认时间缩短5%,以保证级大一级极高概率赢 let Curr_level_default_time =DEFAULT_TIME * Math.pow(1-DEFAULT_UP_DOWM, level); let timelist = []; for (let i = 0; i < 10; i++){ timelist.push((1-Math.random() * DEFAULT_UP_DOWM) * Curr_level_default_time); } return timelist; }, sum(list) { let res = 0; list.forEach(element => { res += element; }); return res; }, showendpic() { this.scheduleOnce(function () { this.endpic.active = true; },0.3) }, endpk() { //PK结束,我方胜利则发放奖金,对方胜利则显示失败。 if (this.endcarnum == 0) { this.endcarnum += 1; return; } if (this.endcarnum == 1) { MyAudio.StopEffect_pkbgm(); this.showinterad(); Global.showbanner(); this.node.active = true; this.pic_toast.active = true; let res = this.sum(this.my_list) - this.sum(this.opposite_list); let respicnode = cc.find('Canvas/BG/弹窗/BG/label'); if (res < 0) { MyAudio.PlayEffect_pksuccess(); respicnode.getComponent('languagesprite').updatelanguage(respicnode.getComponent(cc.Sprite), "你赢了"); // cc.resources.load("automerge/你赢了", cc.SpriteFrame, function (err, spriteFrame) { // cc.find("Canvas/BG/弹窗/BG/label").getComponent(cc.Sprite).spriteFrame = spriteFrame; // }); this.reword_number.string = Number(Storage.Get_storage(Storage.GameMessageType.buy_coin)) * 3; cc.find("Canvas/BG/弹窗/BG/fail_label").active = false; } else { MyAudio.PlayEffect_pkfail(); this.reword_number.string = Number(Storage.Get_storage(Storage.GameMessageType.buy_coin)); cc.find("Canvas/BG/弹窗/BG/fail_label").active = true; // console.log("对方胜利") respicnode.getComponent('languagesprite').updatelanguage(respicnode.getComponent(cc.Sprite), "你输了"); //先判断小游戏平台,再判断原生平台 if (cc.sys.platform === cc.sys.WECHAT_GAME) { return; } //调用广告,奖励3个汽车钱 if (cc.sys.platform === cc.sys.ANDROID) { Admob.ShowInterstitialRewardAD(); return; } } this.endcarnum = 0; } Global.EndRecode(); }, showinterad(){ // 在适合的场景显示插屏广告 let interstitialAd = Global.interstitialAd; if (interstitialAd) { interstitialAd.show().catch((err) => { console.error(err) }) } } // update (dt) {}, });