123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883 |
- var cfg = require("Configure")
- var WxCommon = require("../WxCommon")
- cc.Class({
- extends: cc.Component,
- properties: {
- buDing: {
- default: null,
- type: cc.Sprite
- },
- obstacleNode: {
- default: null,
- type: cc.Node
- },
- scoreNode: {
- default: null,
- type: cc.Node
- },
- funcNode: {
- default: null,
- type: cc.Node
- },
- sumScore: 0,
- layerNum: 0,
- obstacleNum: 0,
- starNum: 0,
- gamebgMusic: {
- default: null,
- url: cc.AudioClip
- },
- changeColorAudio: {
- default: null,
- url: cc.AudioClip
- },
- eatGoldAudio: {
- default: null,
- url: cc.AudioClip
- },
- newRecordAudio: {
- default: null,
- url: cc.AudioClip
- },
- buttonAudio: {
- default: null,
- url: cc.AudioClip
- },
- passNode: { //超越提示节点
- default: null,
- type: cc.Node
- },
- bShare: false,
- bDead: false,
- bPause: false,
- feiendtex: null,
- childCanvas: null
- },
- onLoad: function () {
- if (cc.vv == undefined) {
- cc.vv = {};
- }
- var manager = cc.director.getCollisionManager();
- manager.enabled = true;
- this.registerTouchEventHandle();
- if (cc.winSize.height > 1334) {
- this.node.getChildByName("ScoreNode").setPosition(0, (cc.winSize.height - 1334) / 2);
- this.node.getChildByName("FuncNode").setPosition(0, -(cc.winSize.height - 1334) / 2);
- }
- this.showVd = false;
- this.debugErrorTips = false;
- },
- start: function () {
- this.feiendtex = new cc.Texture2D();
- this.childCanvas = new cc.Texture2D();
- },
- startGame: function () {
- //通知子域重新填充rankList
- if (UserInfo.platform == 1 && cc.vv.isRank) {
- wx.postMessage({
- method: 'fillRankList'
- });
- }
- cc.audioEngine.playMusic(this.gamebgMusic, true);
- this.sumScore = 0;
- this.layerNum = 0;
- this.starNum = 0;
- this.obstacleNum = 0;
- this.bShare = true;
- this.bDead = false;
- this.bVideo = true;
- this.scoreNode.active = true;
- this.funcNode.active = true;
- this.obstacleNode.removeAllChildren();
- this.node.getChildByName("Camera").setPosition(cc.p(0, 0));
- var sumScoreLabel = this.scoreNode.getChildByName("ScoreLabel");
- sumScoreLabel.getComponent("cc.Label").string = this.sumScore;
- //var layerNumLabel = this.scoreNode.getChildByName("LayerLabel");
- //layerNumLabel.getComponent("cc.Label").string = this.layerNum;
- this.node.getChildByName("Camera").getComponent("CameraControl").resetData();
- this.buDing.getComponent("BuDingSprite").initBuding();
- //cc.director.getPhysicsManager().enabled = true;
- this.createObstacle();
- this.node.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(this.createObstacle, this), cc.delayTime(1), cc.callFunc(this.createObstacle, this)));
- let stmp = new Date().getTime();
- cc.loader.load({
- url: "https://pub.dwstatic.com/wxgame/budingGame/share.json?" + (stmp/100000).toFixed(0),
- type: "json"
- }, (err, res) => {
- if(res) {
- this.showVd = res.showVd
- this.bShare = res.bShare
- this.debugErrorTips = res.debugErrorTips
- }
- })
- },
- finishGame: function () {
- this.bDead = true;
- this.buDing.node.active = false;
- this.buDing.node.getComponent("BuDingSprite").setSkSpriteVisible(false);
- this.scoreNode.active = false;
- this.funcNode.active = false;
- var gameOverNode = this.node.getChildByName("GameOver");
- gameOverNode.active = true;
- var endLayerNumLabel = gameOverNode.getChildByName("EndLayerNumLabel");
- endLayerNumLabel.getComponent("cc.Label").string = this.sumScore;
- if (this.bShare) {
- // var endScoreLabel = gameOverNode.getChildByName("ShareNode").getChildByName("EndScoreLabel");
- // endScoreLabel.getComponent("cc.Label").string = this.sumScore;
- var shareNode = gameOverNode.getChildByName("ShareNode");
- shareNode.active = true;
- gameOverNode.getChildByName("EndNode").active = false;
- if (this.showVd) {
- //显示观看视频广告按钮
- shareNode.getChildByName("ShareBtn").active = false;
- shareNode.getChildByName("VideoBtn").active = true;
- } else {
- //显示邀请好友按钮
- shareNode.getChildByName("ShareBtn").active = true;
- shareNode.getChildByName("VideoBtn").active = false;
- }
- this.startFinishCount();
- } else {
- gameOverNode.getChildByName("EndNode").active = true;
- gameOverNode.getChildByName("ShareNode").active = false;
- this.gameOver();
- var data = [{
- key: UserInfo.getCurWeekScoreValue(),
- value: UserInfo.getScore().toString()
- }, {
- key: "driLevel",
- value: '0'
- }
- ];
- if (CC_WECHATGAME && cc.vv.isRank) {
- this.node.parent.getChildByName("PHB").getChildByName("bg").active = false;
- this.showRank();
- this.updateXYXScore('showMyRank', data);
- }
- }
- },
- //结束界面开始倒计时
- startFinishCount: function (countDown) {
- var countDown = 10;
- var gameOverNode = this.node.getChildByName("GameOver");
- var countDownLabel = gameOverNode.getChildByName("ShareNode").getChildByName("EndCountDownLabel");
- countDownLabel.getComponent("cc.Label").string = countDown;
- var callback = function () {
- if (countDown <= 0) {
- gameOverNode.getChildByName("ShareNode").active = false;
- gameOverNode.getChildByName("EndNode").active = true;
- this.gameOver();
- var data = [{
- key: UserInfo.getCurWeekScoreValue(),
- value: UserInfo.getScore().toString()
- }, {
- key: "driLevel",
- value: '0'
- }
- ];
- if (CC_WECHATGAME && cc.vv.isRank) {
- this.showRank();
- self.updateXYXScore('showMyRank', data);
- }
- } else {
- countDown--;
- countDownLabel.getComponent("cc.Label").string = countDown;
- countDownLabel.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(callback, this)));
- }
- }
- countDownLabel.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(callback, this)));
- },
- gameOver: function () {
- var gameOverNode = this.node.getChildByName("GameOver");
- var historyScoreLabel = gameOverNode.getChildByName("EndNode").getChildByName("HistoryScoreLabel");
- var newRecordSp = gameOverNode.getChildByName("EndNode").getChildByName("NewRecordSp");
- if (this.sumScore > UserInfo.getHistoryScore()) {
- newRecordSp.active = true;
- UserInfo.setString("historyScore", this.sumScore);
- cc.audioEngine.playEffect(this.newRecordAudio);
- newRecordSp.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.5), cc.scaleTo(0.5, 1))));
- } else {
- newRecordSp.active = false;
- }
- if (this.sumScore > UserInfo.getScore()) {
- UserInfo.setScore(this.sumScore);
- }
- historyScoreLabel.getComponent("cc.Label").string = "历史最高分:" + UserInfo.getHistoryScore();
- UserInfo.addGold(this.sumScore);
- },
- continueGame: function () {
- this.bShare = false;
- this.bDead = false;
- this.layerNum = 0;
- this.starNum = 0;
- this.obstacleNum = 0;
- this.scoreNode.active = true;
- this.funcNode.active = true;
- this.node.getChildByName("GameOver").active = false;
- this.obstacleNode.removeAllChildren();
- this.node.getChildByName("Camera").getComponent("CameraControl").resetData();
- this.node.getChildByName("Camera").setPosition(cc.p(0, 0));
- this.buDing.getComponent("BuDingSprite").initBuding();
- //cc.director.getPhysicsManager().enabled = true;
- this.createObstacle();
- this.node.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(this.createObstacle, this), cc.delayTime(1), cc.callFunc(this.createObstacle, this)));
- },
- createObstacle: function () {
- var obstacleType = this.randomObstacleType();
- //根据当前分数控制障碍物之间的高度
- var disObstacleY;
- if (this.sumScore > 40) {
- disObstacleY = 0;
- } else if (this.sumScore > 30 && this.sumScore <= 40) {
- disObstacleY = 50;
- } else if (this.sumScore > 15 && this.sumScore <= 30) {
- disObstacleY = 100;
- } else {
- disObstacleY = 150;
- }
- var self = this;
- cc.loader.loadRes(cfg.obstacleTypePath[obstacleType], function (err, prefab) {
- if (self.obstacleNode.getChildByName("obstacle1") == null) {
- var obstacle1 = cc.instantiate(prefab);
- obstacle1.setName("obstacle1");
- self.obstacleNode.addChild(obstacle1);
- if (self.obstacleNode.getChildByName("obstacle3") != null) {
- var type = self.obstacleNode.getChildByName("obstacle3").getComponent("Obstacle").getType();
- var specialOffsetY = 0
- if (type == cfg.obstacleType.circle3) {
- if (obstacleType == cfg.obstacleType.square || obstacleType == cfg.obstacleType.circle2) {
- specialOffsetY = 100;
- }
- } else if (type == cfg.obstacleType.circle2) {
- if (obstacleType == cfg.obstacleType.square) {
- specialOffsetY = 100;
- }
- }
- obstacle1.setPosition(0, self.obstacleNode.getChildByName("obstacle3").y + (cc.winSize.height + cfg.obstacleProperty[type].addY + specialOffsetY) * (1334 / cc.winSize.height) + disObstacleY);
- } else {
- obstacle1.setPosition(0, 500 * (1334 / cc.winSize.height) + 100);
- }
- obstacle1.getComponent("Obstacle").initObstacle(obstacleType, self.obstacleNum, self.sumScore);
- } else if (self.obstacleNode.getChildByName("obstacle2") == null) {
- var obstacle2 = cc.instantiate(prefab);
- obstacle2.setName("obstacle2");
- self.obstacleNode.addChild(obstacle2);
- if (self.obstacleNode.getChildByName("obstacle1") != null) {
- var type = self.obstacleNode.getChildByName("obstacle1").getComponent("Obstacle").getType();
- var specialOffsetY = 0
- if (type == cfg.obstacleType.circle3) {
- if (obstacleType == cfg.obstacleType.square || obstacleType == cfg.obstacleType.circle2) {
- specialOffsetY = 100;
- }
- } else if (type == cfg.obstacleType.circle2) {
- if (obstacleType == cfg.obstacleType.square) {
- specialOffsetY = 100;
- }
- }
- obstacle2.setPosition(0, self.obstacleNode.getChildByName("obstacle1").y + (cc.winSize.height + cfg.obstacleProperty[type].addY + specialOffsetY) * (1334 / cc.winSize.height) + disObstacleY);
- } else {
- obstacle2.setPosition(0, 500 * (1334 / cc.winSize.height) + 100);
- }
- obstacle2.getComponent("Obstacle").initObstacle(obstacleType, self.obstacleNum, self.sumScore);
- } else if (self.obstacleNode.getChildByName("obstacle3") == null) {
- var obstacle3 = cc.instantiate(prefab);
- obstacle3.setName("obstacle3");
- self.obstacleNode.addChild(obstacle3);
- if (self.obstacleNode.getChildByName("obstacle2") != null) {
- var type = self.obstacleNode.getChildByName("obstacle2").getComponent("Obstacle").getType();
- var specialOffsetY = 0
- if (type == cfg.obstacleType.circle3) {
- if (obstacleType == cfg.obstacleType.square || obstacleType == cfg.obstacleType.circle2) {
- specialOffsetY = 100;
- }
- } else if (type == cfg.obstacleType.circle2) {
- if (obstacleType == cfg.obstacleType.square) {
- specialOffsetY = 100;
- }
- }
- obstacle3.setPosition(0, self.obstacleNode.getChildByName("obstacle2").y + (cc.winSize.height + cfg.obstacleProperty[type].addY + specialOffsetY) * (1334 / cc.winSize.height) + disObstacleY);
- } else {
- obstacle3.setPosition(0, 500 * (1334 / cc.winSize.height) + 100);
- }
- obstacle3.getComponent("Obstacle").initObstacle(obstacleType, self.obstacleNum, self.sumScore);
- }
- })
- },
- randomObstacleType: function () {
- var obstacleType = 0;
- this.obstacleNum++;
- var randNum = Math.floor(Math.random() * 100) + 1;
- if (this.obstacleNum == 1) {
- obstacleType = 0;
- } else if (this.obstacleNum > 1 && this.obstacleNum <= 5) {
- if (randNum > 0 && randNum <= 35) {
- obstacleType = 0;
- } else if (randNum > 35 && randNum <= 70) {
- obstacleType = 1;
- } else if (randNum > 70 && randNum <= 85) {
- obstacleType = 2;
- } else if (randNum > 85 && randNum <= 100) {
- obstacleType = 3;
- }
- } else if (this.obstacleNum > 15 && this.obstacleNum <= 45) {
- if (randNum > 0 && randNum <= 20) {
- obstacleType = 0;
- } else if (randNum > 20 && randNum <= 40) {
- obstacleType = 1;
- } else if (randNum > 40 && randNum <= 60) {
- obstacleType = 2;
- } else if (randNum > 60 && randNum <= 80) {
- obstacleType = 3;
- } else if (randNum > 80 && randNum <= 90) {
- obstacleType = 4;
- } else if (randNum > 90 && randNum <= 100) {
- obstacleType = 5;
- }
- } else if (this.obstacleNum > 45) {
- var randNum = Math.floor(Math.random() * 100) + 1;
- if (randNum > 0 && randNum <= 10) {
- obstacleType = 0;
- } else if (randNum > 10 && randNum <= 20) {
- obstacleType = 1;
- } else if (randNum > 20 && randNum <= 35) {
- obstacleType = 2;
- } else if (randNum > 35 && randNum <= 50) {
- obstacleType = 3;
- } else if (randNum > 50 && randNum <= 75) {
- obstacleType = 4;
- } else if (randNum > 75 && randNum <= 100) {
- obstacleType = 5;
- }
- }
- return obstacleType;
- },
- destroyObstacle: function () {
- if (!this.obstacleNode.getChildByName("obstacle1").active) {
- this.obstacleNode.removeChild(this.obstacleNode.getChildByName("obstacle1"));
- }
- if (!this.obstacleNode.getChildByName("obstacle2").active) {
- this.obstacleNode.removeChild(this.obstacleNode.getChildByName("obstacle2"));
- }
- if (!this.obstacleNode.getChildByName("obstacle3").active) {
- this.obstacleNode.removeChild(this.obstacleNode.getChildByName("obstacle3"));
- }
- this.createObstacle();
- },
- registerTouchEventHandle: function () {
- this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
- if (!this.bDead && !this.bPause) {
- this.buDing.getComponent("BuDingSprite").jump();
- }
- }, this)
- this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
- }, this)
- },
- addScore: function () {
- cc.audioEngine.playEffect(this.eatGoldAudio);
- var addScoreLabel = this.node.getChildByName("AddScoreLabel");
- addScoreLabel.getComponent("cc.Label").string = "/" + 1;
- addScoreLabel.active = true;
- addScoreLabel.opacity = 255;
- addScoreLabel.runAction(cc.fadeTo(1, 0));
- this.sumScore += 1;
- this.starNum++;
- var sumScoreLabel = this.scoreNode.getChildByName("ScoreLabel");
- sumScoreLabel.getComponent("cc.Label").string = this.sumScore;
- sumScoreLabel.runAction(cc.sequence(cc.scaleTo(0.5, 1.2), cc.scaleTo(0.5, 1)));
- //超越
- // if (UserInfo.platform == 1 && cc.vv.isRank) {
- // this.node.getChildByName("Pass").active = true;
- // wx.postMessage({
- // method: 'checkPass',
- // data: this.sumScore
- // });
- // }
- // if (this.starNum >= 2)
- // {
- // var isVisible = (this.starNum%2!=0);
- // this.obstacleNode.getChildByName("obstacle1").active = isVisible;
- // this.obstacleNode.getChildByName("obstacle2").active = !isVisible;
- // this.destroyObstacle();
- // }
- },
- showPass: function () {
- if (UserInfo.platform == 1 && cc.vv.isRank) {
- let openDataContext = wx.getOpenDataContext();
- let sharedCanvas = openDataContext.canvas;
- this.childCanvas.initWithElement(sharedCanvas);
- this.childCanvas.handleLoadedTexture();
- this.passNode.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(this.childCanvas);
- //var scale = Math.min(750 / this.feiendtex.width, 1334 / this.feiendtex.height);
- //this.passNode.setContentSize(this.feiendtex.width * scale, this.feiendtex.height * scale);
- }
- },
- addLayerNum: function () {
- cc.audioEngine.playEffect(this.changeColorAudio);
- //var layerNumLabel = this.scoreNode.getChildByName("LayerLabel");
- this.layerNum++;
- //layerNumLabel.getComponent("cc.Label").string = this.layerNum;
- //layerNumLabel.runAction(cc.sequence(cc.scaleTo(0.5,1.2),cc.scaleTo(0.5,1)));
- //this.buDing.getComponent("BuDingSprite").changeColor(colorType);
- if (this.layerNum >= 2) {
- if (this.layerNum % 3 == 0) {
- this.obstacleNode.getChildByName("obstacle1").active = true;
- this.obstacleNode.getChildByName("obstacle2").active = false;
- this.obstacleNode.getChildByName("obstacle3").active = true;
- } else if (this.layerNum % 3 == 1) {
- this.obstacleNode.getChildByName("obstacle1").active = true;
- this.obstacleNode.getChildByName("obstacle2").active = true;
- this.obstacleNode.getChildByName("obstacle3").active = false;
- } else if (this.layerNum % 3 == 2) {
- this.obstacleNode.getChildByName("obstacle1").active = false;
- this.obstacleNode.getChildByName("obstacle2").active = true;
- this.obstacleNode.getChildByName("obstacle3").active = true;
- }
- this.destroyObstacle();
- }
- },
- onPauseBtn: function () {
- this.bPause = true;
- this.buDing.getComponent("BuDingSprite").stopBuding();
- this.node.getChildByName("Mask").active = true;
- this.funcNode.getChildByName("PauseBtn").active = false;
- this.funcNode.getChildByName("PlayBtn").active = true;
- var obstacle1 = this.obstacleNode.getChildByName("obstacle1");
- var obstacle2 = this.obstacleNode.getChildByName("obstacle2");
- var obstacle3 = this.obstacleNode.getChildByName("obstacle3");
- if (obstacle1 != null) {
- obstacle1.getComponent("Obstacle").pauseObstacleAction();
- }
- if (obstacle2 != null) {
- obstacle2.getComponent("Obstacle").pauseObstacleAction();
- }
- if (obstacle3 != null) {
- obstacle3.getComponent("Obstacle").pauseObstacleAction();
- }
- },
- onPlayBtn: function () {
- var playBtn = this.funcNode.getChildByName("PlayBtn");
- playBtn.getComponent("cc.Button").interactable = false;
- playBtn.getChildByName("PlaySprite").active = false;
- var countDownLabel = this.funcNode.getChildByName("CountDownLabel");
- countDownLabel.active = true;
- var countDown = 3;
- countDownLabel.getComponent("cc.Label").string = countDown;
- var mask = this.node.getChildByName("Mask");
- var pauseBtn = this.funcNode.getChildByName("PauseBtn");
- var obstacle1 = this.obstacleNode.getChildByName("obstacle1");
- var obstacle2 = this.obstacleNode.getChildByName("obstacle2");
- var obstacle3 = this.obstacleNode.getChildByName("obstacle3");
- var self = this;
- var callback = function () {
- if (countDown <= 1) {
- playBtn.active = false;
- playBtn.getComponent("cc.Button").interactable = true;
- playBtn.getChildByName("PlaySprite").active = true;
- countDownLabel.active = false;
- var callback1 = function () {
- mask.active = false;
- pauseBtn.active = true;
- self.bPause = false;
- self.buDing.getComponent("BuDingSprite").resumeBuding();
- if (obstacle1 != null) {
- obstacle1.getComponent("Obstacle").resumeObstacleAction();
- }
- if (obstacle2 != null) {
- obstacle2.getComponent("Obstacle").resumeObstacleAction();
- }
- if (obstacle3 != null) {
- obstacle3.getComponent("Obstacle").resumeObstacleAction();
- }
- }
- self.funcNode.runAction(cc.sequence(cc.delayTime(0.5), cc.callFunc(callback1, this)));
- } else {
- countDown--;
- countDownLabel.getComponent("cc.Label").string = countDown;
- countDownLabel.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(callback, this)));
- }
- }
- countDownLabel.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(callback, this)));
- },
- onChallengeBtn: function () {
- var sharedesc = "";
- sharedesc = '我的布丁穿过了' + this.sumScore + '个障碍物,快来挑战我吧!';
- var data = {
- titleData: sharedesc,
- imgurlData: UserInfo.shareUrl,
- queryData: 'pp=pp'
- }
- WxCommon.ShareAppMessage(data, this, null);
- },
- onShareBtn: function () {
- //接分享
- if (CC_WECHATGAME && cc.vv.isRank) {
- var data = {
- titleData: UserInfo.shareDesc,
- imgurlData: UserInfo.shareUrl,
- queryData: 'pp=pp'
- }
- this.shareFlag = 1;
- WxCommon.ShareAppMessage(data, this.node.getComponent("GameSence"), this.node.getComponent("GameSence").comeBack);
- wx.onShow(res => {
- if(this.shareFlag == 1) {
- var gameOverNode = this.node.getChildByName("GameOver");
- var countDownLabel = gameOverNode.getChildByName("ShareNode").getChildByName("EndCountDownLabel");
- countDownLabel.stopAllActions();
- this.continueGame();
- cc.audioEngine.playMusic(this.gamebgMusic, true);
- this.shareFlag = 0;
- }
- })
- } else {
- var gameOverNode = this.node.getChildByName("GameOver");
- var countDownLabel = gameOverNode.getChildByName("ShareNode").getChildByName("EndCountDownLabel");
- countDownLabel.stopAllActions();
- this.continueGame();
- cc.audioEngine.playMusic(this.gamebgMusic, true);
- }
- },
- onWatchVideoBtn: function () {
- var gameOverNode = this.node.getChildByName("GameOver");
- var countDownLabel = gameOverNode.getChildByName("ShareNode").getChildByName("EndCountDownLabel");
-
- if (CC_WECHATGAME && window.wx.createRewardedVideoAd) {
- this.bShare = false;
- countDownLabel.stopAllActions();
- if(this.debugErrorTips) {
- this.showWatchVdError();
- return;
- }
- let videoAd = wx.createRewardedVideoAd({
- adUnitId: 'adunit-563ed529855c1195'
- })
- videoAd.onClose(res => {
- // 用户点击了【关闭广告】按钮
- // 小于 2.1.0 的基础库版本,res 是一个 undefined
- if (res && res.isEnded || res === undefined) {
- // 正常播放结束,可以下发游戏奖励
- this.continueGame();
- cc.audioEngine.playMusic(this.gamebgMusic, true);
- } else {
- // 播放中途退出,不下发游戏奖励
- this.startFinishCount();
- }
- })
- videoAd.onError(res => {
- this.showWatchVdError()
- })
- videoAd.load()
- .then(() => videoAd.show())
- .catch(err => {
- videoAd.load()
- .then(() => videoAd.show())
- })
- } else {
- }
- },
- showWatchVdError: function() {
- if(CC_WECHATGAME) {
- wx.showModal({
- title: "提示",
- content: "拉取视频广告失败,邀请好友一起通关可获得一次复活机会",
- showCancel: false,
- cancelText: "取消",
- confirmText: "确定",
- success: () => {
- var gameOverNode = this.node.getChildByName("GameOver");
- var shareNode = gameOverNode.getChildByName("ShareNode");
- //显示邀请好友按钮
- shareNode.getChildByName("ShareBtn").active = true;
- shareNode.getChildByName("VideoBtn").active = false;
- this.startFinishCount();
- }
- })
- }
- },
- //分享到群复活
- comeBack: function (shareTickets) {
- //console.log("我又回来啦");
- if (!UserInfo.IsEmpty(shareTickets)) {
- let currentShareCount = parseInt(UserInfo.getString("shareWXCount"));
- if (currentShareCount > 0) {
- currentShareCount--;
- UserInfo.setString("shareWXCount", currentShareCount);
- var gameOverNode = this.node.getChildByName("GameOver");
- var countDownLabel = gameOverNode.getChildByName("ShareNode").getChildByName("EndCountDownLabel");
- countDownLabel.stopAllActions();
- this.continueGame();
- cc.audioEngine.playMusic(this.gamebgMusic, true);
- if (UserInfo.platform == 1 && cc.vv.isRank) {
- wx.postMessage({
- method: 'hideRank',
- data: "false"
- });
- cc.find("Canvas/PHB").active = false;
- }
- } else {
- UserInfo.setString("shareWXCount", 0);
- }
- }
- },
- onPassBtn: function () {
- var gameOverNode = this.node.getChildByName("GameOver");
- var countDownLabel = gameOverNode.getChildByName("ShareNode").getChildByName("EndCountDownLabel");
- countDownLabel.stopAllActions();
- gameOverNode.getChildByName("ShareNode").active = false;
- gameOverNode.getChildByName("EndNode").active = true;
- this.gameOver();
- var data = [{
- key: UserInfo.getCurWeekScoreValue(),
- value: UserInfo.getScore().toString()
- },
- {
- key: "driLevel",
- value: '0'
- }
- ];
- if (CC_WECHATGAME && cc.vv.isRank) {
- this.showRank();
- this.updateXYXScore('showMyRank', data);
- }
- },
- onRestartBtn: function () {
- this.node.getChildByName("GameOver").active = false;
- this.node.parent.getChildByName("PHB").active = false;
- this.startGame();
- },
- onShopBtn: function () {
- },
- onRankBtn: function (event, optData) {
- if (CC_WECHATGAME && cc.vv.isRank) {
- wx.postMessage({
- method: 'showFriendRank',
- data: optData
- });
- this.node.parent.getChildByName("PHB").getChildByName("BtnPHBClose").active = (optData == "true");
- this.node.parent.getChildByName("PHB").getChildByName("emptyBtn").active = (optData == "true");
- this.node.parent.getChildByName("PHB").getChildByName("bg").active = (optData == "true");
- if ("true" == optData) {
- this.showRank();
- }
- if ("false" == optData) {
- wx.postMessage({
- method: 'hideRank',
- data: optData
- });
- cc.find("Canvas/PHB").active = false;
- }
- }
- },
- updateXYXScore(strFun, data) {
- data.push({
- key: "starrank",
- value: UserInfo.getScore().toString()
- })
- wx.setUserCloudStorage({
- KVDataList: data,
- success: function (res) {
- wx.postMessage({
- method: strFun
- });
- },
- fail: function (res) {
- console.error(res);
- },
- complete: function (res) {}
- })
- },
- showRank() {
- if (UserInfo.platform == 1 && cc.vv.isRank) {
- let openDataContext = wx.getOpenDataContext();
- let sharedCanvas = openDataContext.canvas;
- this.feiendtex.initWithElement(sharedCanvas);
- this.feiendtex.handleLoadedTexture();
- cc.find("Canvas/PHB").getChildByName("feiendrank").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(this.feiendtex);
- //cc.find("Canvas/PHB").getChildByName("feiendrank").setContentSize(720,1280);
- var scale = Math.min(750 / this.feiendtex.width, 1334 / this.feiendtex.height);
- cc.find("Canvas/PHB").getChildByName("feiendrank").setContentSize(this.feiendtex.width * scale, this.feiendtex.height * scale);
- cc.find("Canvas/PHB").active = true;
- this.node.getChildByName("Pass").active = false;
- }
- },
- onHonourBtn: function () {
- },
- onMoreGameBtn: function (optData) {
- var endNode = this.node.getChildByName("GameOver").getChildByName("EndNode");
- endNode.getChildByName("ChallengeBtn").getComponent("cc.Button").interactable = (optData == "false");
- endNode.getChildByName("RestartBtn").getComponent("cc.Button").interactable = (optData == "false");
- endNode.getChildByName("SkinBtn").getComponent("cc.Button").interactable = (optData == "false");
- endNode.getChildByName("RankBtn").getComponent("cc.Button").interactable = (optData == "false");
- endNode.getChildByName("MoreGameBtn").getComponent("cc.Button").interactable = (optData == "false");
- endNode.getChildByName("HonourBtn").getComponent("cc.Button").interactable = (optData == "false");
- },
- onBackHomeBtn: function() {
- this.node.getChildByName("GameOver").active = false;
- this.node.parent.getChildByName("PHB").active = false;
- this.node.parent.getComponent("SenceManager").enterSence("Game", "Home");
- },
- onBtnAudio: function () {
- cc.audioEngine.playEffect(this.buttonAudio);
- },
- update: function (dt) {
- if (cc.find("Canvas/PHB").active) {
- this.showRank();
- //console.log("显示排行榜");
- }
- // if (this.node.getChildByName("Pass").active)
- // {
- // this.showPass();
- // }
- },
- });
|