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 WordGameBaseComponent from "../../../FrameWork/Base/WordGameBaseComptent"; import DaDianScript from "../../../FrameWork/Base/DaDianScript"; import Game from "../../../Scripts/Game"; import BuYaoLangFeiConfig from "./BuYaoLangFeiConfig"; const { ccclass, property } = cc._decorator; @ccclass export default class BuYaoLangFei extends WordGameBaseComponent { @property(cc.Node) maskNode:cc.Node = null @property(cc.Node) xiaoHai:cc.Node = null @property(cc.Node) shuTouchArea:cc.Node = null @property(cc.Node) xiaoHaiShuNode:cc.Node = null @property(cc.Node) juZi:cc.Node = null @property(cc.Node) maTong:cc.Node = null @property(cc.Node) xiaoHaiMaTongNode:cc.Node = null @property(cc.Node) maTongGai:cc.Node = null @property(cc.Node) xiaoPang:cc.Node = null @property(cc.Node) xiaoPangZuoXia:cc.Node = null @property(cc.Node) shaFa:cc.Node = null @property(cc.Node) jiaoPen:cc.Node = null @property(cc.Node) zhuSpine:cc.Node = null @property(cc.Node) shouJiTouchArea:cc.Node = null @property(cc.Node) shouJiNode:cc.Node = null //文本配置 titleArrayConfig: string[] = []; duihuaArrayConfig: any[] = []; // duihuaArray_Ying: any[] = []; // duihuaArray_PingJu: any[] = []; // duihuaArray_Shu: any[] = []; //初始化节点 curFinishNum:number = 0 curZIndex:number = 100; isXiaoHaiLaShi:boolean = false isXiTuoBu:boolean = false isXiJiaoPenYouShui:boolean = true isShouJiFinish:boolean = false bundle = null start() { this.bundle = Common5.gameConfig.zmGameConfig[Common5.selectGameNum].bundle // Common5.playMusicCustom('WordGame','baoxiaoGame/fuqiyouxi/sound/背景' ); super.start(); DaDianScript.userEnterDaDian(); this.initParameters(); this.initComponent(); this.initView() } //初始化参数 initParameters() { EventMgr.onEvent_custom(ryw_Event.timeOut, (tab) => { this.endGameView(0); }, this); // this.fireNodeInfoArray = []; this.titleArrayConfig = BuYaoLangFeiConfig.getInstance().getGameConfig('titleArray') as string[]; this.duihuaArrayConfig = BuYaoLangFeiConfig.getInstance().getGameConfig('duihuaArray') as any[]; // this.duihuaArray_Ying = BuYaoLangFeiConfig.getInstance().getGameConfig('duihuaArray_Ying') as any[]; // this.duihuaArray_PingJu = BuYaoLangFeiConfig.getInstance().getGameConfig('duihuaArray_PingJu') as any[]; // this.duihuaArray_Shu = BuYaoLangFeiConfig.getInstance().getGameConfig('duihuaArray_Shu') as any[]; Common.Type = 0; Common.subLevel = 0; Common.GameSubTipConfigs = BuYaoLangFeiConfig.getInstance().getGameConfig('tipsArray'); Common.GameSubAnswerConfigs = BuYaoLangFeiConfig.getInstance().getGameConfig('answersArray'); EventMgr.onEvent_custom(ryw_Event.NormalTouchMoveCheck, (data_) => { this.normalTouchCheckCallback(data_.targetNode); }, this); } initView(){ //初始对话 cc.tween(this.node) .delay(1) .call(()=>{ this.showQiPao(this.duihuaArrayConfig[0]) }) .delay(5) .call(()=>{ this.showQiPao(this.duihuaArrayConfig[1]) }) .delay(2) .call(()=>{ this.maskNode.active = false this.initTouchEvent(this.xiaoHai,this.shuTouchArea,this.maTong) this.initTouchEvent(this.maTongGai,this.xiaoHai) this.initTouchEvent(this.jiaoPen,this.maTong) this.initTouchEvent(this.shouJiTouchArea,null) }) .start() } initTouchEvent(node, checkNode1, checkNode2?) { var attrs = { checkNode1: checkNode1, checkNode2: checkNode2, recoveposi: node.getPosition(),//初始位置 recoveparent: node.parent, scr: this //脚本 }; node.attr(attrs); this.openTouchEvent(node) } openTouchEvent(node) { node.on(cc.Node.EventType.TOUCH_START, this.touchStartNode, this) node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this) node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this) node.on(cc.Node.EventType.TOUCH_END, this.touchEndNode, this) } closeTouchEvent(node: cc.Node) { node.off(cc.Node.EventType.TOUCH_START, this.touchStartNode, this) node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this) node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this) node.off(cc.Node.EventType.TOUCH_END, this.touchEndNode, this) } touchStartNode(event) { let target = event.target; let posi = event.getLocation()//世界坐标 posi = target.parent.convertToNodeSpaceAR(posi) target.setPosition(posi) Common5.playEffect("点击音效"); // EventMgr.emitEvent_custom(ryw_Event.openBGMove, { open: false }); if(event.target == this.shouJiTouchArea && !this.isShouJiFinish){ this.shouJiNode.active = true } } touchMoveNode(event) { if(event.target == this.shouJiTouchArea){ return } let posi = event.getLocation()//世界坐标 let target = event.target posi = target.parent.convertToNodeSpaceAR(posi) target.setPosition(posi) } touchEndNode(event) { if(event.target == this.shouJiTouchArea){ return } let target = event.target; let checkNode1 = target.checkNode1; let checkNode2 = target.checkNode2; if (Common5.checkIntersectsBox(target, checkNode1)) { //橘子树拉屎 if(checkNode1 == this.shuTouchArea && !this.isXiaoHaiLaShi){ Common5.playEffectCustom(this.bundle, 'sound/拉屎'); this.closeTouchEvent(target) this.isXiaoHaiLaShi = true target.setPosition(this.xiaoHaiShuNode.getPosition()) this.xiaoHai.getChildByName('xiaoHaiSpine').getComponent(sp.Skeleton).setAnimation(0,"xiaohailashi",false) this.scheduleOnce(()=>{ this.showQiPao(this.duihuaArrayConfig[7]) this.juZi.active = true target.setPosition(target["recoveposi"]) this.xiaoHai.getChildByName('xiaoHaiSpine').getComponent(sp.Skeleton).setAnimation(0,"xiaohaizhengchang",false) this.countFinishNum() },2) return //马桶盖 }else if(target == this.maTongGai && this.isXiaoHaiLaShi){ this.showQiPao(this.duihuaArrayConfig[9]) target.active = false this.closeTouchEvent(target) this.xiaoHai.getChildByName('xiaoHaiSpine').getComponent(sp.Skeleton).setAnimation(0,"xiaohaimatong",false) this.countFinishNum() //小胖坐沙发 }else if(target == this.xiaoPang){ target.active = false this.closeTouchEvent(target) this.xiaoPangZuoXia.active = true this.showQiPao(this.duihuaArrayConfig[11]) this.countFinishNum() //倒洗脚水 }else if(target == this.jiaoPen){ Common5.playEffectCustom(this.bundle, 'sound/泼水声'); this.isXiJiaoPenYouShui = false this.closeTouchEvent(target) this.maTong.getChildByName('maTongSpine').getComponent(sp.Skeleton).setAnimation(0,'matong',false) this.jiaoPen.getChildByName('jiaoPenSpine').getComponent(sp.Skeleton).setAnimation(0,'没水',false) if(!this.isXiTuoBu){ this.showQiPao(this.duihuaArrayConfig[8]) this.endGameView(0) }else{ this.showQiPao(this.duihuaArrayConfig[13]) this.countFinishNum() } } }else if (checkNode2 && Common5.checkIntersectsBox(target, checkNode2)) { //马桶拉屎 if(checkNode2 == this.maTong && !this.isXiaoHaiLaShi){ Common5.playEffectCustom(this.bundle, 'sound/拉屎'); this.closeTouchEvent(target) this.isXiaoHaiLaShi = true target.setPosition(this.xiaoHaiMaTongNode.getPosition()) this.xiaoHai.getChildByName('xiaoHaiSpine').getComponent(sp.Skeleton).setAnimation(0,"xiaohailashi",false) this.scheduleOnce(()=>{ this.showQiPao(this.duihuaArrayConfig[8]) // this.maTong.getChildByName('maTongSpine').getComponent(sp.Skeleton).setAnimation(0,'chouqi',true) target.setPosition(target["recoveposi"]) this.xiaoHai.getChildByName('xiaoHaiSpine').getComponent(sp.Skeleton).setAnimation(0,"xiaohaizhengchang",false) this.endGameView(0) },2) return } } if (target["recoveposi"]) { target.setPosition(target["recoveposi"]) } } //初始化组件 initComponent() { Game.ins.setGameTitle(this.titleArrayConfig[0]) // let lab = this.node.getChildByName("标题").getChildByName("lab"); // lab.getComponent(cc.Label).string = this.titleArrayConfig[0]; // this.touchRoleNode.active = false; // this.refreshSchedule(); this.scheduleOnce(this.setTimeNodePos, 0); } setTimeNodePos() { // let timeNode = this.node.getChildByName("timeNode") // let addtimeNode = this.node.getChildByName("tipsBtn").getChildByName("addtimeNode") // let timeNodePos = timeNode.getPosition() // let addtimeNodePos = addtimeNode.getPosition() // Game.ins.setTimePos(timeNodePos.x, timeNodePos.y) // Game.ins.setTimeScale(0.7) // Game.ins.setTimeBtnPos(addtimeNodePos.x, addtimeNodePos.y) } showQiPao(curLog,func?) { console.log("curLog==", curLog); Common5.playEffectCustom(this.bundle, curLog.effectUrl); let qiPao = this.node.getChildByName("qiPao").getChildByName("qiPao_" + curLog.qiPaoPos); qiPao.stopAllActions() qiPao.getChildByName("str").getComponent(cc.Label).string = curLog.dialogStr qiPao.active = true qiPao.scale = 0 cc.tween(qiPao) .to(0.2, { scale: 1 }) .delay(curLog.delayTime) .call(() => { qiPao.active = false if (func) { func(); } }) .start(); } endGameView(touchIndex) { Game.ins.stopTime(); this.scheduleOnce(()=>{ // this.node.getChildByName("mask").active = true; if (touchIndex == 0) { Game.ins.showFail(); } else { Game.ins.showSuccess(); } },4) } normalTouchCheckCallback(targetNode){ if (targetNode.name == "黑袜 副本") { this.countFinishNum() this.showQiPao(this.duihuaArrayConfig[2]) }else if (targetNode.name == "拖把" && !this.isXiTuoBu) { this.isXiTuoBu = true this.countFinishNum() this.showQiPao(this.duihuaArrayConfig[3]) }else if (targetNode.name == "肉") { if(targetNode.checkNode.name == 'man'){ targetNode.active = true; this.showQiPao(this.duihuaArrayConfig[5]) }else if(targetNode.checkNode.name == 'woman'){ targetNode.active = true; this.showQiPao(this.duihuaArrayConfig[4]) }else if(targetNode.checkNode.name == 'child'){ targetNode.active = false; this.showQiPao(this.duihuaArrayConfig[6]) this.countFinishNum() } } } countFinishNum(){ this.curFinishNum++ console.log('当前完成数==',this.curFinishNum) if(this.curFinishNum == 3){ this.xiaoPangEnterRoom() } if(this.curFinishNum == 8){ this.endGameView(1) } } xiaoPangEnterRoom(){ cc.tween(this.xiaoPang) .to(2.5,{x:170}) .delay(1) .call(()=>{ this.showQiPao(this.duihuaArrayConfig[10]) }) .delay(2) .call(()=>{ this.initTouchEvent(this.xiaoPang,this.shaFa) }) .start() } onBtnClosePhone(){ Common5.playEffect("点击音效"); this.shouJiNode.active = false } onBtnBuy(){ Common5.playEffect("点击音效"); this.shouJiNode.active = false this.isShouJiFinish = true this.zhuSpine.active = true this.showQiPao(this.duihuaArrayConfig[12]) this.countFinishNum() } }