fe2cef98b8b5e3a6dac55e8751eee3969faf0aef 5.7 KB

123456789
  1. {
  2. "code": "var Vector2 = Laya.Vector2;\r\nvar Vector3 = Laya.Vector3;\r\nimport { GameTools } from \"../Tools/GameTools\";\r\nimport { AssetManager } from \"../Tools/AssetManager\";\r\nimport { Runner } from \"./Runner\";\r\nexport class PlayerControl {\r\n constructor() {\r\n this.DownHit = new Laya.HitResult();\r\n this.canmove = true;\r\n this.speed = 1;\r\n this.press = false;\r\n this.offset = new Vector3(0, 0, 0);\r\n this.offestx = 0;\r\n this.poschazhi = new Vector3();\r\n this.gengsuipos = new Vector3();\r\n this.lllpos = new Vector3();\r\n this.hights = 0;\r\n this.wights = 0;\r\n PlayerControl.ins = this;\r\n }\r\n static get Instance() {\r\n if (PlayerControl.ins) {\r\n return PlayerControl.ins;\r\n }\r\n else {\r\n return new PlayerControl();\r\n }\r\n }\r\n Init(_player) {\r\n this.Player = _player;\r\n this.arrowpos = _player.getChildByName(\"arrowpos\");\r\n this._runner = this.Player.addComponent(Runner);\r\n this.Player.transform.position = new Vector3();\r\n this.Camera = AssetManager.Instance.maincamera;\r\n this.Camera.transform.position = new Vector3(0, 10, -15);\r\n this.Camera.transform.localRotationEuler = new Vector3(-5, 0, 0);\r\n Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.onMouseDown);\r\n this.CameraFollow();\r\n }\r\n onMouseDown(e) {\r\n if (!this._runner.canmove)\r\n return;\r\n this._runner._press = true;\r\n this.mouseDownTime = Laya.Browser.now();\r\n this.startMousePos = new Vector3(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);\r\n var startpoint = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);\r\n this.curMousePos = this.startMousePos.clone();\r\n this.curMousePos1 = startpoint.clone();\r\n Laya.timer.frameLoop(1, this, this.onMouseMove);\r\n Laya.stage.on(Laya.Event.MOUSE_UP, this, this.onMouseUp);\r\n Laya.stage.on(Laya.Event.MOUSE_OUT, this, this.onMouseUp);\r\n }\r\n onMouseMove() {\r\n if (!this._runner.canmove)\r\n return;\r\n var MousePos = new Laya.Vector2(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);\r\n var offestX = MousePos.x - this.curMousePos1.x;\r\n this.offestx = GameTools.Instance.lerp(this.offestx, offestX, 0.015);\r\n this._runner.MoveX(-this.offestx);\r\n var dir = new Vector3(-offestX * 0.005, 0, 0);\r\n this._runner.TurnDir(dir);\r\n this.curMousePos1 = new Vector2(MousePos.x, MousePos.y);\r\n }\r\n onMouseUp() {\r\n this.offestx = 0;\r\n Laya.timer.clear(this, this.onMouseMove);\r\n this._runner._press = false;\r\n if (!this.startMousePos)\r\n return;\r\n Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.onMouseMove);\r\n Laya.stage.off(Laya.Event.MOUSE_UP, this, this.onMouseUp);\r\n Laya.stage.off(Laya.Event.MOUSE_OUT, this, this.onMouseUp);\r\n let now = Laya.Browser.now();\r\n let interval = now - this.mouseDownTime;\r\n this.endMousePos = new Vector3(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);\r\n let dist = Laya.Vector3.distance(this.endMousePos, this.startMousePos);\r\n if (dist < 50 && interval < 200 && !this._runner.shoot) {\r\n this._runner.shoot = true;\r\n this._runner.Archery();\r\n }\r\n this.mouseDownTime = now;\r\n }\r\n CameraFollow() {\r\n this.hights = 0;\r\n this.wights = 0;\r\n Vector3.subtract(this.Player.transform.position, this.Camera.transform.position, this.poschazhi);\r\n Laya.timer.frameLoop(1, this, this.GenSui);\r\n }\r\n GenSui() {\r\n Vector3.subtract(this.Player.transform.position, this.poschazhi, this.gengsuipos);\r\n this.hights = GameTools.Instance.lerp(this.hights, 1.0, 0.03);\r\n this.wights = GameTools.Instance.lerp(this.wights, 0.8, 0.02);\r\n this.gengsuipos = new Vector3(this.gengsuipos.x, this.gengsuipos.y, this.gengsuipos.z - this.wights);\r\n Vector3.lerp(this.Camera.transform.position, this.gengsuipos, 0.25, this.lllpos);\r\n this.lllpos = new Vector3(this.gengsuipos.x, this.gengsuipos.y, this.lllpos.z);\r\n this.lllpos = new Vector3(this.gengsuipos.x, this.lllpos.y, this.lllpos.z);\r\n this.Camera.transform.position = this.lllpos;\r\n var qqqwe = new Laya.Quaternion();\r\n var eyePos = new Vector3(this.gengsuipos.x, this.gengsuipos.y - 0.8, this.gengsuipos.z);\r\n Laya.Quaternion.lookAt(eyePos, this.Player.transform.position, new Vector3(0, 1, 0), qqqwe);\r\n qqqwe.invert(qqqwe);\r\n Laya.Quaternion.slerp(this.Camera.transform.rotation, qqqwe, 0.1, qqqwe);\r\n this.Camera.transform.rotation = qqqwe;\r\n }\r\n get DownRayCheck() {\r\n var isDownHit = false;\r\n var startPos = new Vector3(this.Player.transform.position.x, this.Player.transform.position.y + 1.5, this.Player.transform.position.z + 0.5);\r\n var direction = new Vector3(0, -1, 0);\r\n var DownRay = new Laya.Ray(startPos, direction);\r\n if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.DownHit, 100)) {\r\n if (this.DownHit.collider.collisionGroup == 100) {\r\n isDownHit = true;\r\n }\r\n }\r\n return isDownHit;\r\n }\r\n}\r\n",
  3. "references": [
  4. "E:/LayaProject/ArcherWorrior/src/Tools/GameTools.ts",
  5. "E:/LayaProject/ArcherWorrior/src/Tools/AssetManager.ts",
  6. "E:/LayaProject/ArcherWorrior/src/Game/Runner.ts"
  7. ]
  8. }