import { RichData } from "../datas/RichData"; import { WealthData } from "../datas/WealthData"; import TransitNode from "../prefabs/TransitNode"; import MyExtends from "../tools/MyExtends"; import GameM, { AUDIO_TYPE } from "./GameM"; import UiM from "./UiM"; export class GameController { //游戏控制类 private static _ins: GameController = null; public static get Ins(): GameController { if (this._ins == null) { this._ins = new GameController(); } return this._ins; } private canvas: cc.Node = null; private gameCamera: cc.Node = null; get Canvas() { if (this.canvas == null) { this.canvas = cc.find("Canvas"); } return this.canvas; } get GameCamera() { if (this.gameCamera == null) { this.gameCamera = cc.find("Canvas/MoveCamera"); } return this.gameCamera; } transitNode: TransitNode = null; constructor() { if (this.canvas == null) { this.canvas = cc.find("Canvas"); } if (this.gameCamera == null) { this.gameCamera = cc.find("Canvas/MoveCamera"); } } Destroy() { this.canvas = null; this.transitNode = null; this.gameCamera = null; GameController._ins = null; } /**获取节点世界坐标 * @param target 需要转化为世界坐标的节点 */ GetWorldPos(target: cc.Node) { return MyExtends.convetOtherNodeSpaceAR(target, this.Canvas); } /** * 显示天赋详情 弃用 * @param mateid 伙伴id * @param talentid 天赋id */ DisplayTalentDetaile(mateid: number, talentid: number) { if (this.canvas == null) { this.canvas = cc.find("Canvas"); } } /**播放普通过场动画 * @param callback 回调函数 */ async PlayNorTransitAni(callback: Function = null) { if (this.transitNode == null) { if (this.canvas == null) { this.canvas = cc.find("Canvas"); } let copy = cc.instantiate(cc.loader.getRes("prefabs/TransitNode")); copy.parent = this.canvas; this.transitNode = copy.getComponent(TransitNode); } this.transitNode.PlayNorTransitAni(callback); } /**播放过场动画 与PlayCloseTransitAniForHttp配合使用*/ PlayTransitAniForHttp() { if (this.transitNode == null) { if (this.canvas == null) { this.canvas = cc.find("Canvas"); } let copy = cc.instantiate(cc.loader.getRes("prefabs/TransitNode")); copy.parent = this.canvas; this.transitNode = copy.getComponent(TransitNode); } this.transitNode.PlayTransitAniForHttp(); } /**关闭过场动画 与PlayTransitAniForHttp配合使用 * @param callback 回调函数 * */ PlayCloseTransitAniForHttp(callback = null) { if (this.transitNode == null) { if (this.canvas == null) { this.canvas = cc.find("Canvas"); } let copy = cc.instantiate(cc.loader.getRes("prefabs/TransitNode")); copy.parent = this.canvas; this.transitNode = copy.getComponent(TransitNode); } this.transitNode.PlayCloseTransitAniForHttp(callback); } Shock(time = 500) { //if (cc.sys.os == cc.sys.OS_ANDROID) { // jsb.reflection.callStaticMethod("org/cocos2dx/javascript/ToolHelp", "vibrate", "(I)V", time); //} } PlayShock(target: cc.Node, pos: cc.Vec2) { target.runAction( //cc.repeatForever( cc.sequence( cc.moveTo(0.02, cc.v2(pos.x + 5, pos.y + 7)), cc.moveTo(0.02, cc.v2(pos.x + -6, pos.y + 7)), cc.moveTo(0.02, cc.v2(pos.x + -13, pos.y + 3)), cc.moveTo(0.02, cc.v2(pos.x + 3, pos.y + -6)), cc.moveTo(0.02, cc.v2(pos.x + -5, pos.y + 5)), cc.moveTo(0.02, cc.v2(pos.x + 2, pos.y + -8)), cc.moveTo(0.02, cc.v2(pos.x + -8, pos.y + -10)), cc.moveTo(0.02, cc.v2(pos.x + 3, pos.y + 10)), cc.moveTo(0.02, cc.v2(pos.x + 0, pos.y + 0)) ) //) ); } /**移动相机 * @param targetpos 目标坐标 * @param time 时间 */ MoveCamera(targetpos: cc.Vec2, time: number) { console.log("Camera:::", this.GameCamera); cc.tween(this.GameCamera) .to(time, { position: targetpos }) .call(() => { }) .start(); } /** * 切换音效 离开界面 * @param exitType 即将要关闭的界面 1 判断是否有财神 2 判断是否有五福音效 3 离开大富翁 */ SwitchAudio(exitType: number) { switch (exitType) { case 1: if (WealthData.Ins.isTriggerWealth) { GameM.audioM.playMateEffect(AUDIO_TYPE.wealthbgm, true); } else { if (RichData.Ins.isOpenRichPanel) { GameM.audioM.playMateEffect(AUDIO_TYPE.sutrabgm, true); } else { GameM.audioM.setResumeMusic(); if (GameM.audioM.IsMatePlayingEffect()) GameM.audioM.stopMateEffect(); } } break; case 2: if (UiM.Instance.redPackageNode.type != 4) { GameM.audioM.setResumeMusic(); if (GameM.audioM.IsMatePlayingEffect()) GameM.audioM.stopMateEffect(); } break; case 3: if (UiM.Instance.redPackageNode.node.active && UiM.Instance.redPackageNode.type == 4) { GameM.audioM.playMateEffect(AUDIO_TYPE.fiveluckbgm, true); } else { if (WealthData.Ins.isTriggerWealth) { GameM.audioM.playMateEffect(AUDIO_TYPE.wealthbgm, true); } else { GameM.audioM.setResumeMusic(); if (GameM.audioM.IsMatePlayingEffect()) GameM.audioM.stopMateEffect(); } } break; } } }