GameController.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import { RichData } from "../datas/RichData";
  2. import { WealthData } from "../datas/WealthData";
  3. import TransitNode from "../prefabs/TransitNode";
  4. import MyExtends from "../tools/MyExtends";
  5. import GameM, { AUDIO_TYPE } from "./GameM";
  6. import UiM from "./UiM";
  7. export class GameController {
  8. //游戏控制类
  9. private static _ins: GameController = null;
  10. public static get Ins(): GameController {
  11. if (this._ins == null) {
  12. this._ins = new GameController();
  13. }
  14. return this._ins;
  15. }
  16. private canvas: cc.Node = null;
  17. private gameCamera: cc.Node = null;
  18. get Canvas() {
  19. if (this.canvas == null) {
  20. this.canvas = cc.find("Canvas");
  21. }
  22. return this.canvas;
  23. }
  24. get GameCamera() {
  25. if (this.gameCamera == null) {
  26. this.gameCamera = cc.find("Canvas/MoveCamera");
  27. }
  28. return this.gameCamera;
  29. }
  30. transitNode: TransitNode = null;
  31. constructor() {
  32. if (this.canvas == null) {
  33. this.canvas = cc.find("Canvas");
  34. }
  35. if (this.gameCamera == null) {
  36. this.gameCamera = cc.find("Canvas/MoveCamera");
  37. }
  38. }
  39. Destroy() {
  40. this.canvas = null;
  41. this.transitNode = null;
  42. this.gameCamera = null;
  43. GameController._ins = null;
  44. }
  45. /**获取节点世界坐标
  46. * @param target 需要转化为世界坐标的节点
  47. */
  48. GetWorldPos(target: cc.Node) {
  49. return MyExtends.convetOtherNodeSpaceAR(target, this.Canvas);
  50. }
  51. /**
  52. * 显示天赋详情 弃用
  53. * @param mateid 伙伴id
  54. * @param talentid 天赋id
  55. */
  56. DisplayTalentDetaile(mateid: number, talentid: number) {
  57. if (this.canvas == null) {
  58. this.canvas = cc.find("Canvas");
  59. }
  60. }
  61. /**播放普通过场动画
  62. * @param callback 回调函数
  63. */
  64. async PlayNorTransitAni(callback: Function = null) {
  65. if (this.transitNode == null) {
  66. if (this.canvas == null) {
  67. this.canvas = cc.find("Canvas");
  68. }
  69. let copy = cc.instantiate(cc.loader.getRes("prefabs/TransitNode"));
  70. copy.parent = this.canvas;
  71. this.transitNode = copy.getComponent(TransitNode);
  72. }
  73. this.transitNode.PlayNorTransitAni(callback);
  74. }
  75. /**播放过场动画 与PlayCloseTransitAniForHttp配合使用*/
  76. PlayTransitAniForHttp() {
  77. if (this.transitNode == null) {
  78. if (this.canvas == null) {
  79. this.canvas = cc.find("Canvas");
  80. }
  81. let copy = cc.instantiate(cc.loader.getRes("prefabs/TransitNode"));
  82. copy.parent = this.canvas;
  83. this.transitNode = copy.getComponent(TransitNode);
  84. }
  85. this.transitNode.PlayTransitAniForHttp();
  86. }
  87. /**关闭过场动画 与PlayTransitAniForHttp配合使用
  88. * @param callback 回调函数
  89. * */
  90. PlayCloseTransitAniForHttp(callback = null) {
  91. if (this.transitNode == null) {
  92. if (this.canvas == null) {
  93. this.canvas = cc.find("Canvas");
  94. }
  95. let copy = cc.instantiate(cc.loader.getRes("prefabs/TransitNode"));
  96. copy.parent = this.canvas;
  97. this.transitNode = copy.getComponent(TransitNode);
  98. }
  99. this.transitNode.PlayCloseTransitAniForHttp(callback);
  100. }
  101. Shock(time = 500) {
  102. //if (cc.sys.os == cc.sys.OS_ANDROID) {
  103. // jsb.reflection.callStaticMethod("org/cocos2dx/javascript/ToolHelp", "vibrate", "(I)V", time);
  104. //}
  105. }
  106. PlayShock(target: cc.Node, pos: cc.Vec2) {
  107. target.runAction(
  108. //cc.repeatForever(
  109. cc.sequence(
  110. cc.moveTo(0.02, cc.v2(pos.x + 5, pos.y + 7)),
  111. cc.moveTo(0.02, cc.v2(pos.x + -6, pos.y + 7)),
  112. cc.moveTo(0.02, cc.v2(pos.x + -13, pos.y + 3)),
  113. cc.moveTo(0.02, cc.v2(pos.x + 3, pos.y + -6)),
  114. cc.moveTo(0.02, cc.v2(pos.x + -5, pos.y + 5)),
  115. cc.moveTo(0.02, cc.v2(pos.x + 2, pos.y + -8)),
  116. cc.moveTo(0.02, cc.v2(pos.x + -8, pos.y + -10)),
  117. cc.moveTo(0.02, cc.v2(pos.x + 3, pos.y + 10)),
  118. cc.moveTo(0.02, cc.v2(pos.x + 0, pos.y + 0))
  119. )
  120. //)
  121. );
  122. }
  123. /**移动相机
  124. * @param targetpos 目标坐标
  125. * @param time 时间
  126. */
  127. MoveCamera(targetpos: cc.Vec2, time: number) {
  128. console.log("Camera:::", this.GameCamera);
  129. cc.tween(this.GameCamera)
  130. .to(time, { position: targetpos })
  131. .call(() => {
  132. })
  133. .start();
  134. }
  135. /**
  136. * 切换音效 离开界面
  137. * @param exitType 即将要关闭的界面 1 判断是否有财神 2 判断是否有五福音效 3 离开大富翁
  138. */
  139. SwitchAudio(exitType: number) {
  140. switch (exitType) {
  141. case 1:
  142. if (WealthData.Ins.isTriggerWealth) {
  143. GameM.audioM.playMateEffect(AUDIO_TYPE.wealthbgm, true);
  144. } else {
  145. if (RichData.Ins.isOpenRichPanel) {
  146. GameM.audioM.playMateEffect(AUDIO_TYPE.sutrabgm, true);
  147. } else {
  148. GameM.audioM.setResumeMusic();
  149. if (GameM.audioM.IsMatePlayingEffect())
  150. GameM.audioM.stopMateEffect();
  151. }
  152. }
  153. break;
  154. case 2:
  155. if (UiM.Instance.redPackageNode.type != 4) {
  156. GameM.audioM.setResumeMusic();
  157. if (GameM.audioM.IsMatePlayingEffect())
  158. GameM.audioM.stopMateEffect();
  159. }
  160. break;
  161. case 3:
  162. if (UiM.Instance.redPackageNode.node.active && UiM.Instance.redPackageNode.type == 4) {
  163. GameM.audioM.playMateEffect(AUDIO_TYPE.fiveluckbgm, true);
  164. } else {
  165. if (WealthData.Ins.isTriggerWealth) {
  166. GameM.audioM.playMateEffect(AUDIO_TYPE.wealthbgm, true);
  167. } else {
  168. GameM.audioM.setResumeMusic();
  169. if (GameM.audioM.IsMatePlayingEffect())
  170. GameM.audioM.stopMateEffect();
  171. }
  172. }
  173. break;
  174. }
  175. }
  176. }