bundle.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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 = "MainGameView.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 EventState;
  62. (function (EventState) {
  63. EventState[EventState["LoadComplete"] = 0] = "LoadComplete";
  64. EventState[EventState["SceneInit"] = 1] = "SceneInit";
  65. EventState[EventState["StageInit"] = 2] = "StageInit";
  66. EventState[EventState["StageCreateComplete"] = 3] = "StageCreateComplete";
  67. EventState[EventState["AnimatorEnd"] = 4] = "AnimatorEnd";
  68. })(EventState || (EventState = {}));
  69. var StageState;
  70. (function (StageState) {
  71. StageState[StageState["Win"] = 0] = "Win";
  72. StageState[StageState["Lose"] = 1] = "Lose";
  73. StageState[StageState["Start"] = 2] = "Start";
  74. StageState[StageState["StageCreateComPlete"] = 3] = "StageCreateComPlete";
  75. StageState[StageState["Over"] = 4] = "Over";
  76. })(StageState || (StageState = {}));
  77. class EventManager {
  78. static EventOn(_mode, caller, fun, args = []) {
  79. EventManager.instance.on(EventState[_mode], caller, fun, args);
  80. }
  81. static EventOff(_mode, caller, fun, args = []) {
  82. EventManager.instance.off(EventState[_mode], caller, fun);
  83. }
  84. static EventTrigger(_mode, args = []) {
  85. EventManager.instance.event(EventState[_mode], args);
  86. }
  87. static StageOn(_mode, caller, fun, args = []) {
  88. EventManager.instance.on(StageState[_mode], caller, fun, args);
  89. }
  90. static StageOff(_mode, caller, fun, args = []) {
  91. EventManager.instance.off(StageState[_mode], caller, fun);
  92. }
  93. static StageTrigger(_mode, args = []) {
  94. EventManager.instance.event(StageState[_mode], args);
  95. }
  96. }
  97. EventManager.instance = new Laya.EventDispatcher();
  98. class GameTools {
  99. constructor() {
  100. GameTools.ins = this;
  101. }
  102. static get Instance() {
  103. if (GameTools.ins) {
  104. return GameTools.ins;
  105. }
  106. else {
  107. return new GameTools();
  108. }
  109. }
  110. lerp(form, to, t) {
  111. if (t <= 0) {
  112. return form;
  113. }
  114. else if (t >= 1) {
  115. return to;
  116. }
  117. var a = t * to + (1 - t) * form;
  118. return a;
  119. }
  120. SetCollider(setNode, CollisionGroup) {
  121. var numchild = setNode.numChildren;
  122. for (var i = 0; i < setNode.numChildren; i++) {
  123. var numchild2 = setNode.getChildAt(i).numChildren;
  124. if (numchild2 > 1) {
  125. this.SetCollider(setNode.getChildAt(i), CollisionGroup);
  126. }
  127. var physicsCollider = setNode.getChildAt(i).getComponent(Laya.PhysicsCollider);
  128. if (physicsCollider) {
  129. physicsCollider.collisionGroup = CollisionGroup;
  130. }
  131. }
  132. }
  133. static RandomNumber(from, to) {
  134. if (from >= to) {
  135. return 0;
  136. }
  137. var size = to - from;
  138. var curNumber = Math.random() * size + from;
  139. return curNumber;
  140. }
  141. static RandomANumber(from, to) {
  142. if (from >= to) {
  143. return 0;
  144. }
  145. var size = to - from;
  146. var curNumber = Math.random() * size + from;
  147. return Math.floor(curNumber);
  148. }
  149. static GetMoney(_num, _pos = null, _completeHandle = null) {
  150. if (_num == 0)
  151. return;
  152. var fafaafsfa = new Laya.Box;
  153. fafaafsfa.width = 400;
  154. fafaafsfa.height = 100;
  155. fafaafsfa.pivotX = fafaafsfa.width / 2;
  156. fafaafsfa.pivotY = fafaafsfa.height / 2;
  157. if (_pos == null) {
  158. _pos = new Laya.Vector2(Laya.stage.width / 2, Laya.stage.height / 2);
  159. }
  160. fafaafsfa.pos(_pos.x, _pos.y);
  161. var aafafaffa = new Laya.Image;
  162. aafafaffa.skin = "game/qiandao_1_7.png";
  163. aafafaffa.width = 60;
  164. aafafaffa.height = 60;
  165. aafafaffa.left = 50;
  166. aafafaffa.y = 10;
  167. fafaafsfa.addChild(aafafaffa);
  168. var faasfafsafs = new Laya.Text;
  169. faasfafsafs.width = 300;
  170. faasfafsafs.height = 50;
  171. faasfafsafs.align = "center";
  172. faasfafsafs.valign = "middle";
  173. faasfafsafs.font = "Microsoft YaHei";
  174. faasfafsafs.fontSize = 40;
  175. faasfafsafs.color = "#FFFFFF";
  176. faasfafsafs.bold = true;
  177. faasfafsafs.font = "Microsoft YaHei";
  178. faasfafsafs.text = "金币 +" + _num;
  179. faasfafsafs.x = 60;
  180. faasfafsafs.y = 10;
  181. fafaafsfa.addChild(faasfafsafs);
  182. Laya.stage.addChild(fafaafsfa);
  183. var faasfsaf = Laya.Tween.to(fafaafsfa, { y: fafaafsfa.y - 200 }, 1500, Laya.Ease.expoInOut, Laya.Handler.create(this, () => {
  184. faasfsaf.clear();
  185. fafaafsfa.destroy();
  186. if (_completeHandle) {
  187. _completeHandle.run();
  188. }
  189. }), 100);
  190. }
  191. static TweenText(faafssfafsa, _hight, _completeHandle = null, hide = true, _duration = 500) {
  192. var afasafsafsfa = new Laya.Text();
  193. afasafsafsfa.width = faafssfafsa.size.x;
  194. afasafsafsfa.height = faafssfafsa.size.y;
  195. afasafsafsfa.align = "center";
  196. afasafsafsfa.valign = "middle";
  197. afasafsafsfa.font = "Microsoft YaHei";
  198. afasafsafsfa.fontSize = faafssfafsa.fontSize;
  199. afasafsafsfa.pivotX = afasafsafsfa.width / 2;
  200. afasafsafsfa.pivotY = afasafsafsfa.height / 2;
  201. afasafsafsfa.color = "#5ad122";
  202. afasafsafsfa.bold = true;
  203. afasafsafsfa.stroke = 5;
  204. afasafsafsfa.strokeColor = "#ffffff";
  205. if (faafssfafsa.color) {
  206. faafssfafsa.color = faafssfafsa.color;
  207. }
  208. afasafsafsfa.text = faafssfafsa.message;
  209. afasafsafsfa.zOrder = 1;
  210. Laya.stage.addChildAt(afasafsafsfa, Laya.stage.numChildren - 1);
  211. afasafsafsfa.pos(faafssfafsa.pos.x, faafssfafsa.pos.y);
  212. var tween = Laya.Tween.to(afasafsafsfa, { y: afasafsafsfa.y - _hight, update: new Laya.Handler(this, function () {
  213. }) }, _duration, Laya.Ease.expoInOut, Laya.Handler.create(this, function () {
  214. tween.clear();
  215. if (hide) {
  216. afasafsafsfa.destroy();
  217. }
  218. if (_completeHandle) {
  219. _completeHandle.run();
  220. }
  221. }));
  222. if (hide) {
  223. Laya.Tween.to(afasafsafsfa, { alpha: 0.4 }, 500);
  224. }
  225. return afasafsafsfa;
  226. }
  227. static StationTweenText(faafssfafsa, _hight, _completeHandle = null, hide = true, _duration = 500) {
  228. var afasafsafsfa = new Laya.Text();
  229. afasafsafsfa.width = faafssfafsa.size.x;
  230. afasafsafsfa.height = faafssfafsa.size.y;
  231. afasafsafsfa.align = "center";
  232. afasafsafsfa.valign = "middle";
  233. afasafsafsfa.font = "Microsoft YaHei";
  234. afasafsafsfa.fontSize = 50;
  235. afasafsafsfa.pivotX = afasafsafsfa.width / 2;
  236. afasafsafsfa.pivotY = afasafsafsfa.height / 2;
  237. afasafsafsfa.color = "#5ad122";
  238. afasafsafsfa.bold = true;
  239. afasafsafsfa.stroke = 5;
  240. afasafsafsfa.strokeColor = "#ffffff";
  241. if (faafssfafsa.color) {
  242. faafssfafsa.color = faafssfafsa.color;
  243. }
  244. afasafsafsfa.text = faafssfafsa.message;
  245. afasafsafsfa.zOrder = 1;
  246. Laya.stage.addChildAt(afasafsafsfa, Laya.stage.numChildren - 1);
  247. afasafsafsfa.pos(faafssfafsa.pos.x, faafssfafsa.pos.y);
  248. var tween = Laya.Tween.to(afasafsafsfa, { y: afasafsafsfa.y - _hight, update: new Laya.Handler(this, function () {
  249. }) }, _duration, Laya.Ease.expoInOut, Laya.Handler.create(this, function () {
  250. tween.clear();
  251. if (hide) {
  252. afasafsafsfa.destroy();
  253. }
  254. if (_completeHandle) {
  255. _completeHandle.run();
  256. }
  257. }));
  258. if (hide) {
  259. Laya.Tween.to(afasafsafsfa, { alpha: 0.4 }, 10000);
  260. }
  261. return afasafsafsfa;
  262. }
  263. static tweenMove(transform, targPos, delay, ease, complete) {
  264. let curPos = transform.position.clone();
  265. return Laya.Tween.to(curPos, {
  266. x: targPos.x,
  267. y: targPos.y,
  268. z: targPos.z,
  269. update: new Laya.Handler(this, () => {
  270. transform.position = curPos.clone();
  271. })
  272. }, delay, ease, complete);
  273. }
  274. static tweenRotate(transform, targEuler, delay, ease, complete) {
  275. let curEuler = transform.rotationEuler.clone();
  276. return Laya.Tween.to(curEuler, {
  277. x: targEuler.x,
  278. y: targEuler.y,
  279. z: targEuler.z,
  280. update: new Laya.Handler(this, () => {
  281. transform.rotationEuler = curEuler.clone();
  282. })
  283. }, delay, ease, complete);
  284. }
  285. }
  286. class AssetManager {
  287. constructor() {
  288. this.Player = new ResDic();
  289. this.Enemy = new ResDic();
  290. this.Horse = new ResDic();
  291. this.Prop = new ResDic();
  292. AssetManager.ins = this;
  293. EventManager.EventOn(EventState.LoadComplete, this, this.Init);
  294. }
  295. static get Instance() {
  296. if (AssetManager.ins) {
  297. return AssetManager.ins;
  298. }
  299. else {
  300. return new AssetManager();
  301. }
  302. }
  303. Init() {
  304. this.maincamera = this.mainscene.getChildByName("Main Camera");
  305. this.Plane = this.mainscene.getChildByName("Plane");
  306. GameTools.Instance.SetCollider(this.Plane, 100);
  307. EventManager.EventTrigger(EventState.SceneInit);
  308. }
  309. }
  310. class ResourcesPath {
  311. }
  312. ResourcesPath.MainScene = "Game/res/MainScene/LayaScene_Mainscene/Conventional/Mainscene.ls";
  313. ResourcesPath.Horse = [
  314. "Game/res/Role/LayaScene_Role/Conventional/Horse.lh"
  315. ];
  316. ResourcesPath.Player = [
  317. "Game/res/Role/LayaScene_Role/Conventional/player.lh"
  318. ];
  319. ResourcesPath.Enemy = [
  320. "Game/res/Role/LayaScene_Role/Conventional/enemy.lh"
  321. ];
  322. ResourcesPath.Prop = [
  323. "Game/res/Prop/LayaScene_Prop/Conventional/Archer"
  324. ];
  325. var Sprite3D = Laya.Sprite3D;
  326. var Vector3 = Laya.Vector3;
  327. class modelConfig {
  328. constructor(model) {
  329. this.modelcur = model;
  330. this.modelPos = model.transform.position.clone();
  331. this.modelRot = model.transform.rotation.clone();
  332. this.modelSca = model.transform.scale.clone();
  333. }
  334. }
  335. class GamePool {
  336. constructor() {
  337. this.modelpool = {};
  338. this.maxAcount = 30;
  339. GamePool.Ins = this;
  340. }
  341. static get Instance() {
  342. if (GamePool.Ins) {
  343. return GamePool.Ins;
  344. }
  345. else {
  346. return new GamePool();
  347. }
  348. }
  349. GetModel(_model, title) {
  350. var poolname = title + _model.name;
  351. if (this.modelpool[poolname] != null && this.modelpool[poolname] != undefined) {
  352. if (this.modelpool[poolname].length > 0) {
  353. var model1 = this.modelpool[poolname][0];
  354. this.modelpool[poolname].splice(0, 1);
  355. if (model1.modelcur.destroyed) {
  356. model1.modelcur = Sprite3D.instantiate(_model);
  357. if (!model1.modelcur.active) {
  358. model1.modelcur.active = true;
  359. }
  360. }
  361. model1.modelcur.active = true;
  362. model1.modelcur.transform.position = _model.transform.position.clone();
  363. model1.modelcur.transform.rotation = _model.transform.rotation.clone();
  364. model1.modelcur.transform.scale = _model.transform.scale.clone();
  365. return model1.modelcur;
  366. }
  367. else {
  368. var model = Sprite3D.instantiate(_model);
  369. model.active = true;
  370. return model;
  371. }
  372. }
  373. else {
  374. var model = Sprite3D.instantiate(_model);
  375. model.active = true;
  376. return model;
  377. }
  378. }
  379. RecoveryModel(model, title = "", modelstate = false) {
  380. if (model.destroyed) {
  381. return;
  382. }
  383. if (!modelstate && model.active == false) {
  384. return;
  385. }
  386. var poolname = title + model.name;
  387. if (this.modelpool[poolname] != null && this.modelpool[poolname] != undefined) {
  388. var modelnum = this.modelpool[poolname];
  389. if (modelnum.length > this.maxAcount) {
  390. model.destroy();
  391. return;
  392. }
  393. else {
  394. modelnum.push(new modelConfig(model));
  395. }
  396. }
  397. else {
  398. modelnum = [];
  399. modelnum.push(new modelConfig(model));
  400. this.modelpool[poolname] = modelnum;
  401. }
  402. model.transform.position = new Vector3(0, 0, -10000);
  403. model.removeSelf();
  404. model.active = false;
  405. }
  406. ResetsModelPool() {
  407. for (var Key in this.modelpool) {
  408. var model = this.modelpool[Key];
  409. for (var i = 0; i < model.length; i++) {
  410. model[i].modelcur.destroy();
  411. }
  412. }
  413. this.modelpool = {};
  414. }
  415. }
  416. var Vector3$1 = Laya.Vector3;
  417. var CharacterState;
  418. (function (CharacterState) {
  419. CharacterState[CharacterState["Run"] = 0] = "Run";
  420. CharacterState[CharacterState["Idle"] = 1] = "Idle";
  421. CharacterState[CharacterState["Die"] = 2] = "Die";
  422. CharacterState[CharacterState["Win"] = 3] = "Win";
  423. CharacterState[CharacterState["Shoot"] = 4] = "Shoot";
  424. })(CharacterState || (CharacterState = {}));
  425. class Runner extends Laya.Script3D {
  426. constructor() {
  427. super();
  428. this.canmove = false;
  429. this._speed = 1;
  430. this._press = false;
  431. this.DownHit = new Laya.HitResult();
  432. this.FowardHit = new Laya.HitResult();
  433. this.curspeed = 0;
  434. this.currotV = new Vector3$1();
  435. this.currot = new Laya.Quaternion;
  436. this.NormalizeSpeed = new Vector3$1();
  437. this.curpos = new Vector3$1();
  438. this.offest = new Vector3$1();
  439. }
  440. static get Instance() {
  441. if (Runner.ins) {
  442. return Runner.ins;
  443. }
  444. else {
  445. return new Runner();
  446. }
  447. }
  448. onAwake() {
  449. this.m_player = this.owner;
  450. this.m_animator = this.owner.getComponent(Laya.Animator);
  451. this.m_horseanimator = this.owner.getChildAt(1).getComponent(Laya.Animator);
  452. this.ChangeState(CharacterState.Idle);
  453. EventManager.StageOn(StageState.Start, this, this.Begin);
  454. }
  455. Begin() {
  456. this.canmove = true;
  457. this.ChangeState(CharacterState.Run);
  458. }
  459. onUpdate() {
  460. if (this.canmove) {
  461. if (this._press) {
  462. this._speed = 2;
  463. }
  464. this.Move(new Vector3$1(0, 0, 1), this._speed);
  465. }
  466. this.RayCheck();
  467. }
  468. MoveX(_speed) {
  469. _speed *= 0.07;
  470. this.m_player.transform.translate(new Vector3$1(_speed, 0, 0));
  471. }
  472. TurnDir(_dir) {
  473. if (_dir.x != 0) {
  474. Vector3$1.lerp(this.currotV, _dir, 0.35, _dir);
  475. this.currotV = _dir;
  476. Laya.Quaternion.rotationLookAt(_dir, new Vector3$1(0, 1, 0), this.currot);
  477. Laya.Quaternion.slerp(this.m_player.transform.rotation, this.currot, 0.025, this.currot);
  478. this.currot = new Laya.Quaternion(0, this.currot.y, 0);
  479. this.m_player.transform.rotation = this.currot;
  480. }
  481. else {
  482. Laya.Quaternion.slerp(this.m_player.transform.rotation, new Laya.Quaternion(0, 0, 0, 0), 0.1, this.currot);
  483. this.currot = new Laya.Quaternion(0, this.currot.y, 0);
  484. this.m_player.transform.rotation = this.currot;
  485. }
  486. }
  487. Move(_dir, _speed) {
  488. var sp = GameTools.Instance.lerp(this.curspeed, _speed, 0.1);
  489. this.curspeed = sp;
  490. Vector3$1.scale(_dir, this.curspeed, this.offest);
  491. Vector3$1.add(this.m_player.transform.position, this.offest, this.curpos);
  492. Vector3$1.lerp(this.m_player.transform.position, this.curpos, 0.15, this.curpos);
  493. this.curpos = new Vector3$1(this.curpos.x, this.curpos.y, this.curpos.z);
  494. this.m_player.transform.position = this.curpos;
  495. }
  496. ChangeState(_state) {
  497. if (this.m_characterstate == _state)
  498. return;
  499. this.m_characterstate = _state;
  500. switch (this.m_characterstate) {
  501. case CharacterState.Idle:
  502. this.Idle();
  503. break;
  504. case CharacterState.Run:
  505. this.Run();
  506. break;
  507. case CharacterState.Die:
  508. this.Die();
  509. break;
  510. case CharacterState.Win:
  511. this.Win();
  512. break;
  513. case CharacterState.Shoot:
  514. this.Shoot();
  515. break;
  516. }
  517. }
  518. Idle() {
  519. this.m_animator.play("Idle");
  520. this.m_horseanimator.play("Horse_Idle");
  521. }
  522. Run() {
  523. this.m_animator.play("Idle");
  524. this.m_horseanimator.play("Horse_Run");
  525. }
  526. Die() {
  527. }
  528. Win() {
  529. }
  530. Shoot() {
  531. this.m_animator.play("aimshoot");
  532. this.m_animator.play("Horse_Run");
  533. }
  534. RayCheck() {
  535. if (this.DownRayCheck) ;
  536. if (this.FowardRayCheck) {
  537. this.CrashBarrier();
  538. }
  539. }
  540. CrashBarrier() {
  541. var target = this.FowardHit.collider.owner;
  542. if (target.name == "") ;
  543. else if (target.name == "") ;
  544. else if (target.name == "") ;
  545. else if (target.name == "") ;
  546. }
  547. get DownRayCheck() {
  548. var isDownHit = false;
  549. var startPos = new Vector3$1(this.m_player.transform.position.x, this.m_player.transform.position.y + 1.5, this.m_player.transform.position.z + 0.5);
  550. var direction = new Vector3$1(0, -1, 0);
  551. var DownRay = new Laya.Ray(startPos, direction);
  552. if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.DownHit, 100)) {
  553. if (this.DownHit.collider.collisionGroup == 100) {
  554. isDownHit = true;
  555. }
  556. }
  557. return isDownHit;
  558. }
  559. get FowardRayCheck() {
  560. var isFowardHit = false;
  561. var startPos = new Vector3$1(this.m_player.transform.position.x, this.m_player.transform.position.y + 1.5, this.m_player.transform.position.z + 0.5);
  562. var direction = new Vector3$1(0, 0, 1);
  563. var DownRay = new Laya.Ray(startPos, direction);
  564. if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.FowardHit, 1)) {
  565. if (this.FowardHit.collider.collisionGroup == 100) {
  566. isFowardHit = true;
  567. }
  568. }
  569. return isFowardHit;
  570. }
  571. }
  572. var Vector2 = Laya.Vector2;
  573. var Vector3$2 = Laya.Vector3;
  574. class PlayerControl {
  575. constructor() {
  576. this.DownHit = new Laya.HitResult();
  577. this.canmove = true;
  578. this.speed = 1;
  579. this.press = false;
  580. this.offset = new Vector3$2(0, 0, 0);
  581. this.offestx = 0;
  582. this.poschazhi = new Vector3$2();
  583. this.gengsuipos = new Vector3$2();
  584. this.lllpos = new Vector3$2();
  585. this.hights = 0;
  586. this.wights = 0;
  587. PlayerControl.ins = this;
  588. }
  589. static get Instance() {
  590. if (PlayerControl.ins) {
  591. return PlayerControl.ins;
  592. }
  593. else {
  594. return new PlayerControl();
  595. }
  596. }
  597. Init(_player) {
  598. this.Player = _player;
  599. this._runner = this.Player.addComponent(Runner);
  600. this.Player.transform.position = new Vector3$2();
  601. this.Camera = AssetManager.Instance.maincamera;
  602. this.Camera.transform.position = new Vector3$2(0, 10, -15);
  603. this.Camera.transform.localRotationEuler = new Vector3$2(-5, 0, 0);
  604. Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.onMouseDown);
  605. this.CameraFollow();
  606. }
  607. onMouseDown(e) {
  608. if (!this._runner.canmove)
  609. return;
  610. this._runner._press = true;
  611. this.mouseDownTime = Laya.Browser.now();
  612. this.startMousePos = new Vector3$2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  613. var startpoint = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  614. this.curMousePos = this.startMousePos.clone();
  615. this.curMousePos1 = startpoint.clone();
  616. Laya.timer.frameLoop(1, this, this.onMouseMove);
  617. Laya.stage.on(Laya.Event.MOUSE_UP, this, this.onMouseUp);
  618. Laya.stage.on(Laya.Event.MOUSE_OUT, this, this.onMouseUp);
  619. }
  620. onMouseMove() {
  621. var MousePos = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  622. var offestX = MousePos.x - this.curMousePos1.x;
  623. this.offestx = GameTools.Instance.lerp(this.offestx, offestX, 0.015);
  624. this._runner.MoveX(-this.offestx);
  625. var dir = new Vector3$2(-offestX * 0.005, 0, 0);
  626. this._runner.TurnDir(dir);
  627. this.curMousePos1 = new Vector2(MousePos.x, MousePos.y);
  628. }
  629. onMouseUp() {
  630. this.offestx = 0;
  631. Laya.timer.clear(this, this.onMouseMove);
  632. this._runner._press = false;
  633. if (!this.startMousePos)
  634. return;
  635. Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.onMouseMove);
  636. Laya.stage.off(Laya.Event.MOUSE_UP, this, this.onMouseUp);
  637. Laya.stage.off(Laya.Event.MOUSE_OUT, this, this.onMouseUp);
  638. let now = Laya.Browser.now();
  639. let interval = now - this.mouseDownTime;
  640. this.endMousePos = new Vector3$2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  641. let dist = Laya.Vector3.distance(this.endMousePos, this.startMousePos);
  642. if (dist < 50 && interval < 200) {
  643. console.log("shoot--");
  644. }
  645. this.mouseDownTime = now;
  646. }
  647. CameraFollow() {
  648. this.hights = 0;
  649. this.wights = 0;
  650. Vector3$2.subtract(this.Player.transform.position, this.Camera.transform.position, this.poschazhi);
  651. Laya.timer.frameLoop(1, this, this.GenSui);
  652. }
  653. GenSui() {
  654. Vector3$2.subtract(this.Player.transform.position, this.poschazhi, this.gengsuipos);
  655. this.hights = GameTools.Instance.lerp(this.hights, 1.0, 0.03);
  656. this.wights = GameTools.Instance.lerp(this.wights, 0.8, 0.02);
  657. this.gengsuipos = new Vector3$2(this.gengsuipos.x, this.gengsuipos.y, this.gengsuipos.z - this.wights);
  658. Vector3$2.lerp(this.Camera.transform.position, this.gengsuipos, 0.25, this.lllpos);
  659. this.lllpos = new Vector3$2(this.gengsuipos.x, this.gengsuipos.y, this.lllpos.z);
  660. this.lllpos = new Vector3$2(this.gengsuipos.x, this.lllpos.y, this.lllpos.z);
  661. this.Camera.transform.position = this.lllpos;
  662. var qqqwe = new Laya.Quaternion();
  663. var eyePos = new Vector3$2(this.gengsuipos.x, this.gengsuipos.y - 0.8, this.gengsuipos.z);
  664. Laya.Quaternion.lookAt(eyePos, this.Player.transform.position, new Vector3$2(0, 1, 0), qqqwe);
  665. qqqwe.invert(qqqwe);
  666. Laya.Quaternion.slerp(this.Camera.transform.rotation, qqqwe, 0.1, qqqwe);
  667. this.Camera.transform.rotation = qqqwe;
  668. }
  669. get DownRayCheck() {
  670. var isDownHit = false;
  671. var startPos = new Vector3$2(this.Player.transform.position.x, this.Player.transform.position.y + 1.5, this.Player.transform.position.z + 0.5);
  672. var direction = new Vector3$2(0, -1, 0);
  673. var DownRay = new Laya.Ray(startPos, direction);
  674. if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.DownHit, 100)) {
  675. if (this.DownHit.collider.collisionGroup == 100) {
  676. isDownHit = true;
  677. }
  678. }
  679. return isDownHit;
  680. }
  681. }
  682. var REG = Laya.ClassUtils.regClass;
  683. var ui;
  684. (function (ui) {
  685. class InGameViewUI extends Laya.Scene {
  686. constructor() { super(); }
  687. createChildren() {
  688. super.createChildren();
  689. this.createView(InGameViewUI.uiView);
  690. }
  691. }
  692. InGameViewUI.uiView = { "type": "Scene", "props": { "width": 720, "height": 1280 }, "compId": 2, "loadList": [], "loadList3D": [] };
  693. ui.InGameViewUI = InGameViewUI;
  694. REG("ui.InGameViewUI", InGameViewUI);
  695. class MainGameViewUI extends Laya.Scene {
  696. constructor() { super(); }
  697. createChildren() {
  698. super.createChildren();
  699. this.createView(MainGameViewUI.uiView);
  700. }
  701. }
  702. MainGameViewUI.uiView = { "type": "Scene", "props": { "width": 720, "height": 1280 }, "compId": 2, "child": [{ "type": "Button", "props": { "y": 897, "x": 360, "width": 100, "var": "StartBtn", "stateNum": 1, "skin": "comp/button.png", "pivotY": 50, "pivotX": 50, "label": "label", "height": 100 }, "compId": 4 }], "loadList": ["comp/button.png"], "loadList3D": [] };
  703. ui.MainGameViewUI = MainGameViewUI;
  704. REG("ui.MainGameViewUI", MainGameViewUI);
  705. })(ui || (ui = {}));
  706. class MainGameView extends ui.MainGameViewUI {
  707. constructor() {
  708. super();
  709. MainGameView.ins = this;
  710. }
  711. static get Instance() {
  712. if (MainGameView.ins) {
  713. return MainGameView.ins;
  714. }
  715. else {
  716. return new MainGameView();
  717. }
  718. }
  719. Show() {
  720. this.StartBtn.clickHandler = Laya.Handler.create(this, this.ClickStart);
  721. }
  722. Close() {
  723. }
  724. ClickStart() {
  725. EventManager.StageTrigger(StageState.Start);
  726. ViewManager.Instance.ShowView(ViewType.IngameView);
  727. }
  728. }
  729. class InGameView extends ui.InGameViewUI {
  730. constructor() {
  731. super();
  732. InGameView.ins = this;
  733. }
  734. static get Instance() {
  735. if (InGameView.ins) {
  736. return InGameView.ins;
  737. }
  738. else {
  739. return new InGameView();
  740. }
  741. }
  742. Show() {
  743. }
  744. Close() {
  745. }
  746. }
  747. var ViewType;
  748. (function (ViewType) {
  749. ViewType[ViewType["MainView"] = 0] = "MainView";
  750. ViewType[ViewType["IngameView"] = 1] = "IngameView";
  751. })(ViewType || (ViewType = {}));
  752. class ViewManager {
  753. constructor() {
  754. this.showexportview = 0;
  755. this.popViewDic = [];
  756. this.ViewSprite = new Laya.Sprite();
  757. this.OtherViewSprite = new Laya.Sprite();
  758. ViewManager.ins = this;
  759. Laya.stage.addChild(this.ViewSprite);
  760. Laya.stage.addChild(this.OtherViewSprite);
  761. }
  762. static get Instance() {
  763. if (ViewManager.ins) {
  764. return ViewManager.ins;
  765. }
  766. else {
  767. return new ViewManager();
  768. }
  769. }
  770. ShowView(_viewtype, data = null) {
  771. if (this.curView != null) {
  772. this.curView.Close();
  773. this.curView.destroy();
  774. this.curView.removeSelf();
  775. }
  776. this.curView = this.CreateView(_viewtype);
  777. this.curView.name = ViewType[_viewtype];
  778. this.ViewSprite.addChild(this.curView);
  779. this.curView.Show(data);
  780. }
  781. CloseView() {
  782. if (this.curView != null) {
  783. this.curView.Close();
  784. this.curView.destroy();
  785. this.curView.removeSelf();
  786. }
  787. }
  788. OpenPopView(viewType, data = null) {
  789. var popView;
  790. if (this.popViewDic[viewType]) {
  791. popView = this.popViewDic[viewType];
  792. this.OtherViewSprite.setChildIndex(popView, this.OtherViewSprite.numChildren - 1);
  793. popView.visible = true;
  794. }
  795. else {
  796. popView = this.CreateView(viewType);
  797. this.OtherViewSprite.addChild(popView);
  798. this.popViewDic[viewType] = popView;
  799. }
  800. this.showexportview = 1;
  801. popView.OnOpen(data);
  802. }
  803. ClosePopView(viewType) {
  804. var popView = this.popViewDic[viewType];
  805. if (popView == null) {
  806. return;
  807. }
  808. popView.OnHide();
  809. popView.visible = false;
  810. this.showexportview = 0;
  811. }
  812. ClearPopViews() {
  813. }
  814. CreateView(_viewtype) {
  815. switch (_viewtype) {
  816. case ViewType.MainView:
  817. return new MainGameView();
  818. case ViewType.IngameView:
  819. return new InGameView();
  820. }
  821. return null;
  822. }
  823. }
  824. class GameManager {
  825. constructor() {
  826. this.EnemyArray = [];
  827. GameManager.ins = this;
  828. EventManager.EventOn(EventState.SceneInit, this, this.Init);
  829. }
  830. static get Instance() {
  831. if (GameManager.ins) {
  832. return GameManager.ins;
  833. }
  834. else {
  835. return new GameManager();
  836. }
  837. }
  838. Init() {
  839. this.CreatCharacter();
  840. this.mainscene = AssetManager.Instance.mainscene;
  841. Laya.stage.addChildAt(this.mainscene, 0);
  842. ViewManager.Instance.ShowView(ViewType.MainView);
  843. }
  844. CreatCharacter() {
  845. this.CreatPlayer();
  846. this.CreatEnemy();
  847. }
  848. CreatPlayer() {
  849. var playermodel = GamePool.Instance.GetModel(AssetManager.Instance.Player.get(1), "");
  850. var horsemodel = GamePool.Instance.GetModel(AssetManager.Instance.Horse.get(1), "");
  851. playermodel.addChild(horsemodel);
  852. playermodel.transform.position = new Laya.Vector3(0, 0, 0);
  853. horsemodel.transform.localScale = new Laya.Vector3(1, 1, 1);
  854. horsemodel.transform.localPosition = new Laya.Vector3(0, 0, 0);
  855. PlayerControl.Instance.Init(playermodel);
  856. AssetManager.Instance.mainscene.addChild(playermodel);
  857. }
  858. CreatEnemy() {
  859. }
  860. EventListen() {
  861. }
  862. }
  863. class LoadView {
  864. constructor() {
  865. LoadView.ins = this;
  866. this.Init();
  867. }
  868. static get Instance() {
  869. if (LoadView.ins) {
  870. return LoadView.ins;
  871. }
  872. else {
  873. return new LoadView();
  874. }
  875. }
  876. Init() {
  877. new GameManager();
  878. this.LoadScene();
  879. }
  880. LoadComplete() {
  881. console.log("加载完毕--");
  882. EventManager.EventTrigger(EventState.LoadComplete);
  883. }
  884. LoadScene() {
  885. Laya.Scene3D.load(ResourcesPath.MainScene, Laya.Handler.create(this, (scene) => {
  886. this.scene = scene;
  887. AssetManager.Instance.mainscene = this.scene;
  888. console.log("场景加载完毕");
  889. this.LoadEnemy();
  890. }));
  891. }
  892. LoadEnemy() {
  893. var path = [];
  894. for (let i = 0; i < ResourcesPath.Enemy.length; i++) {
  895. path.push(ResourcesPath.Enemy[i]);
  896. }
  897. Laya.loader.create(path, Laya.Handler.create(this, () => {
  898. for (let i = 0; i < ResourcesPath.Enemy.length; i++) {
  899. var model = Laya.loader.getRes(ResourcesPath.Enemy[i]);
  900. AssetManager.Instance.Enemy.set(i + 1, model);
  901. Laya.loader.clearRes(ResourcesPath.Enemy[i]);
  902. }
  903. console.log("敌人模型资源加载完毕---");
  904. this.LoadPlayer();
  905. }));
  906. }
  907. LoadPlayer() {
  908. var path = [];
  909. for (let i = 0; i < ResourcesPath.Player.length; i++) {
  910. path.push(ResourcesPath.Player[i]);
  911. }
  912. Laya.loader.create(path, Laya.Handler.create(this, () => {
  913. for (let i = 0; i < ResourcesPath.Player.length; i++) {
  914. var model = Laya.loader.getRes(ResourcesPath.Player[i]);
  915. AssetManager.Instance.Player.set(i + 1, model);
  916. Laya.loader.clearRes(ResourcesPath.Player[i]);
  917. }
  918. console.log("玩家模型资源加载完毕---");
  919. this.LoadHorse();
  920. }));
  921. }
  922. LoadHorse() {
  923. var path = [];
  924. for (let i = 0; i < ResourcesPath.Horse.length; i++) {
  925. path.push(ResourcesPath.Horse[i]);
  926. }
  927. Laya.loader.create(path, Laya.Handler.create(this, () => {
  928. for (let i = 0; i < ResourcesPath.Horse.length; i++) {
  929. var model = Laya.loader.getRes(ResourcesPath.Horse[i]);
  930. AssetManager.Instance.Horse.set(i + 1, model);
  931. Laya.loader.clearRes(ResourcesPath.Horse[i]);
  932. }
  933. console.log("马模型资源加载完毕---");
  934. this.LoadComplete();
  935. }));
  936. }
  937. }
  938. class Main {
  939. constructor() {
  940. if (window["Laya3D"])
  941. Laya3D.init(GameConfig.width, GameConfig.height);
  942. else
  943. Laya.init(GameConfig.width, GameConfig.height, Laya["WebGL"]);
  944. Laya["Physics"] && Laya["Physics"].enable();
  945. Laya["DebugPanel"] && Laya["DebugPanel"].enable();
  946. Laya.stage.scaleMode = GameConfig.scaleMode;
  947. Laya.stage.screenMode = GameConfig.screenMode;
  948. Laya.stage.alignV = GameConfig.alignV;
  949. Laya.stage.alignH = GameConfig.alignH;
  950. Laya.URL.exportSceneToJson = GameConfig.exportSceneToJson;
  951. if (GameConfig.debug || Laya.Utils.getQueryString("debug") == "true")
  952. Laya.enableDebugPanel();
  953. if (GameConfig.physicsDebug && Laya["PhysicsDebugDraw"])
  954. Laya["PhysicsDebugDraw"].enable();
  955. if (GameConfig.stat)
  956. Laya.Stat.show();
  957. Laya.alertGlobalError = true;
  958. Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.onVersionLoaded), Laya.ResourceVersion.FILENAME_VERSION);
  959. }
  960. onVersionLoaded() {
  961. Laya.AtlasInfoManager.enable("fileconfig.json", Laya.Handler.create(this, this.onConfigLoaded));
  962. }
  963. onConfigLoaded() {
  964. new LoadView();
  965. }
  966. }
  967. new Main();
  968. }());
  969. //# sourceMappingURL=bundle.js.map