bundle.js 42 KB

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