bundle.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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. this.Stone = new ResDic();
  293. this.Tree = new ResDic();
  294. this.RedRay = new ResDic();
  295. this.BlueRay = new ResDic();
  296. this.GreenRay = new ResDic();
  297. AssetManager.ins = this;
  298. EventManager.EventOn(EventState.LoadComplete, this, this.Init);
  299. }
  300. static get Instance() {
  301. if (AssetManager.ins) {
  302. return AssetManager.ins;
  303. }
  304. else {
  305. return new AssetManager();
  306. }
  307. }
  308. Init() {
  309. this.maincamera = this.mainscene.getChildByName("Main Camera");
  310. this.Plane = this.mainscene.getChildByName("Plane");
  311. GameTools.Instance.SetCollider(this.Plane, 100);
  312. EventManager.EventTrigger(EventState.SceneInit);
  313. }
  314. }
  315. class ResourcesPath {
  316. }
  317. ResourcesPath.MainScene = "Game/res/MainScene/LayaScene_Mainscene/Conventional/Mainscene.ls";
  318. ResourcesPath.Horse = [
  319. "Game/res/Role/LayaScene_Role/Conventional/Horse.lh"
  320. ];
  321. ResourcesPath.Player = [
  322. "Game/res/Role/LayaScene_Role/Conventional/player.lh"
  323. ];
  324. ResourcesPath.Enemy = [
  325. "Game/res/Role/LayaScene_Role/Conventional/enemy.lh"
  326. ];
  327. ResourcesPath.Prop = "Game/res/Prop/LayaScene_Prop/Conventional/Prop.lh";
  328. var Sprite3D = Laya.Sprite3D;
  329. var Vector3 = Laya.Vector3;
  330. class modelConfig {
  331. constructor(model) {
  332. this.modelcur = model;
  333. this.modelPos = model.transform.position.clone();
  334. this.modelRot = model.transform.rotation.clone();
  335. this.modelSca = model.transform.scale.clone();
  336. }
  337. }
  338. class GamePool {
  339. constructor() {
  340. this.modelpool = {};
  341. this.maxAcount = 30;
  342. GamePool.Ins = this;
  343. }
  344. static get Instance() {
  345. if (GamePool.Ins) {
  346. return GamePool.Ins;
  347. }
  348. else {
  349. return new GamePool();
  350. }
  351. }
  352. GetModel(_model, title) {
  353. var poolname = title + _model.name;
  354. if (this.modelpool[poolname] != null && this.modelpool[poolname] != undefined) {
  355. if (this.modelpool[poolname].length > 0) {
  356. var model1 = this.modelpool[poolname][0];
  357. this.modelpool[poolname].splice(0, 1);
  358. if (model1.modelcur.destroyed) {
  359. model1.modelcur = Sprite3D.instantiate(_model);
  360. if (!model1.modelcur.active) {
  361. model1.modelcur.active = true;
  362. }
  363. }
  364. model1.modelcur.active = true;
  365. model1.modelcur.transform.position = _model.transform.position.clone();
  366. model1.modelcur.transform.rotation = _model.transform.rotation.clone();
  367. model1.modelcur.transform.scale = _model.transform.scale.clone();
  368. return model1.modelcur;
  369. }
  370. else {
  371. var model = Sprite3D.instantiate(_model);
  372. model.active = true;
  373. return model;
  374. }
  375. }
  376. else {
  377. var model = Sprite3D.instantiate(_model);
  378. model.active = true;
  379. return model;
  380. }
  381. }
  382. RecoveryModel(model, title = "", modelstate = false) {
  383. if (model.destroyed) {
  384. return;
  385. }
  386. if (!modelstate && model.active == false) {
  387. return;
  388. }
  389. var poolname = title + model.name;
  390. if (this.modelpool[poolname] != null && this.modelpool[poolname] != undefined) {
  391. var modelnum = this.modelpool[poolname];
  392. if (modelnum.length > this.maxAcount) {
  393. model.destroy();
  394. return;
  395. }
  396. else {
  397. modelnum.push(new modelConfig(model));
  398. }
  399. }
  400. else {
  401. modelnum = [];
  402. modelnum.push(new modelConfig(model));
  403. this.modelpool[poolname] = modelnum;
  404. }
  405. model.transform.position = new Vector3(0, 0, -10000);
  406. model.removeSelf();
  407. model.active = false;
  408. }
  409. ResetsModelPool() {
  410. for (var Key in this.modelpool) {
  411. var model = this.modelpool[Key];
  412. for (var i = 0; i < model.length; i++) {
  413. model[i].modelcur.destroy();
  414. }
  415. }
  416. this.modelpool = {};
  417. }
  418. }
  419. var Vector3$1 = Laya.Vector3;
  420. var CharacterState;
  421. (function (CharacterState) {
  422. CharacterState[CharacterState["Run"] = 0] = "Run";
  423. CharacterState[CharacterState["Idle"] = 1] = "Idle";
  424. CharacterState[CharacterState["Die"] = 2] = "Die";
  425. CharacterState[CharacterState["Win"] = 3] = "Win";
  426. CharacterState[CharacterState["Shoot"] = 4] = "Shoot";
  427. })(CharacterState || (CharacterState = {}));
  428. class Runner extends Laya.Script3D {
  429. constructor() {
  430. super();
  431. this.canmove = false;
  432. this._speed = 1;
  433. this._press = false;
  434. this.DownHit = new Laya.HitResult();
  435. this.FowardHit = new Laya.HitResult();
  436. this.curspeed = 0;
  437. this.currotV = new Vector3$1();
  438. this.currot = new Laya.Quaternion;
  439. this.NormalizeSpeed = new Vector3$1();
  440. this.curpos = new Vector3$1();
  441. this.offest = new Vector3$1();
  442. }
  443. static get Instance() {
  444. if (Runner.ins) {
  445. return Runner.ins;
  446. }
  447. else {
  448. return new Runner();
  449. }
  450. }
  451. onAwake() {
  452. this.m_player = this.owner;
  453. this.m_animator = this.owner.getComponent(Laya.Animator);
  454. this.m_horseanimator = this.owner.getChildAt(2).getComponent(Laya.Animator);
  455. this.ChangeState(CharacterState.Idle);
  456. EventManager.StageOn(StageState.Start, this, this.Begin);
  457. }
  458. Begin() {
  459. this.canmove = true;
  460. this.ChangeState(CharacterState.Run);
  461. }
  462. onUpdate() {
  463. let ray = this.m_player.getChildByName("raypos");
  464. console.log("玩家的位置---", this.m_player.transform.position);
  465. console.log("ray的位置---", ray.transform.position);
  466. if (this.canmove) {
  467. if (this._press) {
  468. this._speed = 2;
  469. }
  470. this.Move(new Vector3$1(0, 0, 1), this._speed);
  471. }
  472. this.RayCheck();
  473. }
  474. MoveX(_speed) {
  475. _speed *= 0.07;
  476. this.m_player.transform.translate(new Vector3$1(_speed, 0, 0));
  477. }
  478. TurnDir(_dir) {
  479. if (_dir.x != 0) {
  480. Vector3$1.lerp(this.currotV, _dir, 0.35, _dir);
  481. this.currotV = _dir;
  482. Laya.Quaternion.rotationLookAt(_dir, new Vector3$1(0, 1, 0), this.currot);
  483. Laya.Quaternion.slerp(this.m_player.transform.rotation, this.currot, 0.025, this.currot);
  484. this.currot = new Laya.Quaternion(0, this.currot.y, 0);
  485. this.m_player.transform.rotation = this.currot;
  486. }
  487. else {
  488. Laya.Quaternion.slerp(this.m_player.transform.rotation, new Laya.Quaternion(0, 0, 0, 0), 0.1, this.currot);
  489. this.currot = new Laya.Quaternion(0, this.currot.y, 0);
  490. this.m_player.transform.rotation = this.currot;
  491. }
  492. }
  493. Move(_dir, _speed) {
  494. var sp = GameTools.Instance.lerp(this.curspeed, _speed, 0.1);
  495. this.curspeed = sp;
  496. Vector3$1.scale(_dir, this.curspeed, this.offest);
  497. Vector3$1.add(this.m_player.transform.position, this.offest, this.curpos);
  498. Vector3$1.lerp(this.m_player.transform.position, this.curpos, 0.15, this.curpos);
  499. this.curpos = new Vector3$1(this.curpos.x, this.curpos.y, this.curpos.z);
  500. this.m_player.transform.position = this.curpos;
  501. }
  502. ChangeState(_state) {
  503. if (this.m_characterstate == _state)
  504. return;
  505. this.m_characterstate = _state;
  506. switch (this.m_characterstate) {
  507. case CharacterState.Idle:
  508. this.Idle();
  509. break;
  510. case CharacterState.Run:
  511. this.Run();
  512. break;
  513. case CharacterState.Die:
  514. this.Die();
  515. break;
  516. case CharacterState.Win:
  517. this.Win();
  518. break;
  519. case CharacterState.Shoot:
  520. this.Shoot();
  521. break;
  522. }
  523. }
  524. Idle() {
  525. this.m_animator.play("Idle");
  526. this.m_horseanimator.play("Horse_Idle");
  527. }
  528. Run() {
  529. this.m_animator.play("Idle");
  530. this.m_horseanimator.play("Horse_Run");
  531. }
  532. Die() {
  533. }
  534. Win() {
  535. }
  536. Shoot() {
  537. this.m_animator.play("aimshoot");
  538. this.m_animator.play("Horse_Run");
  539. }
  540. RayCheck() {
  541. if (this.DownRayCheck) ;
  542. if (this.FowardRayCheck) {
  543. this.CrashBarrier();
  544. }
  545. }
  546. CrashBarrier() {
  547. var target = this.FowardHit.collider.owner;
  548. if (target.name == "") ;
  549. else if (target.name == "") ;
  550. else if (target.name == "") ;
  551. else if (target.name == "") ;
  552. }
  553. get DownRayCheck() {
  554. var isDownHit = false;
  555. 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);
  556. var direction = new Vector3$1(0, -1, 0);
  557. var DownRay = new Laya.Ray(startPos, direction);
  558. if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.DownHit, 100)) {
  559. if (this.DownHit.collider.collisionGroup == 100) {
  560. isDownHit = true;
  561. }
  562. }
  563. return isDownHit;
  564. }
  565. get FowardRayCheck() {
  566. var isFowardHit = false;
  567. 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);
  568. var direction = new Vector3$1(0, 0, 1);
  569. var DownRay = new Laya.Ray(startPos, direction);
  570. if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.FowardHit, 1)) {
  571. if (this.FowardHit.collider.collisionGroup == 100) {
  572. isFowardHit = true;
  573. }
  574. }
  575. return isFowardHit;
  576. }
  577. }
  578. var Vector2 = Laya.Vector2;
  579. var Vector3$2 = Laya.Vector3;
  580. class PlayerControl {
  581. constructor() {
  582. this.DownHit = new Laya.HitResult();
  583. this.canmove = true;
  584. this.speed = 1;
  585. this.press = false;
  586. this.offset = new Vector3$2(0, 0, 0);
  587. this.offestx = 0;
  588. this.poschazhi = new Vector3$2();
  589. this.gengsuipos = new Vector3$2();
  590. this.lllpos = new Vector3$2();
  591. this.hights = 0;
  592. this.wights = 0;
  593. PlayerControl.ins = this;
  594. }
  595. static get Instance() {
  596. if (PlayerControl.ins) {
  597. return PlayerControl.ins;
  598. }
  599. else {
  600. return new PlayerControl();
  601. }
  602. }
  603. Init(_player) {
  604. this.Player = _player;
  605. this._runner = this.Player.addComponent(Runner);
  606. this.Player.transform.position = new Vector3$2();
  607. this.Camera = AssetManager.Instance.maincamera;
  608. this.Camera.transform.position = new Vector3$2(0, 10, -15);
  609. this.Camera.transform.localRotationEuler = new Vector3$2(-5, 0, 0);
  610. Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.onMouseDown);
  611. this.CameraFollow();
  612. }
  613. onMouseDown(e) {
  614. if (!this._runner.canmove)
  615. return;
  616. this._runner._press = true;
  617. this.mouseDownTime = Laya.Browser.now();
  618. this.startMousePos = new Vector3$2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  619. var startpoint = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  620. this.curMousePos = this.startMousePos.clone();
  621. this.curMousePos1 = startpoint.clone();
  622. Laya.timer.frameLoop(1, this, this.onMouseMove);
  623. Laya.stage.on(Laya.Event.MOUSE_UP, this, this.onMouseUp);
  624. Laya.stage.on(Laya.Event.MOUSE_OUT, this, this.onMouseUp);
  625. }
  626. onMouseMove() {
  627. var MousePos = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  628. var offestX = MousePos.x - this.curMousePos1.x;
  629. this.offestx = GameTools.Instance.lerp(this.offestx, offestX, 0.015);
  630. this._runner.MoveX(-this.offestx);
  631. var dir = new Vector3$2(-offestX * 0.005, 0, 0);
  632. this._runner.TurnDir(dir);
  633. this.curMousePos1 = new Vector2(MousePos.x, MousePos.y);
  634. }
  635. onMouseUp() {
  636. this.offestx = 0;
  637. Laya.timer.clear(this, this.onMouseMove);
  638. this._runner._press = false;
  639. if (!this.startMousePos)
  640. return;
  641. Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.onMouseMove);
  642. Laya.stage.off(Laya.Event.MOUSE_UP, this, this.onMouseUp);
  643. Laya.stage.off(Laya.Event.MOUSE_OUT, this, this.onMouseUp);
  644. let now = Laya.Browser.now();
  645. let interval = now - this.mouseDownTime;
  646. this.endMousePos = new Vector3$2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
  647. let dist = Laya.Vector3.distance(this.endMousePos, this.startMousePos);
  648. if (dist < 50 && interval < 200) {
  649. console.log("shoot--");
  650. }
  651. this.mouseDownTime = now;
  652. }
  653. CameraFollow() {
  654. this.hights = 0;
  655. this.wights = 0;
  656. Vector3$2.subtract(this.Player.transform.position, this.Camera.transform.position, this.poschazhi);
  657. Laya.timer.frameLoop(1, this, this.GenSui);
  658. }
  659. GenSui() {
  660. Vector3$2.subtract(this.Player.transform.position, this.poschazhi, this.gengsuipos);
  661. this.hights = GameTools.Instance.lerp(this.hights, 1.0, 0.03);
  662. this.wights = GameTools.Instance.lerp(this.wights, 0.8, 0.02);
  663. this.gengsuipos = new Vector3$2(this.gengsuipos.x, this.gengsuipos.y, this.gengsuipos.z - this.wights);
  664. Vector3$2.lerp(this.Camera.transform.position, this.gengsuipos, 0.25, this.lllpos);
  665. this.lllpos = new Vector3$2(this.gengsuipos.x, this.gengsuipos.y, this.lllpos.z);
  666. this.lllpos = new Vector3$2(this.gengsuipos.x, this.lllpos.y, this.lllpos.z);
  667. this.Camera.transform.position = this.lllpos;
  668. var qqqwe = new Laya.Quaternion();
  669. var eyePos = new Vector3$2(this.gengsuipos.x, this.gengsuipos.y - 0.8, this.gengsuipos.z);
  670. Laya.Quaternion.lookAt(eyePos, this.Player.transform.position, new Vector3$2(0, 1, 0), qqqwe);
  671. qqqwe.invert(qqqwe);
  672. Laya.Quaternion.slerp(this.Camera.transform.rotation, qqqwe, 0.1, qqqwe);
  673. this.Camera.transform.rotation = qqqwe;
  674. }
  675. get DownRayCheck() {
  676. var isDownHit = false;
  677. var startPos = new Vector3$2(this.Player.transform.position.x, this.Player.transform.position.y + 1.5, this.Player.transform.position.z + 0.5);
  678. var direction = new Vector3$2(0, -1, 0);
  679. var DownRay = new Laya.Ray(startPos, direction);
  680. if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.DownHit, 100)) {
  681. if (this.DownHit.collider.collisionGroup == 100) {
  682. isDownHit = true;
  683. }
  684. }
  685. return isDownHit;
  686. }
  687. }
  688. var REG = Laya.ClassUtils.regClass;
  689. var ui;
  690. (function (ui) {
  691. class InGameViewUI extends Laya.Scene {
  692. constructor() { super(); }
  693. createChildren() {
  694. super.createChildren();
  695. this.createView(InGameViewUI.uiView);
  696. }
  697. }
  698. InGameViewUI.uiView = { "type": "Scene", "props": { "width": 720, "height": 1280 }, "compId": 2, "loadList": [], "loadList3D": [] };
  699. ui.InGameViewUI = InGameViewUI;
  700. REG("ui.InGameViewUI", InGameViewUI);
  701. class MainGameViewUI extends Laya.Scene {
  702. constructor() { super(); }
  703. createChildren() {
  704. super.createChildren();
  705. this.createView(MainGameViewUI.uiView);
  706. }
  707. }
  708. 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": [] };
  709. ui.MainGameViewUI = MainGameViewUI;
  710. REG("ui.MainGameViewUI", MainGameViewUI);
  711. })(ui || (ui = {}));
  712. class MainGameView extends ui.MainGameViewUI {
  713. constructor() {
  714. super();
  715. MainGameView.ins = this;
  716. }
  717. static get Instance() {
  718. if (MainGameView.ins) {
  719. return MainGameView.ins;
  720. }
  721. else {
  722. return new MainGameView();
  723. }
  724. }
  725. Show() {
  726. this.StartBtn.clickHandler = Laya.Handler.create(this, this.ClickStart);
  727. }
  728. Close() {
  729. }
  730. ClickStart() {
  731. EventManager.StageTrigger(StageState.Start);
  732. ViewManager.Instance.ShowView(ViewType.IngameView);
  733. }
  734. }
  735. class InGameView extends ui.InGameViewUI {
  736. constructor() {
  737. super();
  738. InGameView.ins = this;
  739. }
  740. static get Instance() {
  741. if (InGameView.ins) {
  742. return InGameView.ins;
  743. }
  744. else {
  745. return new InGameView();
  746. }
  747. }
  748. Show() {
  749. }
  750. Close() {
  751. }
  752. }
  753. var ViewType;
  754. (function (ViewType) {
  755. ViewType[ViewType["MainView"] = 0] = "MainView";
  756. ViewType[ViewType["IngameView"] = 1] = "IngameView";
  757. })(ViewType || (ViewType = {}));
  758. class ViewManager {
  759. constructor() {
  760. this.showexportview = 0;
  761. this.popViewDic = [];
  762. this.ViewSprite = new Laya.Sprite();
  763. this.OtherViewSprite = new Laya.Sprite();
  764. ViewManager.ins = this;
  765. Laya.stage.addChild(this.ViewSprite);
  766. Laya.stage.addChild(this.OtherViewSprite);
  767. }
  768. static get Instance() {
  769. if (ViewManager.ins) {
  770. return ViewManager.ins;
  771. }
  772. else {
  773. return new ViewManager();
  774. }
  775. }
  776. ShowView(_viewtype, data = null) {
  777. if (this.curView != null) {
  778. this.curView.Close();
  779. this.curView.destroy();
  780. this.curView.removeSelf();
  781. }
  782. this.curView = this.CreateView(_viewtype);
  783. this.curView.name = ViewType[_viewtype];
  784. this.ViewSprite.addChild(this.curView);
  785. this.curView.Show(data);
  786. }
  787. CloseView() {
  788. if (this.curView != null) {
  789. this.curView.Close();
  790. this.curView.destroy();
  791. this.curView.removeSelf();
  792. }
  793. }
  794. OpenPopView(viewType, data = null) {
  795. var popView;
  796. if (this.popViewDic[viewType]) {
  797. popView = this.popViewDic[viewType];
  798. this.OtherViewSprite.setChildIndex(popView, this.OtherViewSprite.numChildren - 1);
  799. popView.visible = true;
  800. }
  801. else {
  802. popView = this.CreateView(viewType);
  803. this.OtherViewSprite.addChild(popView);
  804. this.popViewDic[viewType] = popView;
  805. }
  806. this.showexportview = 1;
  807. popView.OnOpen(data);
  808. }
  809. ClosePopView(viewType) {
  810. var popView = this.popViewDic[viewType];
  811. if (popView == null) {
  812. return;
  813. }
  814. popView.OnHide();
  815. popView.visible = false;
  816. this.showexportview = 0;
  817. }
  818. ClearPopViews() {
  819. }
  820. CreateView(_viewtype) {
  821. switch (_viewtype) {
  822. case ViewType.MainView:
  823. return new MainGameView();
  824. case ViewType.IngameView:
  825. return new InGameView();
  826. }
  827. return null;
  828. }
  829. }
  830. class GameManager {
  831. constructor() {
  832. this.EnemyArray = [];
  833. GameManager.ins = this;
  834. EventManager.EventOn(EventState.SceneInit, this, this.Init);
  835. }
  836. static get Instance() {
  837. if (GameManager.ins) {
  838. return GameManager.ins;
  839. }
  840. else {
  841. return new GameManager();
  842. }
  843. }
  844. Init() {
  845. this.CreatCharacter();
  846. this.mainscene = AssetManager.Instance.mainscene;
  847. Laya.stage.addChildAt(this.mainscene, 0);
  848. ViewManager.Instance.ShowView(ViewType.MainView);
  849. }
  850. CreatCharacter() {
  851. this.CreatPlayer();
  852. this.CreatEnemy();
  853. }
  854. CreatPlayer() {
  855. var playermodel = GamePool.Instance.GetModel(AssetManager.Instance.Player.get(1), "");
  856. var horsemodel = GamePool.Instance.GetModel(AssetManager.Instance.Horse.get(1), "");
  857. playermodel.addChild(horsemodel);
  858. var raypos = playermodel.getChildByName("raypos");
  859. this.CreatRay(raypos.transform.position.clone(), raypos.transform.rotationEuler.clone(), raypos);
  860. playermodel.transform.position = new Laya.Vector3(0, 0, 0);
  861. horsemodel.transform.localScale = new Laya.Vector3(1, 1, 1);
  862. horsemodel.transform.localPosition = new Laya.Vector3(0, 0, 0);
  863. PlayerControl.Instance.Init(playermodel);
  864. AssetManager.Instance.mainscene.addChild(playermodel);
  865. }
  866. CreatEnemy() {
  867. }
  868. CreatRay(pos, euler, raypos) {
  869. var ray = this.CreatRayPrefab();
  870. raypos.addChild(ray);
  871. ray.transform.position = pos;
  872. ray.transform.rotationEuler = euler;
  873. let scale = ray.transform.scale.clone();
  874. scale.z = 5;
  875. scale.x = 1;
  876. ray.transform.scale = scale;
  877. }
  878. CreatRayPrefab() {
  879. var ray = GamePool.Instance.GetModel(AssetManager.Instance.GreenRay.get(1), "");
  880. return ray;
  881. }
  882. }
  883. class LoadView {
  884. constructor() {
  885. LoadView.ins = this;
  886. this.Init();
  887. }
  888. static get Instance() {
  889. if (LoadView.ins) {
  890. return LoadView.ins;
  891. }
  892. else {
  893. return new LoadView();
  894. }
  895. }
  896. Init() {
  897. new GameManager();
  898. this.LoadScene();
  899. }
  900. LoadComplete() {
  901. console.log("加载完毕--");
  902. EventManager.EventTrigger(EventState.LoadComplete);
  903. }
  904. LoadScene() {
  905. Laya.Scene3D.load(ResourcesPath.MainScene, Laya.Handler.create(this, (scene) => {
  906. this.scene = scene;
  907. AssetManager.Instance.mainscene = this.scene;
  908. console.log("场景加载完毕");
  909. this.LoadEnemy();
  910. }));
  911. }
  912. LoadEnemy() {
  913. var path = [];
  914. for (let i = 0; i < ResourcesPath.Enemy.length; i++) {
  915. path.push(ResourcesPath.Enemy[i]);
  916. }
  917. Laya.loader.create(path, Laya.Handler.create(this, () => {
  918. for (let i = 0; i < ResourcesPath.Enemy.length; i++) {
  919. var model = Laya.loader.getRes(ResourcesPath.Enemy[i]);
  920. AssetManager.Instance.Enemy.set(i + 1, model);
  921. Laya.loader.clearRes(ResourcesPath.Enemy[i]);
  922. }
  923. console.log("敌人模型资源加载完毕---");
  924. this.LoadPlayer();
  925. }));
  926. }
  927. LoadPlayer() {
  928. var path = [];
  929. for (let i = 0; i < ResourcesPath.Player.length; i++) {
  930. path.push(ResourcesPath.Player[i]);
  931. }
  932. Laya.loader.create(path, Laya.Handler.create(this, () => {
  933. for (let i = 0; i < ResourcesPath.Player.length; i++) {
  934. var model = Laya.loader.getRes(ResourcesPath.Player[i]);
  935. AssetManager.Instance.Player.set(i + 1, model);
  936. Laya.loader.clearRes(ResourcesPath.Player[i]);
  937. }
  938. console.log("玩家模型资源加载完毕---");
  939. this.LoadHorse();
  940. }));
  941. }
  942. LoadHorse() {
  943. var path = [];
  944. for (let i = 0; i < ResourcesPath.Horse.length; i++) {
  945. path.push(ResourcesPath.Horse[i]);
  946. }
  947. Laya.loader.create(path, Laya.Handler.create(this, () => {
  948. for (let i = 0; i < ResourcesPath.Horse.length; i++) {
  949. var model = Laya.loader.getRes(ResourcesPath.Horse[i]);
  950. AssetManager.Instance.Horse.set(i + 1, model);
  951. Laya.loader.clearRes(ResourcesPath.Horse[i]);
  952. }
  953. console.log("马模型资源加载完毕---");
  954. this.LoadProp();
  955. }));
  956. }
  957. LoadProp() {
  958. Laya.loader.create(ResourcesPath.Prop, Laya.Handler.create(this, this.LoadResources));
  959. }
  960. LoadResources(_prop) {
  961. var Prop = _prop.getChildByName("Prop");
  962. for (let i = 0; i < Prop.numChildren; i++) {
  963. var model = Prop.getChildAt(i);
  964. model.active = false;
  965. AssetManager.Instance.Prop.set(i + 1, model);
  966. }
  967. var Stone = _prop.getChildByName("Stone");
  968. for (let i = 0; i < Stone.numChildren; i++) {
  969. var stone = Stone.getChildAt(i);
  970. stone.active = false;
  971. AssetManager.Instance.Stone.set(i + 1, stone);
  972. }
  973. var Tree = _prop.getChildByName("Tree");
  974. for (let i = 0; i < Tree.numChildren; i++) {
  975. var tree = Tree.getChildAt(i);
  976. tree.active = false;
  977. AssetManager.Instance.Tree.set(i + 1, tree);
  978. }
  979. var Blue = _prop.getChildByName("bulletB");
  980. AssetManager.Instance.BlueRay.set(1, Blue);
  981. var Red = _prop.getChildByName("bulletR");
  982. AssetManager.Instance.RedRay.set(1, Red);
  983. var Green = _prop.getChildByName("bulletG");
  984. AssetManager.Instance.GreenRay.set(1, Green);
  985. Laya.loader.clearRes(ResourcesPath.Prop);
  986. console.log("道具资源加载完毕---");
  987. this.LoadComplete();
  988. }
  989. }
  990. class Main {
  991. constructor() {
  992. if (window["Laya3D"])
  993. Laya3D.init(GameConfig.width, GameConfig.height);
  994. else
  995. Laya.init(GameConfig.width, GameConfig.height, Laya["WebGL"]);
  996. Laya["Physics"] && Laya["Physics"].enable();
  997. Laya["DebugPanel"] && Laya["DebugPanel"].enable();
  998. Laya.stage.scaleMode = GameConfig.scaleMode;
  999. Laya.stage.screenMode = GameConfig.screenMode;
  1000. Laya.stage.alignV = GameConfig.alignV;
  1001. Laya.stage.alignH = GameConfig.alignH;
  1002. Laya.URL.exportSceneToJson = GameConfig.exportSceneToJson;
  1003. if (GameConfig.debug || Laya.Utils.getQueryString("debug") == "true")
  1004. Laya.enableDebugPanel();
  1005. if (GameConfig.physicsDebug && Laya["PhysicsDebugDraw"])
  1006. Laya["PhysicsDebugDraw"].enable();
  1007. if (GameConfig.stat)
  1008. Laya.Stat.show();
  1009. Laya.alertGlobalError = true;
  1010. Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.onVersionLoaded), Laya.ResourceVersion.FILENAME_VERSION);
  1011. }
  1012. onVersionLoaded() {
  1013. Laya.AtlasInfoManager.enable("fileconfig.json", Laya.Handler.create(this, this.onConfigLoaded));
  1014. }
  1015. onConfigLoaded() {
  1016. new LoadView();
  1017. }
  1018. }
  1019. new Main();
  1020. }());
  1021. //# sourceMappingURL=bundle.js.map