ba785e5a-d8db-44fd-bea8-1a5887c1f355.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. "use strict";
  2. cc._RF.push(module, 'ba7855a2NtE/b6oGliHwfNV', 'gameMgr');
  3. // scripts/Game/gameMgr.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. exports.gameMgr = void 0;
  26. var CocosZ_1 = require("../Framework/CocosZ");
  27. var Utils_1 = require("../../common-plugin/Scripts/Utils");
  28. var Constant_1 = require("../Framework/Constant");
  29. var UpgradeMgr_1 = require("./UpgradeMgr");
  30. var YZ_Constant_1 = require("../../common-plugin/Scripts/YZ_Constant");
  31. var ZombieBase_1 = require("./ZombieBase");
  32. var ATAndroidJS2_1 = require("../ATAndroidJS2");
  33. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  34. //tag:{0:攻击范围,1:玩家身体,2:玩家腿部 6,减速,7,毒区 11:墙,12:道具,13:武器,14:草,15:房子,16:物资箱, 17:海水, 18:升级仓, 19:旗台}
  35. exports.gameMgr = null;
  36. var GameMgr = /** @class */ (function (_super) {
  37. __extends(GameMgr, _super);
  38. function GameMgr() {
  39. var _this = _super !== null && _super.apply(this, arguments) || this;
  40. _this.nodePoolObj = {};
  41. _this.canSHowGameBanner = true;
  42. _this.tipLayer = null;
  43. _this.setMapTs = null;
  44. _this.playerTs = null;
  45. _this.uiGamePage = null;
  46. _this.moveArea = null;
  47. _this.yaogan = null;
  48. _this.BtnBullet = null;
  49. _this.posObj = {};
  50. // 躲猫猫模式
  51. _this.dmmArr = [];
  52. _this.red = null;
  53. _this.hpTip = null;
  54. _this.effect_fire = null;
  55. _this.effect_hit = null;
  56. _this.itemList = [];
  57. _this.itemEffect = [];
  58. _this.spark = null;
  59. _this.blood = null;
  60. _this.testPoint = null;
  61. _this.player = null;
  62. _this.jiaoyin = null;
  63. _this.fj = null;
  64. _this.fjTip = null;
  65. _this.mainCamereRootNode = null;
  66. _this.mainCamera = null;
  67. // LIFE-CYCLE CALLBACKS:
  68. _this.atk = null;
  69. _this.safeCenter = cc.v2(0, 0);
  70. _this.redCircle = null;
  71. _this.redCircle2 = null;
  72. // mask: cc.Node = null;
  73. // maskMtl: cc.Material = null;
  74. _this.mapSize = cc.winSize;
  75. _this.miniMapSize = null;
  76. _this.btnSkill = null;
  77. _this.btnSkillAd = null;
  78. _this.rangedWeaponMess = null;
  79. _this.rangedWeaponAdMess = null;
  80. _this.ammo = null;
  81. _this.ammoAd = null;
  82. _this.kt = null;
  83. _this.model6_touxiang = null;
  84. _this.model6_btnShuxing = null;
  85. _this.model6_shuxing = null;
  86. _this.model6_jingyanBar = null;
  87. _this.model6_levelLabel = null;
  88. _this.model6_skillScrollView = null;
  89. _this.model6_skillScrollView_content = null;
  90. _this.model6_skillScrollView_item = null;
  91. _this.model6_timeLabel = null;
  92. _this.model6_ts = null;
  93. _this.model6_bossBar = null;
  94. _this.timeStr = "";
  95. _this.totalNum = 0;
  96. _this.deathNum = 0;
  97. _this.playerRank = 1;
  98. //通关条件: 1击败所有敌人 2击败boss 3抵达撤离点
  99. _this.passCondition = 1;
  100. _this.bossName = "";
  101. _this.map = null;
  102. _this.startPoint = null;
  103. _this.atkRange = null;
  104. _this.curTime = 0;
  105. _this.timeLabel = null;
  106. _this.snow = null;
  107. _this.qlzc = null;
  108. _this.GameTime = 0;
  109. _this.isGameStart = false;
  110. _this.posList = [];
  111. _this.boss_border = null;
  112. _this.zombieTime = 0;
  113. _this.zombieCurNum = 0;
  114. _this.zombieMaxNum = 0;
  115. _this.zombieLength = 2;
  116. _this.zombieArr = ["zombie_basic", "zombie_run", "zombie_drum", "zombie_jump", "zombie_bomb", "zombie_tank", "zombie_poison"];
  117. _this.bossArr = ["boss1", "boss2", "boss3", "boss4", "boss11", "boss5", "boss12", "boss6", "boss7", "boss8", "boss9", "boss10", "boss13"];
  118. _this.boss2Arr = [];
  119. /** 获取僵尸生成坐标 */
  120. _this._recursionCount = 0;
  121. _this.lastTime = 0;
  122. _this.safeTime = 40;
  123. _this.startPos = null;
  124. _this.isUp = false;
  125. _this.isDown = false;
  126. _this.isLeft = false;
  127. _this.isRight = false;
  128. _this.isPre = true;
  129. _this.clipNameArr = {};
  130. _this.isFail = false;
  131. _this.isWin = false;
  132. _this.isRevive = false;
  133. /**
  134. * 震屏
  135. * @param dis 范围
  136. * @param times 次数
  137. * @param isVibrate 是否震动
  138. * @returns
  139. */
  140. _this._timeArr = [0, 0.04, 0.05, 0.06, 0.07];
  141. _this._disArr = [0, 3, 10, 20, 30];
  142. _this._vibrateTime = 0; // 震动时间
  143. return _this;
  144. }
  145. GameMgr.prototype.nodeGet = function (name, prefab) {
  146. var node = null;
  147. // 创建新的节点池
  148. if (!this.nodePoolObj[name]) {
  149. this.nodePoolObj[name] = new cc.NodePool();
  150. }
  151. // 从节点池中获取节点
  152. if (this.nodePoolObj[name].size()) {
  153. node = this.nodePoolObj[name].get();
  154. }
  155. else if (prefab && prefab.isValid) {
  156. node = cc.instantiate(prefab);
  157. }
  158. // 防止预制体和节点名字不同
  159. if (node) {
  160. node.name = name;
  161. }
  162. return node;
  163. };
  164. GameMgr.prototype.nodePut = function (name, node) {
  165. if (this.nodePoolObj[name] && node && node.isValid) {
  166. this.nodePoolObj[name].put(node);
  167. }
  168. else {
  169. cc.log("回收出错: ", name);
  170. }
  171. };
  172. ;
  173. GameMgr.prototype.onLoad = function () {
  174. exports.gameMgr = this;
  175. exports.gameMgr.mainCamera.zoomRatio = 0.65;
  176. CocosZ_1.cocosz.pauseCount = 0;
  177. };
  178. GameMgr.prototype.start = function () {
  179. this.mainCamereRootNode.setContentSize(cc.winSize);
  180. this.mainCamereRootNode.width += 500;
  181. this.mainCamereRootNode.height += 500;
  182. // 飞机任务提示
  183. if (this.fjTip) {
  184. if ([5, 7].includes(CocosZ_1.cocosz.gameMode)) {
  185. this.fjTip.active = false;
  186. }
  187. else {
  188. this.fjTip.active = true;
  189. this.fjTip.zIndex = Constant_1.ZindexLayer.zindex_max;
  190. }
  191. }
  192. };
  193. GameMgr.prototype.lateUpdate = function () {
  194. if (CocosZ_1.cocosz.isPause || exports.gameMgr.isWin || exports.gameMgr.isFail)
  195. return;
  196. this.cameraFollow();
  197. };
  198. GameMgr.prototype.initPos = function () {
  199. var _this = this;
  200. if (CocosZ_1.cocosz.gameMode == 7) {
  201. // 坐标
  202. // rolePos0
  203. var bluePos = cc.find('posLayer/bluePos', exports.gameMgr.map);
  204. if (bluePos)
  205. this.posObj["bluePos"] = bluePos.getPosition();
  206. // rolePos1
  207. var redPos = cc.find('posLayer/redPos', exports.gameMgr.map);
  208. if (redPos)
  209. this.posObj["redPos"] = redPos.getPosition();
  210. // path0
  211. this.posObj["pathPos0"] = [];
  212. var pathPos0 = cc.find('posLayer/pathPos0', exports.gameMgr.map);
  213. pathPos0 && pathPos0.children.forEach(function (node) { _this.posObj["pathPos0"].push(node.getPosition()); });
  214. // path1
  215. this.posObj["pathPos1"] = [];
  216. var pathPos1 = cc.find('posLayer/pathPos1', exports.gameMgr.map);
  217. pathPos1 && pathPos1.children.forEach(function (node) { _this.posObj["pathPos1"].push(node.getPosition()); });
  218. // path2
  219. this.posObj["pathPos2"] = [];
  220. var pathPos2 = cc.find('posLayer/pathPos2', exports.gameMgr.map);
  221. pathPos2 && pathPos2.children.forEach(function (node) { _this.posObj["pathPos2"].push(node.getPosition()); });
  222. }
  223. };
  224. GameMgr.prototype.startGame = function () {
  225. var _this = this;
  226. // 添加提示层
  227. this.tipLayer = new cc.Node();
  228. this.tipLayer.name = "tipLayer";
  229. this.tipLayer.zIndex = Constant_1.ZindexLayer.zindex_roleLabel;
  230. this.tipLayer.setPosition(cc.Vec2.ZERO);
  231. this.tipLayer.setParent(exports.gameMgr.map);
  232. // 小地图
  233. if (CocosZ_1.cocosz.gameMode == 6) {
  234. this.schedule(function () { _this.update_model6_shuxing(); }, 1);
  235. }
  236. this.initPlayer();
  237. };
  238. GameMgr.prototype.initPlayer = function () {
  239. // 僵尸模式
  240. if (CocosZ_1.cocosz.gameMode == 6) {
  241. var player1 = cc.instantiate(this.player);
  242. player1.scale = 0.6;
  243. player1.setPosition(cc.v2(2000, 0).rotateSelf(2 * Math.PI * Math.random()));
  244. player1.setParent(this.map);
  245. this.totalNum++;
  246. // 飞机运输玩家
  247. this.fjEffect();
  248. }
  249. };
  250. GameMgr.prototype.fjEffect = function () {
  251. var _this = this;
  252. if (this.fj && this.playerTs) {
  253. this.uiGamePage.active = false;
  254. // 玩家
  255. this.scheduleOnce(function () {
  256. _this.playerTs.node.opacity = 0;
  257. _this.playerTs.playerMess.opacity = 1;
  258. _this.playerTs.ghAniNode.opacity = 1;
  259. });
  260. // 相机
  261. this.followNode = this.fj;
  262. // 飞机
  263. this.fj.active = true;
  264. this.fj.setParent(exports.gameMgr.map);
  265. this.scheduleOnce(function () { _this.fj.zIndex = Constant_1.ZindexLayer.zindex_max; });
  266. var targetPos = cc.v2(this.playerTs.node.x, this.playerTs.node.y + 500);
  267. var dis = targetPos.sub(this.fj.getPosition());
  268. this.fj.scaleX = dis.x < 0 ? -1 : 1;
  269. // 动画
  270. var fjAni_1 = this.fj.getComponent(sp.Skeleton);
  271. fjAni_1.addAnimation(0, "animation0", true);
  272. // 音效
  273. CocosZ_1.cocosz.audioMgr.playEffect("fj", true, 1);
  274. // 移动
  275. var t = dis.mag() / 800;
  276. cc.tween(this.fj)
  277. .to(t, { x: targetPos.x, y: targetPos.y })
  278. .call(function () {
  279. fjAni_1.setAnimation(0, "animation1", false);
  280. fjAni_1.addAnimation(0, "animation2", false);
  281. fjAni_1.addAnimation(0, "animation4", false);
  282. fjAni_1.addAnimation(0, "animation5", true);
  283. })
  284. .delay(2)
  285. .call(function () {
  286. // 隐藏提示
  287. if (_this.fjTip) {
  288. _this.fjTip.active = false;
  289. }
  290. _this.fj.zIndex = Constant_1.ZindexLayer.zindex_max - 1;
  291. _this.playerTs.node.zIndex = Constant_1.ZindexLayer.zindex_max;
  292. // 玩家下降
  293. _this.playerTs.node.opacity = 255;
  294. _this.playerTs.rig.active = false;
  295. _this.followNode = _this.playerTs.node;
  296. _this.playerTs.node.y += 600;
  297. cc.tween(_this.playerTs.node)
  298. .delay(0.5)
  299. .to(1, { y: _this.playerTs.node.y - 600 })
  300. .call(function () {
  301. _this.uiGamePage.active = true;
  302. _this.playerTs.node.zIndex = Constant_1.ZindexLayer.zindex_player;
  303. _this.playerTs.rig.active = true;
  304. _this.playerTs.playerMess.opacity = 255;
  305. _this.playerTs.ghAniNode.opacity = 255;
  306. _this.playerTs.updateAni("daiji_body", true);
  307. // 初始化游戏
  308. _this.initGame();
  309. if (CocosZ_1.cocosz.gameMode == 6) {
  310. // 生成僵尸计时
  311. _this.schedule(_this.createZombieCount, 1);
  312. }
  313. else {
  314. cc.log("模式有问题");
  315. }
  316. })
  317. .start();
  318. })
  319. .delay(2)
  320. .call(function () {
  321. _this.fj.zIndex = Constant_1.ZindexLayer.zindex_max;
  322. fjAni_1.setAnimation(0, "animation6", false);
  323. fjAni_1.addAnimation(0, "animation7", false);
  324. fjAni_1.addAnimation(0, "animation9", false);
  325. fjAni_1.addAnimation(0, "animation0", true);
  326. })
  327. .delay(2)
  328. .to(2, { position: cc.v3(dis.normalize().mulSelf(2000).add(dis)) })
  329. .call(function () {
  330. CocosZ_1.cocosz.audioMgr.stopEffect("fj");
  331. _this.fj.destroy();
  332. })
  333. .start();
  334. }
  335. };
  336. GameMgr.prototype.showGameTime = function () {
  337. if (this.model6_timeLabel && this.model6_timeLabel.isValid) {
  338. var s = this.GameTime; // 秒
  339. var m = 0; // 分
  340. var h = 0; // 小时
  341. if (s > 60) {
  342. m = Math.floor(s / 60);
  343. s = Math.floor(s % 60);
  344. if (m > 60) {
  345. h = Math.floor(m / 60);
  346. m = Math.floor(m % 60);
  347. }
  348. }
  349. var r = "";
  350. r += (h == 0 ? "" : h + ":");
  351. r += (m >= 10 ? "" + m : "0" + m);
  352. r += (s >= 10 ? ":" + s : ":0" + s);
  353. this.timeStr = r;
  354. this.model6_timeLabel.string = r;
  355. }
  356. };
  357. // 刷新血滴
  358. GameMgr.prototype.update_model6_xuedi = function () {
  359. if (exports.gameMgr.playerTs && exports.gameMgr.playerTs.hpNumNode && exports.gameMgr.playerTs.hpNumNode.isValid) {
  360. exports.gameMgr.playerTs.hpNumNode.active = true;
  361. exports.gameMgr.playerTs.hpNumNode.width = Math.min(250, exports.gameMgr.playerTs.totleHp * 50);
  362. exports.gameMgr.playerTs.hpNumNode.children.forEach(function (n, i) {
  363. if (i < exports.gameMgr.playerTs.totleHp) {
  364. n.active = true;
  365. if (i < exports.gameMgr.playerTs.HP) {
  366. n.children[1].opacity = 255;
  367. }
  368. else {
  369. n.children[1].opacity = 0;
  370. }
  371. }
  372. else {
  373. n.active = false;
  374. }
  375. });
  376. }
  377. };
  378. // 刷新属性
  379. GameMgr.prototype.update_model6_shuxing = function () {
  380. if (UpgradeMgr_1.upgradeMgr && exports.gameMgr && exports.gameMgr.model6_shuxing && exports.gameMgr.model6_shuxing.isValid && exports.gameMgr.model6_shuxing.active) {
  381. // 等级
  382. this.model6_shuxing.children[0].getComponent(cc.Label).string = UpgradeMgr_1.upgradeMgr.curLevel.toString();
  383. // 伤害
  384. this.model6_shuxing.children[1].getComponent(cc.Label).string = (exports.gameMgr.playerTs.atkNum * exports.gameMgr.playerTs.atkRate).toFixed(0);
  385. // 射速
  386. this.model6_shuxing.children[2].getComponent(cc.Label).string = (exports.gameMgr.playerTs.atkSpeed * exports.gameMgr.playerTs.atkSpeedRate).toFixed(1);
  387. // 换弹
  388. this.model6_shuxing.children[3].getComponent(cc.Label).string = (exports.gameMgr.playerTs.reloadSpeed * exports.gameMgr.playerTs.reloadRate).toFixed(1);
  389. // 弹夹容量
  390. this.model6_shuxing.children[4].getComponent(cc.Label).string = exports.gameMgr.playerTs.curWeapon.bulletNum.toString();
  391. // 移动速度
  392. this.model6_shuxing.children[5].getComponent(cc.Label).string = (exports.gameMgr.playerTs.MoveSpeed * exports.gameMgr.playerTs.speedRate).toFixed(0);
  393. // 拾取范围
  394. this.model6_shuxing.children[6].getComponent(cc.Label).string = UpgradeMgr_1.upgradeMgr.jingyanRange.toString();
  395. }
  396. };
  397. GameMgr.prototype.showBossHp = function (rate) {
  398. if (rate > 0) {
  399. if (this.model6_bossBar && cc.isValid(this.model6_bossBar)) {
  400. this.model6_bossBar.node.active = true;
  401. this.model6_bossBar.progress = rate;
  402. }
  403. if (this.model6_jingyanBar && cc.isValid(this.model6_jingyanBar)) {
  404. this.model6_jingyanBar.node.active = false;
  405. }
  406. if (this.model6_levelLabel && cc.isValid(this.model6_levelLabel)) {
  407. this.model6_levelLabel.node.active = false;
  408. }
  409. }
  410. else {
  411. if (this.model6_bossBar && cc.isValid(this.model6_bossBar)) {
  412. this.model6_bossBar.node.active = false;
  413. this.model6_bossBar.progress = rate;
  414. }
  415. if (this.model6_jingyanBar && cc.isValid(this.model6_jingyanBar)) {
  416. this.model6_jingyanBar.node.active = true;
  417. }
  418. if (this.model6_levelLabel && cc.isValid(this.model6_levelLabel)) {
  419. this.model6_levelLabel.node.active = true;
  420. }
  421. }
  422. };
  423. /** 创建僵尸计时 */
  424. GameMgr.prototype.createZombieCount = function () {
  425. var _this = this;
  426. if (CocosZ_1.cocosz.isPause || exports.gameMgr.isWin || exports.gameMgr.isFail)
  427. return;
  428. // 游戏计时
  429. this.GameTime++;
  430. this.showGameTime();
  431. // 生成逻辑
  432. if (this.boss_border)
  433. return;
  434. // 僵尸生成时间计时
  435. this.zombieTime++;
  436. var count = 1;
  437. /** 创建Boss */
  438. if (0 === this.zombieTime % 100) {
  439. this.createBossZombie();
  440. // 更新普通僵尸
  441. if (this.zombieLength < this.zombieArr.length)
  442. this.zombieLength++;
  443. }
  444. // 大波僵尸
  445. else if (0 === this.zombieTime % 50) {
  446. // 提示
  447. if (this.model6_ts) {
  448. this.model6_ts.active = true;
  449. this.scheduleOnce(function () { _this.model6_ts.active = false; }, 3);
  450. var spAni = this.model6_ts.getComponent(sp.Skeleton);
  451. spAni.setSkin("sclx_" + CocosZ_1.cocosz.curLanguage);
  452. spAni.setAnimation(0, "animation", true);
  453. }
  454. // 僵尸数量
  455. this.zombieMaxNum = 20 + Math.floor(this.zombieTime / 40) * 10;
  456. if (this.zombieMaxNum > 40)
  457. this.zombieMaxNum = 40;
  458. // 小于最大数量继续生成
  459. if (this.zombieCurNum < this.zombieMaxNum) {
  460. count = this.zombieMaxNum - this.zombieCurNum;
  461. // 分成k份生成,每份10
  462. var k = Math.ceil(count / 10);
  463. // 分帧创建
  464. var angle_1 = 0;
  465. var inter_1 = 36;
  466. for (var i = 0; i < k; i++) {
  467. this.schedule(function () {
  468. angle_1 += inter_1;
  469. _this.createCommonZombie(cc.winSize.height / 2.5 / _this.mainCamera.zoomRatio, angle_1);
  470. }, 0.1, Math.ceil(count / k), i);
  471. }
  472. }
  473. // 生成击败boss
  474. for (var i = this.boss2Arr.length - 1; i >= 0 && i >= this.boss2Arr.length - 2; i--) {
  475. var resName = this.boss2Arr[i];
  476. cc.log("创建尸潮boss: ", resName);
  477. if (resName) {
  478. this.createZombie(resName, exports.gameMgr.playerTs.node.getPosition(), cc.winSize.width / 2 / this.mainCamera.zoomRatio);
  479. }
  480. }
  481. }
  482. // 僵尸继续
  483. else if (0 === this.zombieTime % 51 || 0 === this.zombieTime % 52 || 0 === this.zombieTime % 53 || 0 === this.zombieTime % 54 || 0 === this.zombieTime % 55) {
  484. }
  485. // 随机少量僵尸
  486. else {
  487. // 僵尸数量
  488. this.zombieMaxNum = 5 + Math.floor(this.zombieTime / 20) * 5;
  489. if (this.zombieMaxNum > 20)
  490. this.zombieMaxNum = 20;
  491. // 小于最大数量继续生成
  492. if (this.zombieCurNum < this.zombieMaxNum) {
  493. // 随机数量
  494. count = Math.ceil(Math.random() * 4);
  495. this.schedule(function () { _this.createCommonZombie(cc.winSize.height / 2.5 / _this.mainCamera.zoomRatio); }, 0.1, count);
  496. }
  497. }
  498. };
  499. /** 创建普通僵尸 */
  500. GameMgr.prototype.createCommonZombie = function (dis, angle) {
  501. var index = Math.floor(Math.random() * this.zombieLength);
  502. var resName = this.zombieArr[index];
  503. if (resName) {
  504. this.createZombie(resName, exports.gameMgr.playerTs.node.getPosition(), dis, angle);
  505. }
  506. };
  507. /** 创建Boss僵尸 */
  508. GameMgr.prototype.createBossZombie = function () {
  509. var _this = this;
  510. if (this.bossArr.length) {
  511. this.createBossBorder();
  512. // 提示
  513. if (this.model6_ts) {
  514. this.model6_ts.active = true;
  515. this.scheduleOnce(function () { _this.model6_ts.active = false; }, 3);
  516. var spAni = this.model6_ts.getComponent(sp.Skeleton);
  517. spAni.setSkin("bosslx_" + CocosZ_1.cocosz.curLanguage);
  518. spAni.setAnimation(0, "animation", true);
  519. }
  520. // boss
  521. var resName = this.bossArr.shift();
  522. var centerPos = exports.gameMgr.playerTs.node.getPosition();
  523. if (this.boss_border) {
  524. centerPos = this.boss_border.getPosition();
  525. }
  526. if (resName) {
  527. this.boss2Arr.push(resName);
  528. this.createZombie(resName, centerPos, 300, null, true);
  529. }
  530. }
  531. };
  532. /** 创建boss边界 */
  533. GameMgr.prototype.createBossBorder = function () {
  534. // 边界
  535. var pre = CocosZ_1.cocosz.resMgr.getRes("boss_border", cc.Prefab);
  536. if (pre) {
  537. this.boss_border = cc.instantiate(pre);
  538. this.boss_border.setPosition(exports.gameMgr.playerTs.node.getPosition());
  539. if (this.boss_border.x - this.boss_border.width / 2 < -exports.gameMgr.mapSize.width / 2) {
  540. this.boss_border.x = -exports.gameMgr.mapSize.width / 2 + this.boss_border.width / 2 + 100;
  541. }
  542. else if (this.boss_border.x + this.boss_border.width / 2 > exports.gameMgr.mapSize.width / 2) {
  543. this.boss_border.x = exports.gameMgr.mapSize.width / 2 - this.boss_border.width / 2 - 100;
  544. }
  545. if (this.boss_border.y - this.boss_border.height / 2 < -exports.gameMgr.mapSize.height / 2) {
  546. this.boss_border.y = -exports.gameMgr.mapSize.height / 2 + this.boss_border.height / 2 + 100;
  547. }
  548. else if (this.boss_border.y + this.boss_border.height / 2 > exports.gameMgr.mapSize.height / 2) {
  549. this.boss_border.y = exports.gameMgr.mapSize.height / 2 - this.boss_border.height / 2 - 300;
  550. }
  551. this.boss_border.setParent(this.map);
  552. }
  553. };
  554. /** 创建僵尸 */
  555. GameMgr.prototype.createZombie = function (resName, center, dis, angle, isBoss) {
  556. var _this = this;
  557. if (isBoss === void 0) { isBoss = false; }
  558. // 预制体
  559. var prefab = CocosZ_1.cocosz.resMgr.getRes(resName, cc.Prefab);
  560. if (prefab) {
  561. // 坐标
  562. this._recursionCount = 0;
  563. var pos = this.getZombieBirthPos(center, dis, angle);
  564. if (pos) {
  565. // 僵尸
  566. var newZombie = this.nodeGet(resName, prefab);
  567. if (newZombie) {
  568. var ts = newZombie.getComponent(ZombieBase_1.default);
  569. if (ts && isBoss) {
  570. ts.isBoss = true;
  571. }
  572. newZombie.setPosition(pos);
  573. newZombie.setParent(exports.gameMgr.map);
  574. if (ts)
  575. ts.initNode();
  576. }
  577. }
  578. }
  579. else {
  580. CocosZ_1.cocosz.resMgr.loadAndCacheRes("prefab_zombie/" + resName, cc.Prefab, null, function (err, res) {
  581. if (!err) {
  582. _this.createZombie(resName, center, dis, angle, isBoss);
  583. }
  584. });
  585. }
  586. };
  587. GameMgr.prototype.getZombieBirthPos = function (center, dis, angle) {
  588. if (++this._recursionCount > 100) {
  589. return null;
  590. }
  591. var radians = 0;
  592. if (angle == null || angle == undefined) {
  593. radians = 2 * Math.PI * Math.random();
  594. }
  595. else {
  596. radians = cc.misc.degreesToRadians(angle);
  597. }
  598. var dif = cc.v2(dis + Math.floor(200 * Math.random()), 0).rotateSelf(radians);
  599. var pos = center.add(dif);
  600. if (pos.x > -exports.gameMgr.mapSize.width / 2 + 400 && pos.x < exports.gameMgr.mapSize.width / 2 - 400 &&
  601. pos.y < exports.gameMgr.mapSize.height / 2 - 400 && pos.y > -exports.gameMgr.mapSize.height / 2 + 400) {
  602. return pos;
  603. }
  604. else {
  605. return this.getZombieBirthPos(center, dis);
  606. }
  607. };
  608. GameMgr.prototype.initGame = function () {
  609. var _this = this;
  610. this.startPos = this.yaogan.getPosition();
  611. this.isGameStart = true;
  612. cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.keyDown, this);
  613. cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.keyUp, this);
  614. this.moveArea.on(cc.Node.EventType.TOUCH_START, (function (event) {
  615. var pos = event.getLocation();
  616. pos = _this.node.convertToNodeSpaceAR(pos);
  617. _this.yaogan.setPosition(pos);
  618. }), this);
  619. this.moveArea.on(cc.Node.EventType.TOUCH_MOVE, (function (event) {
  620. var div = event.getLocation().sub(event.getStartLocation());
  621. if (div.mag() > 160) {
  622. div = div.mul(160 / div.mag());
  623. }
  624. _this.yaogan.children[0].setPosition(div);
  625. exports.gameMgr.playerTs.moveDir = div.normalize();
  626. }), this);
  627. this.moveArea.on(cc.Node.EventType.TOUCH_END, (function (event) {
  628. _this.yaogan.setPosition(_this.startPos);
  629. _this.yaogan.children[0].setPosition(cc.v2(0, 0));
  630. exports.gameMgr.playerTs.moveDir = cc.v2(0, 0);
  631. }), this);
  632. this.moveArea.on(cc.Node.EventType.TOUCH_CANCEL, (function (event) {
  633. _this.yaogan.setPosition(_this.startPos);
  634. _this.yaogan.children[0].setPosition(cc.v2(0, 0));
  635. exports.gameMgr.playerTs.moveDir = cc.v2(0, 0);
  636. }), this);
  637. };
  638. GameMgr.prototype.keyDown = function (event) {
  639. switch (event.keyCode) {
  640. case 87: {
  641. if (!this.isUp) {
  642. this.isUp = true;
  643. this.setDir();
  644. }
  645. break;
  646. }
  647. case 83: {
  648. if (!this.isDown) {
  649. this.isDown = true;
  650. this.setDir();
  651. }
  652. break;
  653. }
  654. case 65: {
  655. if (!this.isLeft) {
  656. this.isLeft = true;
  657. this.setDir();
  658. }
  659. break;
  660. }
  661. case 68: {
  662. if (!this.isRight) {
  663. this.isRight = true;
  664. this.setDir();
  665. }
  666. break;
  667. }
  668. }
  669. };
  670. GameMgr.prototype.keyUp = function (event) {
  671. switch (event.keyCode) {
  672. case 87: {
  673. this.isUp = false;
  674. this.setDir();
  675. break;
  676. }
  677. case 83: {
  678. this.isDown = false;
  679. this.setDir();
  680. break;
  681. }
  682. case 65: {
  683. this.isLeft = false;
  684. this.setDir();
  685. break;
  686. }
  687. case 68: {
  688. this.isRight = false;
  689. this.setDir();
  690. break;
  691. }
  692. }
  693. };
  694. GameMgr.prototype.cameraFollow = function () {
  695. var pos_to = null;
  696. var t = 0.1;
  697. if (this.followNode && this.followNode.isValid) {
  698. pos_to = this.followNode.getPosition();
  699. t = 0.1;
  700. }
  701. if (pos_to) {
  702. var pos_from = this.mainCamereRootNode.getPosition();
  703. var pos_out = cc.Vec2.ZERO;
  704. var ratio = this.mainCamera.zoomRatio;
  705. var winSize = new cc.Size(cc.winSize.width / ratio, cc.winSize.height / ratio);
  706. if (CocosZ_1.cocosz.gameMode == 7) {
  707. // 无边界
  708. }
  709. else {
  710. // 相机边界
  711. if ((pos_to.x + winSize.width / 2) > exports.gameMgr.mapSize.width / 2) {
  712. pos_to.x = exports.gameMgr.mapSize.width / 2 - winSize.width / 2;
  713. }
  714. else if ((pos_to.x - winSize.width / 2) < -exports.gameMgr.mapSize.width / 2) {
  715. pos_to.x = -exports.gameMgr.mapSize.width / 2 + winSize.width / 2;
  716. }
  717. if ((pos_to.y + winSize.height / 2) > exports.gameMgr.mapSize.height / 2) {
  718. pos_to.y = exports.gameMgr.mapSize.height / 2 - winSize.height / 2;
  719. }
  720. else if ((pos_to.y - winSize.height / 2) < -exports.gameMgr.mapSize.height / 2) {
  721. pos_to.y = -exports.gameMgr.mapSize.height / 2 + winSize.height / 2;
  722. }
  723. }
  724. if (pos_to.sub(pos_from).mag() < 1000) {
  725. cc.Vec2.lerp(pos_out, pos_from, pos_to, t);
  726. this.mainCamereRootNode.setPosition(pos_out);
  727. }
  728. else {
  729. this.mainCamereRootNode.setPosition(pos_to);
  730. // 更新节点透明度
  731. exports.gameMgr.setMapTs && exports.gameMgr.setMapTs.checkAllNode();
  732. }
  733. }
  734. };
  735. GameMgr.prototype.setDir = function () {
  736. var moveDir = cc.v2(0, 0);
  737. if (this.isUp) {
  738. moveDir.y++;
  739. }
  740. if (this.isLeft) {
  741. moveDir.x--;
  742. }
  743. if (this.isRight) {
  744. moveDir.x++;
  745. }
  746. if (this.isDown) {
  747. moveDir.y--;
  748. }
  749. this.playerTs.moveDir = moveDir.normalize();
  750. };
  751. GameMgr.prototype.restart = function () { };
  752. GameMgr.prototype.useMeleeWeapon = function () { };
  753. GameMgr.prototype.useRangedWeapon = function () {
  754. this.playerTs.changeCurWeapon(this.playerTs.rangedWeapon);
  755. };
  756. GameMgr.prototype.useRangedWeaponAd = function () {
  757. this.playerTs.changeCurWeapon(this.playerTs.rangedWeaponAd);
  758. };
  759. GameMgr.prototype.getNewWeapon = function () {
  760. CocosZ_1.cocosz.audioMgr.playEffect("changeWeapon");
  761. this.playerTs.setNewWeapon();
  762. };
  763. GameMgr.prototype.playEffect = function (name, node, interval) {
  764. var _this = this;
  765. if (interval === void 0) { interval = 0.2; }
  766. if (exports.gameMgr.isWin || exports.gameMgr.isFail || CocosZ_1.cocosz.isPause)
  767. return;
  768. if (this.clipNameArr[name]) {
  769. return;
  770. }
  771. var voice = 1;
  772. if (node && node.isValid && node.parent && node.parent.isValid) {
  773. var pos = node.getPosition();
  774. pos = node.parent.convertToWorldSpaceAR(pos);
  775. var pos2 = this.playerTs.node.getPosition();
  776. pos2 = this.playerTs.node.parent.convertToWorldSpaceAR(pos2);
  777. var dt = pos.sub(pos2).mag();
  778. if (dt > 2000) {
  779. return;
  780. }
  781. }
  782. CocosZ_1.cocosz.audioMgr.playEffect(name, false, voice);
  783. if (interval > 0) {
  784. this.clipNameArr[name] = 1;
  785. this.scheduleOnce(function () { _this.clipNameArr[name] = 0; }, interval);
  786. }
  787. };
  788. GameMgr.prototype.playClip = function (clip, node, interval) {
  789. var _this = this;
  790. if (interval === void 0) { interval = 0.2; }
  791. if (exports.gameMgr.isWin || exports.gameMgr.isFail || CocosZ_1.cocosz.isPause)
  792. return;
  793. if (this.clipNameArr[clip.name]) {
  794. return;
  795. }
  796. var voice = 1;
  797. if (node && node.isValid && node.parent && node.parent.isValid) {
  798. var pos = node.getPosition();
  799. pos = node.parent.convertToWorldSpaceAR(pos);
  800. var pos2 = this.playerTs.node.getPosition();
  801. pos2 = this.playerTs.node.parent.convertToWorldSpaceAR(pos2);
  802. var dt = pos.sub(pos2).mag();
  803. if (dt > 2000) {
  804. return;
  805. }
  806. }
  807. CocosZ_1.cocosz.audioMgr.playClip(clip, false, voice);
  808. // 记录
  809. if (interval > 0) {
  810. this.clipNameArr[clip.name] = 1;
  811. this.scheduleOnce(function () { _this.clipNameArr[clip.name] = 0; }, interval);
  812. }
  813. };
  814. /** 文字提示效果 */
  815. GameMgr.prototype.showRoleTip = function (node, str, labelColor) {
  816. var _this = this;
  817. if (labelColor === void 0) { labelColor = cc.Color.WHITE; }
  818. if (node && node.isValid && this.hpTip && this.hpTip.isValid && exports.gameMgr.tipLayer) {
  819. var tipNode_1 = this.nodeGet("hpTip", this.hpTip);
  820. if (tipNode_1) {
  821. tipNode_1.setParent(exports.gameMgr.tipLayer);
  822. // 初始化
  823. tipNode_1.setPosition(node.x + 200 * (Math.random() - 0.5), node.y + node.height / 2);
  824. tipNode_1.opacity = 255;
  825. tipNode_1.color = labelColor;
  826. tipNode_1.scale = (labelColor == cc.Color.WHITE ? 1 : 1.2);
  827. // 字体内容
  828. var tipLabel = tipNode_1.getComponent(cc.Label);
  829. if (tipLabel) {
  830. tipLabel.string = str;
  831. }
  832. // 动效
  833. tipNode_1.stopAllActions();
  834. cc.tween(tipNode_1)
  835. .by(0.5, { y: 20, scale: 1, })
  836. .by(0.3, { y: 10, scale: -1, opacity: -255 })
  837. .call(function () { _this.nodePut("hpTip", tipNode_1); })
  838. .start();
  839. }
  840. }
  841. };
  842. GameMgr.prototype.fail = function () {
  843. var _this = this;
  844. if (this.isWin || this.isFail)
  845. return;
  846. CocosZ_1.cocosz.pauseCount++;
  847. this.isFail = true;
  848. this.unscheduleAllCallbacks();
  849. UpgradeMgr_1.upgradeMgr && UpgradeMgr_1.upgradeMgr.unscheduleAllCallbacks();
  850. this.scheduleOnce(function () {
  851. _this.qlzc.active = true;
  852. cc.tween(_this.qlzc)
  853. .delay(0.3)
  854. .call(function () { _this.qlzc.getChildByName("dian").children[0].active = true; })
  855. .delay(0.3)
  856. .call(function () { _this.qlzc.getChildByName("dian").children[1].active = true; })
  857. .delay(0.3)
  858. .call(function () { _this.qlzc.getChildByName("dian").children[2].active = true; })
  859. .delay(0.3)
  860. .call(function () {
  861. _this.qlzc.getChildByName("dian").children[0].active = false;
  862. _this.qlzc.getChildByName("dian").children[1].active = false;
  863. _this.qlzc.getChildByName("dian").children[2].active = false;
  864. })
  865. .union()
  866. .repeatForever()
  867. .start();
  868. }, 2);
  869. this.scheduleOnce(function () {
  870. CocosZ_1.cocosz.gameMgr.gameFailed();
  871. }, 4);
  872. };
  873. GameMgr.prototype.win = function () {
  874. var _this = this;
  875. if (this.isWin || this.isFail)
  876. return;
  877. CocosZ_1.cocosz.pauseCount++;
  878. this.isWin = true;
  879. this.unscheduleAllCallbacks();
  880. UpgradeMgr_1.upgradeMgr && UpgradeMgr_1.upgradeMgr.unscheduleAllCallbacks();
  881. this.scheduleOnce(function () {
  882. _this.qlzc.active = true;
  883. cc.tween(_this.qlzc)
  884. .delay(0.3)
  885. .call(function () { _this.qlzc.getChildByName("dian").children[0].active = true; })
  886. .delay(0.3)
  887. .call(function () { _this.qlzc.getChildByName("dian").children[1].active = true; })
  888. .delay(0.3)
  889. .call(function () { _this.qlzc.getChildByName("dian").children[2].active = true; })
  890. .delay(0.3)
  891. .call(function () {
  892. _this.qlzc.getChildByName("dian").children[0].active = false;
  893. _this.qlzc.getChildByName("dian").children[1].active = false;
  894. _this.qlzc.getChildByName("dian").children[2].active = false;
  895. })
  896. .union()
  897. .repeatForever()
  898. .start();
  899. }, 2);
  900. this.scheduleOnce(function () {
  901. CocosZ_1.cocosz.gameMgr.gameSuccess();
  902. }, 4);
  903. };
  904. GameMgr.prototype.revive = function () {
  905. this.isRevive = true;
  906. this.playerTs.revive();
  907. };
  908. GameMgr.prototype.shakeEffect = function (extent, times, isVibrate, vibrateType) {
  909. if (extent === void 0) { extent = 1; }
  910. if (times === void 0) { times = 1; }
  911. if (isVibrate === void 0) { isVibrate = true; }
  912. if (vibrateType === void 0) { vibrateType = YZ_Constant_1.VibrateType.Short; }
  913. // 镜头晃动
  914. var t = this._timeArr[extent];
  915. var dis = this._disArr[extent];
  916. if (extent > 0 && times > 0) {
  917. this.mainCamera.node.stopAllActions();
  918. this.mainCamera.node.setPosition(0, 0, 0);
  919. cc.tween(this.mainCamera.node)
  920. .to(t, { position: cc.v3(dis, dis) })
  921. .to(t, { position: cc.v3(0, -dis) })
  922. .to(t, { position: cc.v3(-dis, dis) })
  923. .to(t, { position: cc.v3(-dis, -dis) })
  924. .to(t, { position: cc.v3(0, dis) })
  925. .to(t, { position: cc.v3(0, 0) })
  926. .union()
  927. .repeat(times)
  928. .start();
  929. }
  930. // 震动,间隔1秒
  931. if (CocosZ_1.cocosz.dataMgr.ShakeOn) {
  932. var currentTime = new Date().getTime();
  933. if (currentTime - this._vibrateTime > 1000) { // 间隔调整为1000毫秒即1秒
  934. this._vibrateTime = currentTime;
  935. if (isVibrate) {
  936. if (vibrateType == YZ_Constant_1.VibrateType.Short) {
  937. ATAndroidJS2_1.default.appVibrateShort();
  938. }
  939. else {
  940. ATAndroidJS2_1.default.appVibrateLong();
  941. }
  942. }
  943. }
  944. }
  945. if (2 > 1) {
  946. return;
  947. }
  948. // 震动,间隔1秒
  949. if (CocosZ_1.cocosz.dataMgr.ShakeOn) {
  950. var t_1 = new Date().getTime();
  951. if (t_1 - this._vibrateTime > 500) {
  952. this._vibrateTime = t_1;
  953. isVibrate && Utils_1.utils.vibrate(vibrateType);
  954. }
  955. }
  956. };
  957. GameMgr.prototype.guideSkip = function () {
  958. // 新手指引跳过
  959. };
  960. __decorate([
  961. property(cc.Node)
  962. ], GameMgr.prototype, "red", void 0);
  963. __decorate([
  964. property(cc.Prefab)
  965. ], GameMgr.prototype, "hpTip", void 0);
  966. __decorate([
  967. property(cc.Prefab)
  968. ], GameMgr.prototype, "effect_fire", void 0);
  969. __decorate([
  970. property(cc.Prefab)
  971. ], GameMgr.prototype, "effect_hit", void 0);
  972. __decorate([
  973. property(cc.Prefab)
  974. ], GameMgr.prototype, "itemList", void 0);
  975. __decorate([
  976. property(cc.Prefab)
  977. ], GameMgr.prototype, "itemEffect", void 0);
  978. __decorate([
  979. property(cc.Prefab)
  980. ], GameMgr.prototype, "spark", void 0);
  981. __decorate([
  982. property(cc.Prefab)
  983. ], GameMgr.prototype, "blood", void 0);
  984. __decorate([
  985. property(cc.Prefab)
  986. ], GameMgr.prototype, "testPoint", void 0);
  987. __decorate([
  988. property(cc.Prefab)
  989. ], GameMgr.prototype, "player", void 0);
  990. __decorate([
  991. property(cc.SpriteFrame)
  992. ], GameMgr.prototype, "jiaoyin", void 0);
  993. __decorate([
  994. property(cc.Node)
  995. ], GameMgr.prototype, "fj", void 0);
  996. __decorate([
  997. property(cc.Node)
  998. ], GameMgr.prototype, "fjTip", void 0);
  999. __decorate([
  1000. property(cc.Node)
  1001. ], GameMgr.prototype, "mainCamereRootNode", void 0);
  1002. __decorate([
  1003. property(cc.Camera)
  1004. ], GameMgr.prototype, "mainCamera", void 0);
  1005. GameMgr = __decorate([
  1006. ccclass
  1007. ], GameMgr);
  1008. return GameMgr;
  1009. }(cc.Component));
  1010. exports.default = GameMgr;
  1011. cc._RF.pop();