f985b21fde6f3f4cc33530b0fb43b55d8f43811b 9.5 KB

12345678910111213141516
  1. {
  2. "code": "var Vector3 = Laya.Vector3;\r\nimport PoolManager from \"../Util/PoolManager\";\r\nimport { AssetManager } from \"./AssetManager\";\r\nimport { SceneManager } from \"./SceneManager\";\r\nimport { Player } from \"./Player\";\r\nimport { EventManager, EventType } from \"./EventManager\";\r\nimport { ColliderLay, GameState } from \"./DataMaker\";\r\nimport { RigObj } from \"../Util/RigObj\";\r\nimport { AudioControl, VoiceType } from \"./AudioControl\";\r\nexport class Bullet {\r\n constructor(_form, _startpos, _type, _speed) {\r\n this.cut = false;\r\n this.life = 10;\r\n this.clear = false;\r\n this.follower = false;\r\n this.curpos = new Vector3();\r\n this.currot = new Laya.Quaternion();\r\n this.firedir = new Vector3();\r\n this.tridis = 0.5;\r\n this.forwardhit = new Laya.HitResult();\r\n this.formonster = _form;\r\n this.type = _type;\r\n this.bulletspeed = _speed;\r\n this.cursprite = PoolManager.GetSprite3D(AssetManager.bullet.getValue(this.type));\r\n SceneManager.mainscene.addChild(this.cursprite);\r\n this.cursprite.transform.position = _startpos;\r\n if (this.type == 1 || this.type == 2) {\r\n this.tw = PoolManager.GetSprite3D(AssetManager.effect.getValue(1));\r\n this.cursprite.addChild(this.tw);\r\n this.tw.transform.localPosition = new Vector3(0, 0, 0);\r\n }\r\n else if (this.type == 3) {\r\n this.tw = PoolManager.GetSprite3D(AssetManager.effect.getValue(8));\r\n this.cursprite.addChild(this.tw);\r\n this.tw.transform.localPosition = new Vector3(0, 0, 0);\r\n }\r\n this.upsprite = this.cursprite.getChildAt(1);\r\n this.downsprite = this.cursprite.getChildAt(0);\r\n this.curcollider = this.cursprite.getChildAt(2).getComponent(Laya.PhysicsCollider);\r\n this.curcollider.collisionGroup = ColliderLay.bullet;\r\n this.OnInit();\r\n }\r\n OnInit() {\r\n EventManager.On(EventType.Cut, this, this.OnCut);\r\n EventManager.GameOn(GameState.Over, this, this.OnGameEnd);\r\n }\r\n OnGameEnd() {\r\n this.Clear();\r\n }\r\n OnCut(_collider) {\r\n if (_collider != this.curcollider || this.cut)\r\n return;\r\n this.BeCut();\r\n }\r\n Clear() {\r\n if (this.clear)\r\n return;\r\n this.clear = true;\r\n Laya.timer.clearAll(this);\r\n Laya.timer.clear(this, this.FireLoop);\r\n if (this.tw)\r\n this.tw.destroy();\r\n if (this.uprig)\r\n this.uprig.Clear();\r\n if (this.downrig)\r\n this.downrig.Clear();\r\n if (this.cuteffect)\r\n PoolManager.RecoverSprite3D(this.cuteffect);\r\n if (this.copysprite) {\r\n var dieupsprite1 = this.copysprite.getChildAt(1);\r\n dieupsprite1.active = true;\r\n PoolManager.RecoverSprite3D(this.copysprite);\r\n }\r\n this.downsprite.active = true;\r\n PoolManager.RecoverSprite3D(this.cursprite);\r\n EventManager.Off(EventType.Cut, this, this.OnCut);\r\n EventManager.GameOff(GameState.Over, this, this.OnGameEnd);\r\n }\r\n Fire(_startdir, _target = null, _follower = false) {\r\n this.firetarget = _target;\r\n this.firedir = _startdir ? _startdir : this.firedir;\r\n this.follower = _follower;\r\n if (_follower && this.type != 2) {\r\n var taretpos = this.firetarget.transform.position.clone();\r\n var lookpos = new Vector3(taretpos.x, taretpos.y + 0.5, taretpos.z);\r\n Laya.Quaternion.lookAt(lookpos, this.cursprite.transform.position, new Vector3(0, 1, 0), this.currot);\r\n this.currot.invert(this.currot);\r\n this.cursprite.transform.rotation = this.currot;\r\n }\r\n if (_target != null) {\r\n var sfsf = _target.transform.position.clone();\r\n var targetpos = new Vector3(sfsf.x, sfsf.y + 0.5, sfsf.z);\r\n Vector3.subtract(targetpos, this.cursprite.transform.position, this.firedir);\r\n }\r\n this.follower = this.follower && _target != null;\r\n Vector3.normalize(this.firedir, this.firedir);\r\n Vector3.scale(this.firedir, this.bulletspeed, this.firedir);\r\n Laya.timer.frameLoop(1, this, this.FireLoop);\r\n Laya.timer.once(this.life * 1000, this, this.Clear);\r\n }\r\n FireLoop() {\r\n Vector3.add(this.cursprite.transform.position, this.firedir, this.curpos);\r\n Vector3.lerp(this.cursprite.transform.position, this.curpos, 0.12, this.curpos);\r\n this.cursprite.transform.position = this.curpos;\r\n if (this.follower) {\r\n var sfsf = this.firetarget.transform.position.clone();\r\n var targetpos = new Vector3(sfsf.x, sfsf.y + 0.5, sfsf.z);\r\n Vector3.subtract(targetpos, this.cursprite.transform.position, this.firedir);\r\n Vector3.normalize(this.firedir, this.firedir);\r\n Vector3.scale(this.firedir, this.bulletspeed, this.firedir);\r\n if (this.type != 2) {\r\n var taretpos = this.firetarget.transform.position.clone();\r\n var lookpos = new Vector3(taretpos.x, this.cursprite.transform.position.y, taretpos.z);\r\n Laya.Quaternion.lookAt(lookpos, this.cursprite.transform.position, new Vector3(0, 1, 0), this.currot);\r\n this.currot.invert(this.currot);\r\n Laya.Quaternion.slerp(this.cursprite.transform.rotation, this.currot, 0.2, this.currot);\r\n this.cursprite.transform.rotation = this.currot;\r\n }\r\n }\r\n if (this.type == 2) {\r\n this.cursprite.transform.rotate(new Vector3(0, 0.1, 0));\r\n var hifbarrier = this.ForwardCheck(this.firedir);\r\n if (hifbarrier) {\r\n var normal = this.forwardhit.normal;\r\n var newdir = new Vector3();\r\n var fs = -2 * Vector3.dot(normal, this.firedir);\r\n var gsg = new Vector3();\r\n Vector3.scale(normal, fs, gsg);\r\n Vector3.subtract(normal, gsg, newdir);\r\n this.firedir = newdir;\r\n Vector3.normalize(this.firedir, this.firedir);\r\n Vector3.scale(this.firedir, this.bulletspeed, this.firedir);\r\n }\r\n }\r\n if (this.displayer < this.tridis) {\r\n this.Clear();\r\n EventManager.Trigger(EventType.Hit, [this.formonster]);\r\n }\r\n }\r\n BeCut() {\r\n this.cut = true;\r\n if (this.tw) {\r\n this.tw.destroy();\r\n this.tw = null;\r\n }\r\n Laya.timer.clear(this, this.FireLoop);\r\n AudioControl.PlayVoice(VoiceType.cut);\r\n var cutasset = AssetManager.effect.getValue(4);\r\n this.cuteffect = PoolManager.GetSprite3D(cutasset);\r\n SceneManager.mainscene.addChild(this.cuteffect);\r\n this.cuteffect.transform.position = this.upsprite.transform.position.clone();\r\n this.copysprite = PoolManager.GetSprite3D(AssetManager.bullet.getValue(this.type));\r\n SceneManager.mainscene.addChild(this.copysprite);\r\n this.copysprite.transform.position = this.cursprite.transform.position.clone();\r\n this.copysprite.transform.rotationEuler = this.cursprite.transform.rotationEuler.clone();\r\n var dieupsprite = this.copysprite.getChildAt(1);\r\n dieupsprite.active = false;\r\n this.uprig = new RigObj(this.copysprite, null, 1);\r\n this.uprig.minhight = 1;\r\n this.uprig.AddForce(new Laya.Vector3(0, 1, 0.1), 0.5);\r\n this.downsprite.active = false;\r\n this.downrig = new RigObj(this.cursprite, () => {\r\n this.Clear();\r\n }, 1.2);\r\n this.downrig.minhight = 1;\r\n this.downrig.AddForce(new Laya.Vector3(0, 1, 0.1), 0.3);\r\n }\r\n get displayer() {\r\n var curpos = this.cursprite.transform.position.clone();\r\n var mainplayerpos = Player.mainpalyer.cursprite.transform.position.clone();\r\n mainplayerpos = new Vector3(mainplayerpos.x, mainplayerpos.y + 0.5, mainplayerpos.z);\r\n var dis = Vector3.distance(mainplayerpos, curpos);\r\n return dis;\r\n }\r\n ForwardCheck(_dir) {\r\n var hitenter = false;\r\n var curpos = this.cursprite.transform.position;\r\n var startpoint = new Vector3(curpos.x, curpos.y, curpos.z);\r\n var ray = new Laya.Ray(startpoint, _dir);\r\n if (SceneManager.mainscene.physicsSimulation.rayCast(ray, this.forwardhit, 0.5)) {\r\n if (this.forwardhit.collider.collisionGroup == ColliderLay.obstacle) {\r\n return true;\r\n }\r\n }\r\n return hitenter;\r\n }\r\n}\r\n",
  3. "references": [
  4. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/Role.ts",
  5. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/PoolManager.ts",
  6. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/AssetManager.ts",
  7. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/SceneManager.ts",
  8. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/Player.ts",
  9. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/GameUtils.ts",
  10. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/EventManager.ts",
  11. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/DataMaker.ts",
  12. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/RigObj.ts",
  13. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/AudioControl.ts"
  14. ]
  15. }