// Learn TypeScript: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html import DaDianScript from "../../../FrameWork/Base/DaDianScript"; import WordGameBaseComponent from "../../../FrameWork/Base/WordGameBaseComptent"; import { ryw_Event } from "../../../FrameWork/Event/EventEnum"; import EventMgr from "../../../FrameWork/Event/EventMgr"; import Common from "../../../FrameWork/Util/Common"; import Common5 from "../../../Platform/th/Common5"; import Game from "../../../Scripts/Game"; import ChooseBtnLayer from "../../../WordGame/gameComScript/ChooseBtnLayer"; import DuiHuaScript from "../../../WordGame/guizeGame/comScript/DuiHuaScript"; import GZTipBtnScript from "../../../WordGame/guizeGame/comScript/GZTipBtnScript"; import GuiZeLayer from "../../../WordGame/guizeGame/comScript/GuiZeLayer"; // import DaiJiaConfig from "./DaiJiaConfig"; const { ccclass, property } = cc._decorator; enum QIDONG { FIRST, SECOND, THIRD } @ccclass export default class DaiJiaScript extends WordGameBaseComponent { @property(cc.Node) layerArray: cc.Node[] = [] @property(cc.Node) resultLayer: cc.Node[] = [] @property(cc.Node) GuiZeLayer: cc.Node = null @property(cc.Node) ChooseLayer: cc.Node = null @property(cc.Node) DuiHuaPrefab: cc.Node = null @property(cc.Node) GZTipBtn: cc.Node = null @property(cc.Node) ChooseLayer2: cc.Node = null // LIFE-CYCLE CALLBACKS: // onLoad () {} curVdTipIndex = 0 //当前提示界面的索引0,1,2,3,4,5 duihuaConfig = null resultDuihuaArray = null titleArrayConfig = null curLayerIndex = 0 //当前层0 stepIndex = 0 //对话有用0 curTime = 0 timeAngle = 30 kuaidiDesc: string; IsChoose = false; isQiaomen = false; curSpeedNum = 15 // LIFE-CYCLE CALLBACKS: isJiangwen = false clearTmOut: number; firstQidong = true; // onLoad () {} qidongQiChe = QIDONG.FIRST; showDuihuaIndex = 'chooseArray0' ChooseLayerNode = null start() { super.start(); DaDianScript.userEnterDaDian() Common5.playMusicCustom('daijia', 'sound/代驾背景音') Common5.getJsonFromBundle(Common5.selectGameInfo.bundle,'script/DaiJiaConfig',(assest)=>{ //this.jsonData = JSON.stringify(assest.json) this.jsonData = assest.json this.initParameters(); }) EventMgr.onEvent_custom(ryw_Event.GuiZeGameBtnClick, (data) => { let touchIndex = data.touchIndex if (this.curLayerIndex == 0) { this.changeCurTipIndex(1) } else if (this.curLayerIndex == 1) { this.changeCurTipIndex(3) } else if (this.curLayerIndex == 2) { this.changeCurTipIndex(5) } this.gameStep(touchIndex) }, this) EventMgr.onEvent_custom(ryw_Event.openGuizeLayerEvent, (data) => { this.guizeBtnLayer() }, this) EventMgr.onEvent_custom(ryw_Event.chooseResult, (data_) => { this.chooseResult(data_.touchIndex) }, this) EventMgr.onEvent_custom(ryw_Event.NormalTouchEndCheck, (data_) => { this.normalTouchEnd(data_.targetNode) }, this) EventMgr.onEvent_custom(ryw_Event.NormalTouchMoveCheck, (data_) => { this.normalTouchMove(data_.targetNode) }, this) EventMgr.onEvent_custom(ryw_Event.DirectTouchMoveCheck, (data_) => { this.directTouchMove(data_.targetNode) }, this) EventMgr.onEvent_custom(ryw_Event.WordGameRevive, () => { this.wordGameReviveCallback(); }, this); } initParameters(){ Common.Type = 0; Common.subLevel = this.curVdTipIndex Common.GameSubTipConfigs = this.jsonData.tipsArray //DaiJiaConfig.getInstance().getGameConfig('tipsArray') Common.GameSubAnswerConfigs = this.jsonData.answersArray //DaiJiaConfig.getInstance().getGameConfig('answersArray'); Common.GameSubChooseArray = this.jsonData.chooseArray //DaiJiaConfig.getInstance().getGameConfig('chooseArray') Common.GameguizeArray = this.jsonData.GameguizeArray //DaiJiaConfig.getInstance().getGameConfig('GameguizeArray') this.titleArrayConfig = this.jsonData.titleArray //DaiJiaConfig.getInstance().getGameConfig('titleArray') this.duihuaConfig = this.jsonData.duihuaArray //DaiJiaConfig.getInstance().getGameConfig('duihuaArray') this.resultDuihuaArray = this.jsonData.resultDuihuaArray //DaiJiaConfig.getInstance().getGameConfig('resultDuihuaArray') this.refreshTipBtn() this.refreshTitle() this.showDuihua(this.stepIndex) this.setpIndexAdd() } wordGameReviveCallback(){ // for(let i = 0; i { node.getChildByName('tui').getChildByName('daijiazheng').active = false node.getChildByName('qidongChezi').getChildByName('qidong2').active = true }) this.setpIndexAdd() }else if(targetNode.name == 'touchM' ){ console.log(this.showDuihuaIndex, targetNode.active, 'targetNode.active') if(this.showDuihuaIndex == 'chooseArray1'){ if(node.getChildByName('yao')){ node.getChildByName('yao').active = true } }else{ if(node.getChildByName('yao')){ node.getChildByName('yao').active = false } } } } setChooseLayerHide() { let ChooseLayer = this.node.getChildByName('ChooseLayer') ChooseLayer.active = false let ChooseLayer2 = this.node.getChildByName('GZChooseLayer2') ChooseLayer2.active = false } normalTouchMove(targetNode) { let node = this.layerArray[this.curLayerIndex] if (node.getChildByName('yao') && targetNode == node.getChildByName('yao')) { let hongyi = node.getChildByName('hongyi') let door = node.getChildByName('车').getChildByName('开门') this.showDuihua(this.stepIndex, () => { cc.tween(hongyi) .to(2, { opacity: 0 }) .call(() => { hongyi.active = false door.active = false this.setChooseLayerHide() }) .start() }) this.setpIndexAdd() } } normalTouchEnd(targetNode) { let node = this.layerArray[this.curLayerIndex] if (node.getChildByName('kaicheQianmen') && targetNode == node.getChildByName('kaicheQianmen')) { //失败 let hongyi = node.getChildByName('hongyi') node.getChildByName('kaicheQianmen').active = false if (hongyi.active) { if(this.showDuihuaIndex == 'chooseArray'){ this.showDuihuaIndex = null } this.failShow(this.curLayerIndex) } else { //出发 let meigui2 = node.getChildByName('玫瑰酒吧2') meigui2.active = true this.scheduleOnce(() => { this.refreCurLayerView(null, 3) }, 2.0) } } else if (node.getChildByName('kaicheHoumen') && targetNode == node.getChildByName('kaicheHoumen')) { // this.showDuihua(this.stepIndex, () => { node.getChildByName('hongyi').getChildByName('touchM').active = true this.chooseLayerShow(this.ChooseLayer2, 'chooseArray1') }) this.setpIndexAdd() } else if (node.getChildByName('baiyi') && targetNode == node.getChildByName('baiyi')) { this.showDuihua(this.stepIndex, () => { this.chooseLayerShow(this.ChooseLayer, 'chooseArray') }) this.setpIndexAdd() } else if (node.getChildByName('qidongChezi') && targetNode == node.getChildByName('qidongChezi').getChildByName('qidong2')) { //开车 let changjing = node.getChildByName('场景1') let shu = node.getChildByName('shu') changjing.getComponent(cc.Animation).play() shu.getComponent(cc.Animation).play() let baiyinvzi = node.getChildByName('baiyinvzi') if (this.qidongQiChe == QIDONG.FIRST) { this.qidongQiChe = QIDONG.SECOND this.scheduleOnce(() => { this.showDuihua(this.stepIndex, () => { console.log('111111111kongtiaoBreak') node.getChildByName('kongtiaoBreak').active = false }) this.setpIndexAdd() }, 2.0) this.clearTmOut = setTimeout(() => { clearTimeout(this.clearTmOut) this.clearTmOut = null; if(this.showDuihuaIndex == 'chooseArray1'){ this.showDuihuaIndex = null } let curLayerIndex = 2 this.failShow(curLayerIndex) }, 10000); } else if (this.qidongQiChe == QIDONG.SECOND) { this.qidongQiChe = QIDONG.THIRD this.setChooseLayerHide() // baiyinvzi.active = false let changjing = node.getChildByName('场景1') let shu = node.getChildByName('shu') changjing.getComponent(cc.Animation).play() shu.getComponent(cc.Animation).play() cc.tween(baiyinvzi) .to(2.0, { opacity: 0 }) .call(() => { changjing.getComponent(cc.Animation).stop() shu.getComponent(cc.Animation).stop() this.refreCurLayerView(() => { //汽车启动 let curNode = this.layerArray[this.curLayerIndex] curNode.getChildByName('mudiMove1').getComponent(cc.Animation).play() curNode.getChildByName('mudiMove2').getComponent(cc.Animation).play() this.scheduleOnce(() => { curNode.getChildByName('mudiMove1').getComponent(cc.Animation).stop() curNode.getChildByName('mudiMove2').getComponent(cc.Animation).stop() curNode.getChildByName('殡仪馆').active = true this.showDuihua(this.stepIndex, () => { this.chooseLayerShow(this.ChooseLayer2, 'chooseArray3') }) this.setpIndexAdd() //选项 }, 6) }, 3) }) .start() } else if (this.qidongQiChe == QIDONG.THIRD) { } } else if (node.getChildByName('qidonglayer4') && targetNode == node.getChildByName('qidonglayer4').getChildByName('qidong')) { let curNode = this.layerArray[this.curLayerIndex] curNode.getChildByName('殡仪馆').active = false curNode.getChildByName('mudiMove1').getComponent(cc.Animation).play() curNode.getChildByName('mudiMove2').getComponent(cc.Animation).play() this.scheduleOnce(() => { for (let i = 0; i < curNode.getChildByName('mudiMove1').childrenCount; i++) { curNode.getChildByName('mudiMove1').children[i].active = true } for (let i = 0; i < curNode.getChildByName('mudiMove2').childrenCount; i++) { curNode.getChildByName('mudiMove1').children[i].active = true } curNode.getChildByName('mudiMove1').getComponent(cc.Animation).stop() curNode.getChildByName('mudiMove2').getComponent(cc.Animation).stop() //选项 let hongyi = curNode.getChildByName('hongyi') cc.tween(hongyi) .to(3.0, { opacity: 0 }) .delay(1.0) .call(() => { this.showDuihua(this.stepIndex, () => { this.scheduleOnce(()=>{ Game.ins.showSuccess(); },3.0) }) }) .start() }, 6) } } chooseResult(touchIndex) { console.log(this.curLayerIndex, 'this.curLayerIndex') if (Common.GameSubChooseArray.btnEffectArray) { let duihuaArray = Common.GameSubChooseArray.btnEffectArray[touchIndex] if (duihuaArray && duihuaArray.length > 0) { console.log(duihuaArray, 'duihuaArray+++===') this.showChooseDuihua(duihuaArray) } } if (this.curLayerIndex == 0) { let node = this.layerArray[this.curLayerIndex] let ludeng = node.getChildByName('ludeng') let yuanguang = node.getChildByName('远光') let dianxian = node.getChildByName('电线杆') let qidongNode = node.getChildByName('qidongNode') qidongNode.active = true if (touchIndex == 0) { //路线1 ludeng.getComponent(cc.Animation).play() this.scheduleOnce(() => { dianxian.active = true ludeng.getComponent(cc.Animation).stop() this.scheduleOnce(()=>{ Game.ins.showFailFuHuo(); },2.0) }, 3.0) } else if (touchIndex == 1) { //路线2 ludeng.getComponent(cc.Animation).play() this.scheduleOnce(() => { if (yuanguang.active == false || this.curSpeedNum < 30) { //黑屏 ludeng.getComponent(cc.Animation).stop() this.failShow(this.curLayerIndex) } else { //next this.refreCurLayerView() } }, 3.0) } } else if (this.curLayerIndex == 1) { let chooseStr = Common.GameSubChooseArray.btnArray[touchIndex] let node = this.layerArray[this.curLayerIndex] let baiyi = node.getChildByName('baiyi') let xueji = node.getChildByName('车').getChildByName('血') let black = node.getChildByName('black') let hongyi = node.getChildByName('hongyi') let naozhong2 = node.getChildByName('naozhong2') let pingbi = node.getChildByName('pingbi') pingbi.active = false if (chooseStr == '上车') { //失败 cc.tween(baiyi) .to(2, { opacity: 0 }) .call(() => { xueji.active = true baiyi.active = false this.scheduleOnce(() => { Game.ins.showFailFuHuo(); }, 2) }) .start() } else if (chooseStr == '不上车') { //换红衣 black.active = true baiyi.active = false hongyi.active = true naozhong2.active = true this.scheduleOnce(() => { black.active = false this.showDuihua(this.stepIndex) this.setpIndexAdd() }, 2.0) } else if (chooseStr == '扶进去') { let curLayerIndex = 1 this.failShow(curLayerIndex, false) } else if (chooseStr == '不扶') { let curLayerIndex = 1 this.failShow(curLayerIndex, false) } } else if (this.curLayerIndex == 2) { if (touchIndex == 0) { let curLayerIndex = 3 this.failShow(curLayerIndex, false) } else if (touchIndex == 1) { let curLayerIndex = 3 this.failShow(curLayerIndex, false) } } else if (this.curLayerIndex == 3) { if (touchIndex == 0) { let curLayerIndex = 1 this.failShow(curLayerIndex, false) } else if (touchIndex == 1) { let node = this.layerArray[this.curLayerIndex] node.getChildByName('qidonglayer4').getChildByName('qidong').active = true } } } showChooseDuihua(duihuaArray, func?: Function) { this.DuiHuaPrefab.active = true let script_: DuiHuaScript = this.DuiHuaPrefab.getComponent('DuiHuaScript') script_.setDuihuaArray('daijia',duihuaArray, func) } refreshTitle() { let title = this.titleArrayConfig[this.curLayerIndex] let titleLab = this.node.getChildByName('标题').getChildByName('lab').getComponent(cc.Label) if (titleLab.string) { titleLab.string = title } Game.ins.setGameTitle(title) } changeCurTipIndex(curVdTipIndex) { this.curVdTipIndex = curVdTipIndex //Common.subLevel = this.curVdTipIndex this.refreshTipBtn() } refreshTipBtn() { // let tipScr: GZTipBtnScript = this.GZTipBtn.getComponent('GZTipBtnScript') // tipScr.refreshTipsCurView() // let title = this.titleArrayConfig[this.curLayerIndex] // let titleLab = this.node.getChildByName('标题').getChildByName('lab').getComponent(cc.Label) // if (titleLab.string) { // titleLab.string = title // } } gameStep(touchIndex) { console.log(touchIndex, 'gameStep+11++++++++++++======') console.log(this.stepIndex, ' this.stepIndex+11++++++++++++======') if (touchIndex == this.stepIndex) { console.log(touchIndex, 'gameStep+22++++++++++++======') if (this.stepIndex == 1) { //规则一 this.showGuizeLayer() this.setpIndexAdd() } else if (this.stepIndex == 3) { // //规则2 this.showGuizeLayer() this.setpIndexAdd() } else if (this.stepIndex == 9) {//规则3 this.showGuizeLayer() this.setpIndexAdd() } } } guizeBtnLayer() { this.GuiZeLayer.active = true let script_: GuiZeLayer = this.GuiZeLayer.getComponent('GuiZeLayer') script_.refreshView() } showGuizeLayer() { this.GuiZeLayer.active = true let script_: GuiZeLayer = this.GuiZeLayer.getComponent('GuiZeLayer') script_.setGuizeArray(this.curLayerIndex) } showDuihua(stepIndex, func?: Function) { this.DuiHuaPrefab.active = true let script_: DuiHuaScript = this.DuiHuaPrefab.getComponent('DuiHuaScript') let duihuaArray = this.duihuaConfig[stepIndex] if (duihuaArray.length > 0) { script_.setDuihuaArray('daijia',duihuaArray, func) } else { this.DuiHuaPrefab.active = false if (func) { func() } } } setpIndexAdd() { this.stepIndex++ console.log(this.stepIndex, 'setpIndexAdd setpIndexAdd+++++++++++===') } failShow(curLayerIndex, isshowDuihua = true, callFunc?: Function) { console.log(curLayerIndex, 'curLayerIndex curLayerIndex+++++++++++===') let node = this.resultLayer[curLayerIndex] let renwuNode = node.getChildByName('renwuNode') renwuNode.scale = 0.01 let zhuahengBg = node.getChildByName('zhuahengBg') if (zhuahengBg) { zhuahengBg.active = false let zhuhen = zhuahengBg.getChildByName('抓痕') zhuhen.active = false } renwuNode.active = true node.active = true cc.tween(renwuNode) .to(0.3, { scale: 1 }, { easing: 'elasticOut' }) .delay(1.0) .call(() => { if (zhuahengBg) { zhuahengBg.active = true let zhuhen = zhuahengBg.getChildByName('抓痕') zhuhen.active = true zhuhen.getComponent(sp.Skeleton).setAnimation(0, 'animation', false) } if (isshowDuihua) { this.showDuihuaResult(curLayerIndex) } if (callFunc) { callFunc() } this.scheduleOnce(() => { Game.ins.showFailFuHuo(); }, 2) }) .start() } showDuihuaResult(duihuaIndex, func?: Function) { this.DuiHuaPrefab.active = true let script_: DuiHuaScript = this.DuiHuaPrefab.getComponent('DuiHuaScript') let duihuaArray = this.resultDuihuaArray[duihuaIndex] console.log(duihuaArray, 'duihuaArray+++++++++++==') script_.setDuihuaArray('daijia',duihuaArray, func) } refreCurLayerNoOpacAnim(callFunc?: Function, delayTime = 3) { let node = this.layerArray[this.curLayerIndex] cc.tween(node) .delay(1.0) .call(() => { this.curLayerIndex++ let curVdTipIndex = this.curLayerIndex + 1 this.changeCurTipIndex(curVdTipIndex) let node_1 = this.layerArray[this.curLayerIndex] node_1.active = true this.showDuihua(this.stepIndex, callFunc) this.setpIndexAdd() this.refreshTitle() node.active = false }) .start() } refreCurLayerView(callFunc?: Function, delayTime = 3) { console.log(delayTime, 'refreCurLayerView++++++++++++===') let node = this.layerArray[this.curLayerIndex] cc.tween(node) .to(delayTime, { opacity: 0 }) .delay(1.0) .call(() => { this.curLayerIndex++ console.log(this.curLayerIndex, 'refreCurLayerView this.curLayerIndex') if(this.curLayerIndex<=Common.GameSubAnswerConfigs.length-1){ Common.subLevel = this.curLayerIndex Game.ins.updateTishiBtn() } if (this.curLayerIndex == 3) { } else { let curVdTipIndex = this.curLayerIndex * 2 this.changeCurTipIndex(curVdTipIndex) } let node_1 = this.layerArray[this.curLayerIndex] node_1.active = true this.showDuihua(this.stepIndex, callFunc) this.setpIndexAdd() this.refreshTitle() node.active = false }) .start() } upSpeedClickEvent() { let node = this.layerArray[this.curLayerIndex] let chezi = node.getChildByName('车') let speedLab = chezi.getChildByName('speedLab').getComponent(cc.Label) this.curSpeedNum += 5 if (this.curSpeedNum >= 30) { this.curSpeedNum = 30 } speedLab.string = this.curSpeedNum + '' } downSpeedClickEvent() { let node = this.layerArray[this.curLayerIndex] let chezi = node.getChildByName('车') let speedLab = chezi.getChildByName('speedLab').getComponent(cc.Label) this.curSpeedNum -= 5 if (this.curSpeedNum <= 5) { this.curSpeedNum = 5 } speedLab.string = this.curSpeedNum + '' } closeMySelfClickEvent(event) { let target = event.target target.active = false } chooseLayerShow(ChooseLayerNode, chooseName) { if(ChooseLayerNode && chooseName){ this.showDuihuaIndex = chooseName this.ChooseLayerNode = ChooseLayerNode ChooseLayerNode.active = true Common.GameSubChooseArray = this.jsonData[chooseName]//DaiJiaConfig.getInstance().getGameConfig(chooseName) let script_: ChooseBtnLayer = ChooseLayerNode.getComponent('ChooseBtnLayer') script_.setChooseBtnView() } } qidongDiancheClickEvent() { //启动选择 this.chooseLayerShow(this.ChooseLayer2, 'chooseArray0') } addWenduClickEvent() { let node = this.layerArray[this.curLayerIndex] let anniu = node.getChildByName('空调钮') this.isJiangwen = false anniu.setPosition(cc.v2(47, -143)) node.getChildByName('wenduLab').getComponent(cc.Label).string = '30℃' } subWenduClickEvent(event) { let target = event.target let node = this.layerArray[this.curLayerIndex] let anniu = node.getChildByName('空调钮') let baiyinvzi = node.getChildByName('baiyinvzi') if (this.qidongQiChe != QIDONG.SECOND) { return } this.isJiangwen = true anniu.setPosition(cc.v2(-21, -143)) clearTimeout(this.clearTmOut) this.clearTmOut = null; node.getChildByName('wenduLab').getComponent(cc.Label).string = '18℃' if (!target['isclick']) { target['isclick'] = true this.scheduleOnce(() => { let baiyinvzi = node.getChildByName('baiyinvzi') let changjing = node.getChildByName('场景1') let shu = node.getChildByName('shu') changjing.getComponent(cc.Animation).stop() shu.getComponent(cc.Animation).stop() baiyinvzi.active = true this.showDuihua(this.stepIndex) this.setpIndexAdd() this.chooseLayerShow(this.ChooseLayer2, 'chooseArray2') }, 3.0) } } // update (dt) {} }