bundle.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. (function () {
  2. 'use strict';
  3. class GameConfig {
  4. constructor() { }
  5. static init() {
  6. var reg = Laya.ClassUtils.regClass;
  7. }
  8. }
  9. GameConfig.width = 640;
  10. GameConfig.height = 1136;
  11. GameConfig.scaleMode = "fixedwidth";
  12. GameConfig.screenMode = "none";
  13. GameConfig.alignV = "top";
  14. GameConfig.alignH = "left";
  15. GameConfig.startScene = "MainScene.scene";
  16. GameConfig.sceneRoot = "";
  17. GameConfig.debug = false;
  18. GameConfig.stat = false;
  19. GameConfig.physicsDebug = false;
  20. GameConfig.exportSceneToJson = true;
  21. GameConfig.init();
  22. class ResDic {
  23. constructor() {
  24. this._container = {};
  25. this._length = 0;
  26. }
  27. get container() {
  28. return this._container;
  29. }
  30. get size() {
  31. return this._length;
  32. }
  33. set(key, value) {
  34. if (!this._container.hasOwnProperty(key)) {
  35. this._length++;
  36. }
  37. this._container[key] = value;
  38. }
  39. has(key) {
  40. return this._container.hasOwnProperty(key) ? true : false;
  41. }
  42. get(key) {
  43. if (this._container.hasOwnProperty(key)) {
  44. return this._container[key];
  45. }
  46. else {
  47. return undefined;
  48. }
  49. }
  50. delete(key) {
  51. if (this._container.hasOwnProperty(key)) {
  52. delete this._container[key];
  53. this._length--;
  54. }
  55. }
  56. clear() {
  57. this._container = {};
  58. this._length = 0;
  59. }
  60. }
  61. var DispatcherState;
  62. (function (DispatcherState) {
  63. DispatcherState[DispatcherState["LoadComplete"] = 0] = "LoadComplete";
  64. DispatcherState[DispatcherState["SceneInit"] = 1] = "SceneInit";
  65. DispatcherState[DispatcherState["StageInit"] = 2] = "StageInit";
  66. DispatcherState[DispatcherState["StageCreateComplete"] = 3] = "StageCreateComplete";
  67. DispatcherState[DispatcherState["GoldGet"] = 4] = "GoldGet";
  68. DispatcherState[DispatcherState["PlayerRunning"] = 5] = "PlayerRunning";
  69. DispatcherState[DispatcherState["PlayerStand"] = 6] = "PlayerStand";
  70. DispatcherState[DispatcherState["ShowModel"] = 7] = "ShowModel";
  71. DispatcherState[DispatcherState["RefreshCityName"] = 8] = "RefreshCityName";
  72. })(DispatcherState || (DispatcherState = {}));
  73. var StageState;
  74. (function (StageState) {
  75. StageState[StageState["Start"] = 0] = "Start";
  76. StageState[StageState["Lose"] = 1] = "Lose";
  77. StageState[StageState["Win"] = 2] = "Win";
  78. StageState[StageState["TimeOver"] = 3] = "TimeOver";
  79. })(StageState || (StageState = {}));
  80. class DispatcherControl {
  81. static DispatcherOn(_mode, caller, fun, args = []) {
  82. DispatcherControl.instance.on(DispatcherState[_mode], caller, fun, args);
  83. }
  84. static DispatcherOff(_mode, caller, fun, args = []) {
  85. DispatcherControl.instance.off(DispatcherState[_mode], caller, fun);
  86. }
  87. static DispatcherTrigger(_mode, args = []) {
  88. DispatcherControl.instance.event(DispatcherState[_mode], args);
  89. }
  90. static StageOn(_state, caller, fun, args = []) {
  91. DispatcherControl.instance.on(StageState[_state], caller, fun, args);
  92. }
  93. static StageOff(_state, caller, fun, args = []) {
  94. DispatcherControl.instance.off(StageState[_state], caller, fun);
  95. }
  96. static StageTrigger(_state, args = []) {
  97. DispatcherControl.instance.event(StageState[_state], args);
  98. }
  99. }
  100. DispatcherControl.instance = new Laya.EventDispatcher();
  101. class GameTools {
  102. constructor() {
  103. GameTools.ins = this;
  104. }
  105. static get Instance() {
  106. if (GameTools.ins) {
  107. return GameTools.ins;
  108. }
  109. else {
  110. return new GameTools();
  111. }
  112. }
  113. lerp(form, to, t) {
  114. if (t <= 0) {
  115. return form;
  116. }
  117. else if (t >= 1) {
  118. return to;
  119. }
  120. var a = t * to + (1 - t) * form;
  121. return a;
  122. }
  123. static RandomNumber(from, to) {
  124. if (from >= to) {
  125. return 0;
  126. }
  127. var size = to - from;
  128. var curNumber = Math.random() * size + from;
  129. return curNumber;
  130. }
  131. static RandomANumber(from, to) {
  132. if (from >= to) {
  133. return 0;
  134. }
  135. var size = to - from;
  136. var curNumber = Math.random() * size + from;
  137. return Math.floor(curNumber);
  138. }
  139. SetCollider(setNode, CollisionGroup) {
  140. var numchild = setNode.numChildren;
  141. for (var i = 0; i < setNode.numChildren; i++) {
  142. var numchild2 = setNode.getChildAt(i).numChildren;
  143. if (numchild2 > 1) {
  144. this.SetCollider(setNode.getChildAt(i), CollisionGroup);
  145. }
  146. var physicsCollider = setNode.getChildAt(i).getComponent(Laya.PhysicsCollider);
  147. if (physicsCollider) {
  148. physicsCollider.collisionGroup = CollisionGroup;
  149. }
  150. }
  151. }
  152. static GetMoney(_num, _pos = null, _completeHandle = null) {
  153. if (_num == 0)
  154. return;
  155. var fafaafsfa = new Laya.Box;
  156. fafaafsfa.width = 400;
  157. fafaafsfa.height = 100;
  158. fafaafsfa.pivotX = fafaafsfa.width / 2;
  159. fafaafsfa.pivotY = fafaafsfa.height / 2;
  160. if (_pos == null) {
  161. _pos = new Laya.Vector2(Laya.stage.width / 2, Laya.stage.height / 2);
  162. }
  163. fafaafsfa.pos(_pos.x, _pos.y);
  164. var aafafaffa = new Laya.Image;
  165. aafafaffa.skin = "game/qiandao_1_7.png";
  166. aafafaffa.width = 60;
  167. aafafaffa.height = 60;
  168. aafafaffa.left = 50;
  169. aafafaffa.y = 10;
  170. fafaafsfa.addChild(aafafaffa);
  171. var faasfafsafs = new Laya.Text;
  172. faasfafsafs.width = 300;
  173. faasfafsafs.height = 50;
  174. faasfafsafs.align = "center";
  175. faasfafsafs.valign = "middle";
  176. faasfafsafs.font = "Microsoft YaHei";
  177. faasfafsafs.fontSize = 40;
  178. faasfafsafs.color = "#FFFFFF";
  179. faasfafsafs.bold = true;
  180. faasfafsafs.font = "Microsoft YaHei";
  181. faasfafsafs.text = "金币 +" + _num;
  182. faasfafsafs.x = 60;
  183. faasfafsafs.y = 10;
  184. fafaafsfa.addChild(faasfafsafs);
  185. Laya.stage.addChild(fafaafsfa);
  186. var faasfsaf = Laya.Tween.to(fafaafsfa, { y: fafaafsfa.y - 200 }, 1500, Laya.Ease.expoInOut, Laya.Handler.create(this, () => {
  187. faasfsaf.clear();
  188. fafaafsfa.destroy();
  189. if (_completeHandle) {
  190. _completeHandle.run();
  191. }
  192. }), 100);
  193. }
  194. static TweenText(faafssfafsa, _hight, _completeHandle = null, hide = true, _duration = 500) {
  195. var afasafsafsfa = new Laya.Text();
  196. afasafsafsfa.width = faafssfafsa.size.x;
  197. afasafsafsfa.height = faafssfafsa.size.y;
  198. afasafsafsfa.align = "center";
  199. afasafsafsfa.valign = "middle";
  200. afasafsafsfa.font = "Microsoft YaHei";
  201. afasafsafsfa.fontSize = faafssfafsa.fontSize;
  202. afasafsafsfa.pivotX = afasafsafsfa.width / 2;
  203. afasafsafsfa.pivotY = afasafsafsfa.height / 2;
  204. afasafsafsfa.color = "#5ad122";
  205. afasafsafsfa.bold = true;
  206. afasafsafsfa.stroke = 5;
  207. afasafsafsfa.strokeColor = "#ffffff";
  208. if (faafssfafsa.color) {
  209. faafssfafsa.color = faafssfafsa.color;
  210. }
  211. afasafsafsfa.text = faafssfafsa.message;
  212. afasafsafsfa.zOrder = 1;
  213. Laya.stage.addChildAt(afasafsafsfa, Laya.stage.numChildren - 1);
  214. afasafsafsfa.pos(faafssfafsa.pos.x, faafssfafsa.pos.y);
  215. var tween = Laya.Tween.to(afasafsafsfa, { y: afasafsafsfa.y - _hight, update: new Laya.Handler(this, function () {
  216. }) }, _duration, Laya.Ease.expoInOut, Laya.Handler.create(this, function () {
  217. tween.clear();
  218. if (hide) {
  219. afasafsafsfa.destroy();
  220. }
  221. if (_completeHandle) {
  222. _completeHandle.run();
  223. }
  224. }));
  225. if (hide) {
  226. Laya.Tween.to(afasafsafsfa, { alpha: 0.4 }, 500);
  227. }
  228. return afasafsafsfa;
  229. }
  230. static StationTweenText(faafssfafsa, _hight, _completeHandle = null, hide = true, _duration = 1000) {
  231. var afasafsafsfa = new Laya.Text();
  232. afasafsafsfa.width = faafssfafsa.size.x;
  233. afasafsafsfa.height = faafssfafsa.size.y;
  234. afasafsafsfa.align = "center";
  235. afasafsafsfa.valign = "middle";
  236. afasafsafsfa.font = "Microsoft YaHei";
  237. afasafsafsfa.fontSize = 50;
  238. afasafsafsfa.pivotX = afasafsafsfa.width / 2;
  239. afasafsafsfa.pivotY = afasafsafsfa.height / 2;
  240. afasafsafsfa.color = "#5ad122";
  241. afasafsafsfa.bold = true;
  242. afasafsafsfa.stroke = 5;
  243. afasafsafsfa.strokeColor = "#ffffff";
  244. if (faafssfafsa.color) {
  245. faafssfafsa.color = faafssfafsa.color;
  246. }
  247. afasafsafsfa.text = faafssfafsa.message;
  248. afasafsafsfa.zOrder = 1;
  249. Laya.stage.addChildAt(afasafsafsfa, Laya.stage.numChildren - 1);
  250. afasafsafsfa.pos(faafssfafsa.pos.x, faafssfafsa.pos.y);
  251. var tween = Laya.Tween.to(afasafsafsfa, { y: afasafsafsfa.y - _hight, update: new Laya.Handler(this, function () {
  252. }) }, _duration, Laya.Ease.expoInOut, Laya.Handler.create(this, function () {
  253. tween.clear();
  254. if (hide) {
  255. afasafsafsfa.destroy();
  256. }
  257. if (_completeHandle) {
  258. _completeHandle.run();
  259. }
  260. }));
  261. if (hide) {
  262. Laya.Tween.to(afasafsafsfa, { alpha: 0.4 }, 10000);
  263. }
  264. return afasafsafsfa;
  265. }
  266. static tweenMove(transform, targPos, delay, ease, complete) {
  267. let curPos = transform.position.clone();
  268. return Laya.Tween.to(curPos, {
  269. x: targPos.x,
  270. y: targPos.y,
  271. z: targPos.z,
  272. update: new Laya.Handler(this, () => {
  273. transform.position = curPos.clone();
  274. })
  275. }, delay, ease, complete);
  276. }
  277. static tweenRotate(transform, targEuler, delay, ease, complete) {
  278. let curEuler = transform.rotationEuler.clone();
  279. return Laya.Tween.to(curEuler, {
  280. x: targEuler.x,
  281. y: targEuler.y,
  282. z: targEuler.z,
  283. update: new Laya.Handler(this, () => {
  284. transform.rotationEuler = curEuler.clone();
  285. })
  286. }, delay, ease, complete);
  287. }
  288. }
  289. class AssetManager {
  290. constructor() {
  291. this.Zombie = new ResDic();
  292. this.Character = new ResDic();
  293. AssetManager.ins = this;
  294. DispatcherControl.DispatcherOn(DispatcherState.LoadComplete, this, this.Init);
  295. }
  296. static get Instance() {
  297. if (AssetManager.ins) {
  298. return AssetManager.ins;
  299. }
  300. else {
  301. return new AssetManager();
  302. }
  303. }
  304. Init() {
  305. this.maincamera = this.mainscene.getChildByName("Main Camera");
  306. this.Wall = this.mainscene.getChildByName("Wall");
  307. this.Build = this.mainscene.getChildByName("Build");
  308. GameTools.Instance.SetCollider(this.Wall, 100);
  309. GameTools.Instance.SetCollider(this.Build, 100);
  310. DispatcherControl.DispatcherTrigger(DispatcherState.SceneInit);
  311. }
  312. }
  313. class ResourcesPath {
  314. constructor() {
  315. ResourcesPath.ins = this;
  316. }
  317. static get Instance() {
  318. if (ResourcesPath.ins) {
  319. return ResourcesPath.ins;
  320. }
  321. else {
  322. return new ResourcesPath();
  323. }
  324. }
  325. }
  326. ResourcesPath.MainScene = "Game/res/MainScene/LayaScene_mainscene/Conventional/mainscene.ls";
  327. ResourcesPath.Character = [
  328. "Game/res/Role/LayaScene_role/Conventional/Character.lh"
  329. ];
  330. ResourcesPath.Zombie = [
  331. "Game/res/Role/LayaScene_role/Conventional/Zombie.lh"
  332. ];
  333. var Sprite3D = Laya.Sprite3D;
  334. var Vector3 = Laya.Vector3;
  335. class modelConfig {
  336. constructor(model) {
  337. this.modelcur = model;
  338. this.modelPos = model.transform.position.clone();
  339. this.modelRot = model.transform.rotation.clone();
  340. this.modelSca = model.transform.scale.clone();
  341. }
  342. }
  343. class GamePool {
  344. constructor() {
  345. this.modelpool = {};
  346. this.maxAcount = 100;
  347. GamePool.ins = this;
  348. }
  349. static get Instance() {
  350. if (GamePool.ins) {
  351. return GamePool.ins;
  352. }
  353. else {
  354. return new GamePool();
  355. }
  356. }
  357. GetModel(_model, title) {
  358. var poolname = title + _model.name;
  359. if (this.modelpool[poolname] != null && this.modelpool[poolname] != undefined) {
  360. if (this.modelpool[poolname].length > 0) {
  361. var model1 = this.modelpool[poolname][0];
  362. this.modelpool[poolname].splice(0, 1);
  363. if (model1.modelcur.destroyed) {
  364. model1.modelcur = Sprite3D.instantiate(_model);
  365. if (!model1.modelcur.active) {
  366. model1.modelcur.active = true;
  367. }
  368. }
  369. model1.modelcur.active = true;
  370. model1.modelcur.transform.position = _model.transform.position.clone();
  371. model1.modelcur.transform.rotation = _model.transform.rotation.clone();
  372. model1.modelcur.transform.scale = _model.transform.scale.clone();
  373. return model1.modelcur;
  374. }
  375. else {
  376. var model = Sprite3D.instantiate(_model);
  377. model.active = true;
  378. return model;
  379. }
  380. }
  381. else {
  382. var model = Sprite3D.instantiate(_model);
  383. model.active = true;
  384. return model;
  385. }
  386. }
  387. RecoveryModel(model, title = "", modelstate = false) {
  388. if (model.destroyed) {
  389. return;
  390. }
  391. if (!modelstate && model.active == false) {
  392. return;
  393. }
  394. var poolname = title + model.name;
  395. if (this.modelpool[poolname] != null && this.modelpool[poolname] != undefined) {
  396. var modelnum = this.modelpool[poolname];
  397. if (modelnum.length > this.maxAcount) {
  398. model.destroy();
  399. return;
  400. }
  401. else {
  402. modelnum.push(new modelConfig(model));
  403. }
  404. }
  405. else {
  406. modelnum = [];
  407. modelnum.push(new modelConfig(model));
  408. this.modelpool[poolname] = modelnum;
  409. }
  410. model.transform.position = new Vector3(0, 0, -10000);
  411. model.removeSelf();
  412. model.active = false;
  413. }
  414. }
  415. class CharacterData {
  416. constructor() {
  417. }
  418. }
  419. var Vector3$1 = Laya.Vector3;
  420. class NpcControl {
  421. constructor() {
  422. this.NpcCharacter = true;
  423. this.FowardHit = new Laya.HitResult();
  424. this.move = true;
  425. this.ChargeSpeed = 0;
  426. this.rundir = new Laya.Vector3();
  427. this.rolepos = new Laya.Vector3();
  428. this.curspeed = 0;
  429. NpcControl.ins = this;
  430. DispatcherControl.StageOn(StageState.Start, this, this.Start);
  431. DispatcherControl.StageOn(StageState.Lose, this, this.GameOver);
  432. DispatcherControl.StageOn(StageState.Win, this, this.GameOver);
  433. DispatcherControl.StageOn(StageState.TimeOver, this, this.GameOver);
  434. }
  435. static get Instance() {
  436. if (NpcControl.ins) {
  437. return NpcControl.ins;
  438. }
  439. else {
  440. return new NpcControl();
  441. }
  442. }
  443. Init(_model, _characterdata) {
  444. var Npc = new NpcControl();
  445. Npc.CurCharacterData = _characterdata;
  446. Npc.CurCharacterData.Model = _model;
  447. Npc.CurCharacterData.Animator = _model.getComponent(Laya.Animator);
  448. return Npc;
  449. }
  450. Start() {
  451. Laya.timer.frameLoop(1, this, this.LateUpdate);
  452. }
  453. GameOver() {
  454. Laya.timer.clear(this, this.LateUpdate);
  455. }
  456. LateUpdate() {
  457. this.RayCheck();
  458. this.Move();
  459. }
  460. Move() {
  461. if (this.move) {
  462. if (this.NpcCharacter) {
  463. var speed = this.CurCharacterData.Speed;
  464. this.ChargeSpeed = GameTools.Instance.lerp(this.ChargeSpeed, 0, 0.1);
  465. speed = this.CurCharacterData.Speed + this.ChargeSpeed;
  466. this.curspeed = GameTools.Instance.lerp(this.curspeed, speed, 0.04);
  467. Vector3$1.scale(new Vector3$1(0, 0, 1), this.curspeed, this.rundir);
  468. Vector3$1.add(this.CurCharacterData.Model.transform.position, this.rundir, this.rolepos);
  469. Vector3$1.lerp(this.CurCharacterData.Model.transform.position, this.rolepos, 0.15, this.rolepos);
  470. this.CurCharacterData.Model.transform.position = this.rolepos;
  471. }
  472. }
  473. }
  474. RayCheck() {
  475. if (this.FowardRayCheck) {
  476. let dir = Math.random();
  477. if (dir < 0.25) {
  478. this.CurCharacterData.Model.transform.rotationEuler = new Vector3$1(this.CurCharacterData.Model.transform.rotationEuler.x, 90, this.CurCharacterData.Model.transform.rotationEuler.z);
  479. }
  480. else if (dir >= 0.25 && dir < 0.5) {
  481. this.CurCharacterData.Model.transform.rotationEuler = new Vector3$1(this.CurCharacterData.Model.transform.rotationEuler.x, -90, this.CurCharacterData.Model.transform.rotationEuler.z);
  482. }
  483. else if (dir >= 0.5 && dir < 0.75) {
  484. this.CurCharacterData.Model.transform.rotationEuler = new Vector3$1(this.CurCharacterData.Model.transform.rotationEuler.x, 180, this.CurCharacterData.Model.transform.localRotationEuler.z);
  485. }
  486. else if (dir >= 0.75 && dir < 1) {
  487. this.CurCharacterData.Model.transform.rotationEuler = new Vector3$1(this.CurCharacterData.Model.transform.rotationEuler.x, -180, this.CurCharacterData.Model.transform.rotationEuler.z);
  488. }
  489. }
  490. }
  491. get FowardRayCheck() {
  492. var isFowardHit = false;
  493. var startPos = new Vector3$1(this.CurCharacterData.Model.transform.position.x, this.CurCharacterData.Model.transform.position.y + 0.5, this.CurCharacterData.Model.transform.position.z);
  494. var direction = new Vector3$1(0, 0, 1);
  495. var FowardRay = new Laya.Ray(startPos, direction);
  496. if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(FowardRay, this.FowardHit, 0.5)) {
  497. if (this.FowardHit.collider.collisionGroup == 200 && this.FowardHit.collider != this.ForwardTarget || this.FowardHit.collider.owner.name == "Wall" || this.FowardHit.collider.owner.name == "build") {
  498. this.ForwardTarget = this.FowardHit.collider;
  499. isFowardHit = true;
  500. }
  501. }
  502. return isFowardHit;
  503. }
  504. }
  505. var Vector3$2 = Laya.Vector3;
  506. class PlayerControl {
  507. constructor() {
  508. this.curtouchsmoothness = 0.02;
  509. this.offx = 0;
  510. this.offz = 0;
  511. this.poschazhi = new Vector3$2();
  512. this.gengsuipos = new Vector3$2();
  513. this.lllpos = new Vector3$2();
  514. this.hights = 0;
  515. this.wights = 0;
  516. PlayerControl.ins = this;
  517. }
  518. static get Instance() {
  519. if (PlayerControl.ins) {
  520. return PlayerControl.ins;
  521. }
  522. else {
  523. return new PlayerControl();
  524. }
  525. }
  526. Init(_npccontrol) {
  527. this.NPC = _npccontrol;
  528. this.Player = _npccontrol.CurCharacterData.Model;
  529. this.maincamera = AssetManager.Instance.maincamera;
  530. console.log(this.maincamera.transform.rotationEuler);
  531. this.maincamera.transform.position = new Laya.Vector3(19.5, 40, 16.7);
  532. Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.TouchEnter);
  533. Laya.stage.on(Laya.Event.MOUSE_UP, this, this.OnTouchOut);
  534. Laya.stage.on(Laya.Event.MOUSE_OUT, this, this.OnTouchOut);
  535. this.CameraFollow();
  536. }
  537. TouchEnter() {
  538. this.mousepos = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  539. Laya.timer.clear(this, this.OnTouchMove);
  540. Laya.timer.frameLoop(1, this, this.OnTouchMove);
  541. }
  542. OnTouchOut() {
  543. Laya.timer.clear(this, this.OnTouchMove);
  544. }
  545. OnTouchMove() {
  546. var MousePos = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  547. var offestX = MousePos.x - this.mousepos.x;
  548. var offestZ = MousePos.y - this.mousepos.y;
  549. offestX = offestX > 200 ? 200 : offestX;
  550. offestX = offestX < -200 ? -200 : offestX;
  551. offestZ = offestZ > 200 ? 200 : offestZ;
  552. offestZ = offestZ < -200 ? -200 : offestZ;
  553. this.offx = GameTools.Instance.lerp(this.offx, offestX, this.curtouchsmoothness);
  554. this.offz = GameTools.Instance.lerp(this.offz, offestZ, this.curtouchsmoothness);
  555. var movespeedx = this.offx * 0.04;
  556. var movespeedz = this.offz * 0.04;
  557. this.ChangeDirection();
  558. this.Player.transform.translate(new Vector3$2(movespeedz, 0, -movespeedx));
  559. var dir = new Laya.Vector3(-offestX * 0.001, 0, 0);
  560. this.mousepos = MousePos;
  561. }
  562. ChangeDirection() {
  563. let point = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  564. let Ray = new Laya.Ray(new Vector3$2(0, 0, 0), new Vector3$2(0, 0, 0));
  565. let enemyhit = new Laya.HitResult();
  566. AssetManager.Instance.maincamera.viewportPointToRay(point, Ray);
  567. if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(Ray, enemyhit, 10000)) {
  568. let target = enemyhit.collider.owner;
  569. if (target.name == "build" || target.name == "ground") {
  570. var position = enemyhit.point;
  571. position.y = this.Player.transform.position.y;
  572. }
  573. }
  574. }
  575. CameraFollow() {
  576. this.hights = 0;
  577. this.wights = 0;
  578. Vector3$2.subtract(this.Player.transform.position, this.maincamera.transform.position, this.poschazhi);
  579. Laya.timer.frameLoop(1, this, this.Follow);
  580. }
  581. Follow() {
  582. Vector3$2.subtract(this.Player.transform.position, this.poschazhi, this.gengsuipos);
  583. this.hights = GameTools.Instance.lerp(this.hights, 1.0, 0.03);
  584. this.wights = GameTools.Instance.lerp(this.wights, 0.8, 0.02);
  585. this.gengsuipos = new Vector3$2(this.gengsuipos.x + this.hights, this.gengsuipos.y, this.gengsuipos.z + this.wights);
  586. Vector3$2.lerp(this.maincamera.transform.position, this.gengsuipos, 0.25, this.lllpos);
  587. this.lllpos = new Vector3$2(this.gengsuipos.x + 20, this.lllpos.y, this.lllpos.z);
  588. this.maincamera.transform.position = this.lllpos;
  589. var qqqwe = new Laya.Quaternion();
  590. var eyePos = new Vector3$2(this.gengsuipos.x, this.gengsuipos.y, this.gengsuipos.z);
  591. Laya.Quaternion.lookAt(eyePos, this.Player.transform.position, new Vector3$2(0, 1, 0), qqqwe);
  592. qqqwe.invert(qqqwe);
  593. Laya.Quaternion.slerp(this.maincamera.transform.rotation, qqqwe, 0.1, qqqwe);
  594. this.maincamera.transform.rotationEuler = new Laya.Vector3(-45, 90, 0);
  595. }
  596. }
  597. class MainGame {
  598. constructor() {
  599. this.TransformUp = new Laya.Vector3(0, 0.5, 0);
  600. this.CharacterArray = [];
  601. DispatcherControl.DispatcherOn(DispatcherState.SceneInit, this, this.Init);
  602. MainGame.ins = this;
  603. }
  604. static get Instance() {
  605. if (MainGame.ins) {
  606. return MainGame.ins;
  607. }
  608. else {
  609. return new MainGame();
  610. }
  611. }
  612. Init() {
  613. this.mainscene = AssetManager.Instance.mainscene;
  614. this.CreatCharacter();
  615. Laya.stage.addChildAt(this.mainscene, 0);
  616. }
  617. CreatCharacter() {
  618. this.CreatPlayer();
  619. this.CreatNpc();
  620. DispatcherControl.StageTrigger(StageState.Start);
  621. }
  622. CreatPlayer() {
  623. let playermodel = GamePool.Instance.GetModel(AssetManager.Instance.Character.get(1), "");
  624. playermodel.transform.position = new Laya.Vector3(19.5, 25, 16.7);
  625. playermodel.transform.localScale = new Laya.Vector3(1, 1, 1);
  626. AssetManager.Instance.mainscene.addChild(playermodel);
  627. this.AddBooldUI(playermodel);
  628. let _characterdata = new CharacterData();
  629. var npc = NpcControl.Instance.Init(playermodel, _characterdata);
  630. npc.NpcCharacter = false;
  631. PlayerControl.Instance.Init(npc);
  632. this.CharacterArray.push(npc);
  633. }
  634. CreatNpc() {
  635. for (let i = 0; i < 10; i++) {
  636. let npcmodel = GamePool.Instance.GetModel(AssetManager.Instance.Zombie.get(1), "");
  637. let X = GameTools.RandomANumber(-50, 50);
  638. let Z = GameTools.RandomANumber(-50, 50);
  639. npcmodel.transform.position = new Laya.Vector3(X, 25, Z);
  640. npcmodel.transform.localScale = new Laya.Vector3(1, 1, 1);
  641. npcmodel.transform.localRotationEuler = new Laya.Vector3(0, 0, 0);
  642. AssetManager.Instance.mainscene.addChild(npcmodel);
  643. this.AddBooldUI(npcmodel);
  644. let _characterdata = new CharacterData();
  645. var npc = NpcControl.Instance.Init(npcmodel, _characterdata);
  646. this.CharacterArray.push(npc);
  647. }
  648. }
  649. AddBooldUI(_sprite3D) {
  650. let bloodprogress = new Laya.ProgressBar();
  651. let screenposition = new Laya.Vector3();
  652. bloodprogress.skin = "Game/res/Resources/jiazai.png";
  653. bloodprogress.value = 0.9;
  654. let role_position = _sprite3D.transform.position;
  655. AssetManager.Instance.maincamera.worldToViewportPoint(role_position, screenposition);
  656. bloodprogress.pos(screenposition.x, screenposition.y);
  657. console.log("X--", bloodprogress.x);
  658. console.log("Y--", bloodprogress.y);
  659. AssetManager.Instance.mainscene.addChild(bloodprogress);
  660. Laya.stage.addChild(bloodprogress);
  661. }
  662. }
  663. class LoadView {
  664. constructor() {
  665. LoadView.ins = this;
  666. new MainGame();
  667. this.Init();
  668. }
  669. static get Instance() {
  670. if (LoadView.ins) {
  671. return LoadView.ins;
  672. }
  673. else {
  674. return new LoadView();
  675. }
  676. }
  677. Init() {
  678. this.LoadScene();
  679. }
  680. LoadScene() {
  681. Laya.Scene3D.load(ResourcesPath.MainScene, Laya.Handler.create(this, (scene) => {
  682. this.mainscene = scene;
  683. AssetManager.Instance.mainscene = this.mainscene;
  684. console.log("场景加载完毕--");
  685. this.LoadZombie();
  686. }));
  687. }
  688. LoadZombie() {
  689. var path = [];
  690. for (let i = 0; i < ResourcesPath.Zombie.length; i++) {
  691. path.push(ResourcesPath.Zombie[i]);
  692. }
  693. Laya.loader.create(path, Laya.Handler.create(this, () => {
  694. for (var i = 0; i < ResourcesPath.Zombie.length; i++) {
  695. var people = Laya.loader.getRes(ResourcesPath.Zombie[i]);
  696. AssetManager.Instance.Zombie.set(i + 1, people);
  697. Laya.loader.clearRes(ResourcesPath.Zombie[i]);
  698. }
  699. }));
  700. console.log("僵尸模型加载完毕--");
  701. this.LoadCharacter();
  702. }
  703. LoadCharacter() {
  704. var path = [];
  705. for (let i = 0; i < ResourcesPath.Character.length; i++) {
  706. path.push(ResourcesPath.Character[i]);
  707. }
  708. Laya.loader.create(path, Laya.Handler.create(this, () => {
  709. for (var i = 0; i < ResourcesPath.Character.length; i++) {
  710. var people = Laya.loader.getRes(ResourcesPath.Character[i]);
  711. AssetManager.Instance.Character.set(i + 1, people);
  712. Laya.loader.clearRes(ResourcesPath.Character[i]);
  713. }
  714. DispatcherControl.DispatcherTrigger(DispatcherState.LoadComplete);
  715. }));
  716. console.log("人物模型加载完毕--");
  717. }
  718. }
  719. class CheckMain {
  720. }
  721. CheckMain.Create = false;
  722. class Main {
  723. constructor() {
  724. if (CheckMain.Create)
  725. return;
  726. CheckMain.Create = true;
  727. if (window["Laya3D"])
  728. Laya3D.init(GameConfig.width, GameConfig.height);
  729. else
  730. Laya.init(GameConfig.width, GameConfig.height, Laya["WebGL"]);
  731. Laya["Physics"] && Laya["Physics"].enable();
  732. Laya["DebugPanel"] && Laya["DebugPanel"].enable();
  733. Laya.stage.scaleMode = GameConfig.scaleMode;
  734. Laya.stage.screenMode = GameConfig.screenMode;
  735. Laya.stage.alignV = GameConfig.alignV;
  736. Laya.stage.alignH = GameConfig.alignH;
  737. Laya.URL.exportSceneToJson = GameConfig.exportSceneToJson;
  738. if (GameConfig.debug || Laya.Utils.getQueryString("debug") == "true")
  739. Laya.enableDebugPanel();
  740. if (GameConfig.physicsDebug && Laya["PhysicsDebugDraw"])
  741. Laya["PhysicsDebugDraw"].enable();
  742. if (GameConfig.stat)
  743. Laya.Stat.show();
  744. Laya.alertGlobalError = true;
  745. Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.onVersionLoaded), Laya.ResourceVersion.FILENAME_VERSION);
  746. }
  747. onVersionLoaded() {
  748. Laya.AtlasInfoManager.enable("fileconfig.json", Laya.Handler.create(this, this.onConfigLoaded));
  749. }
  750. onConfigLoaded() {
  751. new LoadView();
  752. }
  753. }
  754. new Main();
  755. }());
  756. //# sourceMappingURL=bundle.js.map