mainManager.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { AudioManager } from "../configData/AudioManager";
  2. import GameConfig from "../configData/GameConfig";
  3. import gameManger from "../game/UIFace/gameManger";
  4. import viewComtent from "../game/UIFace/viewComtent";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class mainManager extends cc.Component {
  8. @property(cc.Node)
  9. private view: cc.Node = null;
  10. /**当前最新关卡 */
  11. @property(cc.Node)
  12. private nowLevel: cc.Node = null;
  13. /**钻石数量 */
  14. @property(cc.Label)
  15. private dialabel: cc.Label = null;
  16. /**总星星数量 */
  17. @property(cc.Label)
  18. private starlabel: cc.Label = null;
  19. /**剩余星星数量 */
  20. @property(cc.Label)
  21. private nowstarlabel: cc.Label = null;
  22. private allTapBtn: cc.Node[] = [];
  23. private scroll: cc.ScrollView = null;
  24. public static instance: mainManager = null;
  25. protected onLoad() {
  26. mainManager.instance = this;
  27. this.node.opacity = 255;
  28. let hhh = cc.winSize.height * (1920 / cc.winSize.width);
  29. this.view.setContentSize(1920, hhh);
  30. this.scroll = this.node.getComponent(cc.ScrollView);
  31. this.scroll.scrollToOffset(cc.v2());
  32. localStorage.clear();
  33. this.initStorage();
  34. this.initData();
  35. this.initStartBtn();
  36. this.nowLevel.on(cc.Node.EventType.TOUCH_START, function () {
  37. this.startgame(GameConfig.instance().storageData.level);
  38. }, this);
  39. this.preLoadSprite();
  40. }
  41. /**钻石星星数量 */
  42. public initData() {
  43. this.dialabel.string = GameConfig.instance().storageData.Diamond.toString();
  44. this.starlabel.string = GameConfig.instance().storageData.TotalStarNum.toString();
  45. this.nowstarlabel.string = GameConfig.instance().storageData.starNum.toString();
  46. }
  47. /**返回主界面刷新 */
  48. public backInit() {
  49. for (let i = 0; i < this.allTapBtn.length; i++) {
  50. const element = this.allTapBtn[i];
  51. element.destroy();
  52. }
  53. this.allTapBtn = [];
  54. cc.director.resume();
  55. cc.director.getScheduler().setTimeScale(1);
  56. this.initData();
  57. this.initStartBtn();
  58. AudioManager.palyAudio(1);
  59. }
  60. /**初始化存储数据 */
  61. private initStorage() {
  62. let sore = GameConfig.instance().getStorage();
  63. if (sore) {
  64. GameConfig.instance().storageData = sore;
  65. }
  66. else {
  67. GameConfig.instance().setStorage();
  68. }
  69. }
  70. /**开始按钮加载 */
  71. private initStartBtn() {
  72. let self = this;
  73. let storeLevel = GameConfig.instance().storageData.level;
  74. let posArr = [cc.v2(801, 454), cc.v2(507, 463), cc.v2(423, 292), cc.v2(255, 451), cc.v2(127, 286), cc.v2(-12, 376), cc.v2(-86, 226),
  75. cc.v2(-332, 418), cc.v2(-634, 433), cc.v2(-877, 274), cc.v2(-591, 124), cc.v2(-713, -164), cc.v2(-524, -373),
  76. cc.v2(-256, -374), cc.v2(-37, -298), cc.v2(264, -329), cc.v2(580, -357), cc.v2(878, -284)];
  77. if (storeLevel > 1) {
  78. cc.resources.load("prefabs/level_last", cc.Prefab, function (err, prefab: cc.Prefab) {
  79. for (let i = 0; i < storeLevel - 1; i++) {
  80. const element = posArr[i];
  81. var newNode = cc.instantiate(prefab);
  82. self.nowLevel.parent.addChild(newNode, 1);
  83. newNode.setPosition(element);
  84. newNode.on(cc.Node.EventType.TOUCH_START, function () {
  85. self.startgame(i + 1);
  86. }, this);
  87. let star = newNode.getChildByName("star_" + GameConfig.instance().storageData.levelStar[i]);
  88. star.opacity = 255;
  89. self.allTapBtn.push(newNode);
  90. }
  91. });
  92. }
  93. this.nowLevel.setPosition(posArr[storeLevel - 1]);
  94. }
  95. /**天赋界面 */
  96. private openTalant() {
  97. AudioManager.palyAudio(6);
  98. let self = this;
  99. cc.resources.load("prefabs/talantNode", cc.Prefab, function (err, prefab: cc.Prefab) {
  100. var newNode = cc.instantiate(prefab);
  101. self.node.addChild(newNode, 10);
  102. newNode.setPosition(0, 0);
  103. });
  104. }
  105. /**设置界面 */
  106. private openSetFace() {
  107. AudioManager.palyAudio(6);
  108. let self = this;
  109. }
  110. /**开始游戏 */
  111. private startgame(level: number) {
  112. AudioManager.palyAudio(6);
  113. GameConfig.instance().palyLevel = level;
  114. this.loadLevelIntro();
  115. }
  116. /**加载关卡介绍界面 */
  117. public loadLevelIntro() {
  118. let self = this;
  119. cc.resources.load("prefabs/LevelIntro", cc.Prefab, function (err, prefab: cc.Prefab) {
  120. var newNode = cc.instantiate(prefab);
  121. self.node.addChild(newNode, 1);
  122. newNode.setPosition(cc.v2(0, 0));
  123. });
  124. }
  125. private preLoadSprite() {
  126. cc.resources.load("talant/itembg", cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  127. });
  128. for (let i = 0; i < 30; i++) {
  129. cc.resources.load("talant/talant_skill_" + (i + 1), cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  130. });
  131. }
  132. }
  133. }