12757f0c-1bd4-49d7-b99c-b7084b7aa4b1.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. "use strict";
  2. cc._RF.push(module, '127578MG9RJ17mctwhLeqSx', 'GameCtr');
  3. // scripts/Framework/GameCtr.ts
  4. "use strict";
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var Constant_1 = require("./Constant");
  7. var CocosZ_1 = require("./CocosZ");
  8. var gameMgr_1 = require("../Game/gameMgr");
  9. /**
  10. * 游戏控制类
  11. * 实现游戏的基础逻辑
  12. */
  13. var GameCtr = /** @class */ (function () {
  14. function GameCtr() {
  15. this.curUseSkinId = -1; // 使用皮肤id
  16. this.loadProgress = 0; // 总加载进度
  17. this._loadMapPro = 0; // 地图加载进度
  18. this._totalCount = 0; // 资源总数
  19. this._compCount = 0; // 资源完成数量
  20. this._pathBack = "";
  21. this._prefabBack = null;
  22. }
  23. //游戏初始化
  24. GameCtr.prototype.init = function () {
  25. this.loadProgress = 0;
  26. this._loadMapPro = 0;
  27. this._totalCount = 0;
  28. this._compCount = 0;
  29. this.loadRes();
  30. };
  31. GameCtr.prototype.updateLoadRes = function () {
  32. this.loadProgress = (this._loadMapPro + this._compCount / this._totalCount) / 2;
  33. // 开启地图加载
  34. if (this._compCount >= this._totalCount && this._loadMapPro == 0) {
  35. this._loadMapPro = 0.01;
  36. this.loadMap();
  37. }
  38. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_UPDATE_PROGRESS, data: this.loadProgress });
  39. };
  40. GameCtr.prototype.loadRes = function () {
  41. var _this = this;
  42. // 游戏音效
  43. var mess1 = [];
  44. // 地下城音效
  45. var mess2 = [];
  46. // 地下城技能预制体
  47. var mess3 = [];
  48. // 游戏音效
  49. CocosZ_1.cocosz.getDirWithPath("audio_game", cc.AudioClip, mess1);
  50. CocosZ_1.cocosz.resMgr.loadAndCacheResArray(mess1, cc.AudioClip, null, function () {
  51. _this._compCount++;
  52. _this.updateLoadRes();
  53. });
  54. // 地下城
  55. if (6 == CocosZ_1.cocosz.gameMode) {
  56. // 音效
  57. CocosZ_1.cocosz.getDirWithPath("audio_zombie", cc.AudioClip, mess2);
  58. CocosZ_1.cocosz.resMgr.loadAndCacheResArray(mess2, cc.AudioClip, null, function () {
  59. _this._compCount++;
  60. _this.updateLoadRes();
  61. });
  62. // 预制体
  63. CocosZ_1.cocosz.getDirWithPath("prefab_zombie_skill", cc.Prefab, mess3);
  64. CocosZ_1.cocosz.resMgr.loadAndCacheResArray(mess3, cc.Prefab, null, function () {
  65. _this._compCount++;
  66. _this.updateLoadRes();
  67. });
  68. }
  69. // 资源总数
  70. this._totalCount = mess1.length + mess2.length + mess3.length;
  71. };
  72. GameCtr.prototype.loadMap = function () {
  73. var _this = this;
  74. var path = "maps/mapzombie";
  75. // 释放地图资源
  76. if (this._pathBack != path && this._prefabBack && this._prefabBack.isValid) {
  77. cc.assetManager.releaseAsset(this._prefabBack);
  78. }
  79. // 加载地图
  80. CocosZ_1.cocosz.resMgr.loadRes(path, cc.Prefab, (function (cur, total) {
  81. if (cur / total > _this._loadMapPro) {
  82. _this._loadMapPro = cur / total;
  83. }
  84. if (_this._loadMapPro > 0.99)
  85. _this._loadMapPro = 0.99;
  86. _this.updateLoadRes();
  87. }), (function (err, res) {
  88. if (err) {
  89. console.log(err);
  90. CocosZ_1.cocosz.sceneMgr.loadScene("Home", (function () {
  91. CocosZ_1.cocosz.uiMgr.openPage(Constant_1.PageName.UIHomePage);
  92. }));
  93. }
  94. else {
  95. _this._pathBack = path;
  96. _this._prefabBack = res;
  97. gameMgr_1.gameMgr.map = cc.instantiate(res);
  98. gameMgr_1.gameMgr.initPos();
  99. gameMgr_1.gameMgr.mapSize = gameMgr_1.gameMgr.map.getContentSize();
  100. gameMgr_1.gameMgr.node.addChild(gameMgr_1.gameMgr.map, -5);
  101. _this._loadMapPro = 1;
  102. _this.updateLoadRes();
  103. }
  104. }));
  105. };
  106. return GameCtr;
  107. }());
  108. exports.default = GameCtr;
  109. cc._RF.pop();