123456789101112 |
- {
- "code": "var Vector3 = Laya.Vector3;\r\nimport { GameTools, Transform3DHelper } from \"../Tools/GameTools\";\r\nimport { EventManager, StageState } from \"../Tools/EventManager\";\r\nimport { AssetManager } from \"../Tools/AssetManager\";\r\nimport GamePool from \"../Tools/GamePool\";\r\nimport { NpcRunner } from \"./NpcRunner\";\r\nexport var CharacterState;\r\n(function (CharacterState) {\r\n CharacterState[CharacterState[\"Run\"] = 0] = \"Run\";\r\n CharacterState[CharacterState[\"Idle\"] = 1] = \"Idle\";\r\n CharacterState[CharacterState[\"Die\"] = 2] = \"Die\";\r\n CharacterState[CharacterState[\"Win\"] = 3] = \"Win\";\r\n CharacterState[CharacterState[\"Shoot\"] = 4] = \"Shoot\";\r\n})(CharacterState || (CharacterState = {}));\r\nexport class Runner extends Laya.Script3D {\r\n constructor() {\r\n super();\r\n this.shoot = false;\r\n this.m_raydistance = 1000;\r\n this.isdead = false;\r\n this.canmove = false;\r\n this._speed = 1;\r\n this._press = false;\r\n this.RayDir = new Vector3();\r\n this.DownHit = new Laya.HitResult();\r\n this.FowardHit = new Laya.HitResult();\r\n this.curspeed = 0;\r\n this.currotV = new Vector3();\r\n this.currot = new Laya.Quaternion;\r\n this.NormalizeSpeed = new Vector3();\r\n this.curpos = new Vector3();\r\n this.offest = new Vector3();\r\n this.arrowspeed = 10;\r\n this.speed = 0;\r\n this.arrowoffset = new Vector3();\r\n this.arrowcurpos = new Vector3();\r\n }\r\n static get Instance() {\r\n if (Runner.ins) {\r\n return Runner.ins;\r\n }\r\n else {\r\n return new Runner();\r\n }\r\n }\r\n onAwake() {\r\n this.m_player = this.owner;\r\n this.m_animator = this.owner.getComponent(Laya.Animator);\r\n this.m_arrowpos = this.owner.getChildByName(\"arrowpos\");\r\n this.m_raypos = this.owner.getChildByName(\"raypos\");\r\n this.m_archerpos = this.owner.getChildByName(\"archerpos\");\r\n this.m_horseanimator = this.owner.getChildByName(\"horse\").getComponent(Laya.Animator);\r\n this.ChangeState(CharacterState.Idle);\r\n EventManager.StageOn(StageState.Start, this, this.Begin);\r\n }\r\n Begin() {\r\n this.canmove = true;\r\n this.CreatArrow();\r\n this.ChangeState(CharacterState.Run);\r\n }\r\n onUpdate() {\r\n if (this.isdead) {\r\n this.ChangeState(CharacterState.Die);\r\n return;\r\n }\r\n if (this.canmove) {\r\n if (this._press) {\r\n this._speed = 2;\r\n }\r\n this.Move(new Vector3(0, 0, 1), this._speed);\r\n }\r\n this.RayCheck();\r\n }\r\n MoveX(_speed) {\r\n _speed *= 0.07;\r\n this.RayDir = new Vector3(_speed, 0, 0);\r\n this.m_player.transform.translate(new Vector3(_speed, 0, 0));\r\n }\r\n TurnDir(_dir) {\r\n if (_dir.x != 0) {\r\n Vector3.lerp(this.currotV, _dir, 0.35, _dir);\r\n this.currotV = _dir;\r\n Laya.Quaternion.rotationLookAt(_dir, new Vector3(0, 1, 0), this.currot);\r\n Laya.Quaternion.slerp(this.m_player.transform.rotation, this.currot, 0.025, this.currot);\r\n this.currot = new Laya.Quaternion(0, this.currot.y, 0);\r\n this.m_player.transform.rotation = this.currot;\r\n }\r\n else {\r\n }\r\n }\r\n Move(_dir, _speed) {\r\n var sp = GameTools.Instance.lerp(this.curspeed, _speed, 0.1);\r\n this.curspeed = sp;\r\n Vector3.scale(_dir, this.curspeed, this.offest);\r\n Vector3.add(this.m_player.transform.position, this.offest, this.curpos);\r\n Vector3.lerp(this.m_player.transform.position, this.curpos, 0.15, this.curpos);\r\n this.curpos = new Vector3(this.curpos.x, this.curpos.y, this.curpos.z);\r\n this.m_player.transform.position = this.curpos;\r\n }\r\n ChangeState(_state) {\r\n if (this.m_characterstate == _state)\r\n return;\r\n this.m_characterstate = _state;\r\n switch (this.m_characterstate) {\r\n case CharacterState.Idle:\r\n this.Idle();\r\n break;\r\n case CharacterState.Run:\r\n this.Run();\r\n break;\r\n case CharacterState.Die:\r\n this.Die();\r\n break;\r\n case CharacterState.Win:\r\n this.Win();\r\n break;\r\n case CharacterState.Shoot:\r\n this.Shoot();\r\n break;\r\n }\r\n }\r\n Idle() {\r\n this.m_animator.play(\"idle\");\r\n this.m_horseanimator.play(\"idle\");\r\n }\r\n Run() {\r\n this.m_animator.play(\"down\");\r\n this.m_horseanimator.play(\"run\");\r\n }\r\n Die() {\r\n this.canmove = false;\r\n this.m_animator.play(\"die\");\r\n this.m_horseanimator.play(\"idle\");\r\n this.m_raypos.destroy();\r\n this.m_arrowpos.destroy();\r\n this.m_archerpos.destroy();\r\n this.m_arrow.destroy();\r\n Laya.timer.clearAll(this);\r\n }\r\n Win() {\r\n }\r\n Shoot() {\r\n this.m_animator.play(\"shoot\");\r\n this.m_animator.play(\"run\");\r\n }\r\n RayCheck() {\r\n if (this.DownRayCheck) {\r\n this.m_player.transform.position = new Vector3(this.m_player.transform.position.x, this.DownHit.point.y, this.m_player.transform.position.z);\r\n }\r\n if (this.FowardRayCheck) {\r\n this.CrashBarrier();\r\n }\r\n }\r\n CrashBarrier() {\r\n var target = this.FowardHit.collider.owner;\r\n if (target.name == \"\") {\r\n }\r\n else if (target.name == \"fire\") {\r\n }\r\n else if (target.name == \"fence\") {\r\n }\r\n else if (target.name == \"\") {\r\n }\r\n }\r\n get DownRayCheck() {\r\n var isDownHit = false;\r\n var startPos = new Vector3(this.m_player.transform.position.x, this.m_player.transform.position.y + 1.5, this.m_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 get FowardRayCheck() {\r\n var isFowardHit = false;\r\n var startPos = new Vector3(this.m_player.transform.position.x, this.m_player.transform.position.y, this.m_player.transform.position.z + 0.5);\r\n var direction = new Vector3(0, 0, 1);\r\n var DownRay = new Laya.Ray(startPos, direction);\r\n if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(DownRay, this.FowardHit, 1)) {\r\n if (this.FowardHit.collider.collisionGroup == 100) {\r\n isFowardHit = true;\r\n }\r\n }\r\n return isFowardHit;\r\n }\r\n Archery() {\r\n Laya.timer.clear(this, this.ArrowFollow);\r\n let ray = this.owner.getChildByName(\"raypos\").getChildAt(0);\r\n let forw = Transform3DHelper.getForward(ray.transform);\r\n let raypos = this.owner.getChildByName(\"raypos\");\r\n let trans = raypos.transform;\r\n let testRay = new Laya.Ray(new Vector3(trans.position.x, trans.position.y - 1, trans.position.z), forw);\r\n let hitRes = new Laya.HitResult();\r\n this.m_animator.play(\"shoot\");\r\n Laya.timer.frameLoop(1, this, this.AnimatorState);\r\n if (AssetManager.Instance.mainscene.physicsSimulation.rayCast(testRay, hitRes)) {\r\n let target = hitRes.collider.owner.parent;\r\n Laya.timer.frameLoop(1, this, this.ArrowMove, [this.m_arrow, forw, target]);\r\n if (hitRes.collider.owner.name == \"npcfrontcollider\") {\r\n }\r\n else if (hitRes.collider.owner.name == \"npcrearcollider\") {\r\n }\r\n console.log(\"射箭打到东西了---\", hitRes.collider.owner.name);\r\n }\r\n else {\r\n Laya.timer.frameLoop(1, this, this.ArrowMove, [this.m_arrow, forw]);\r\n }\r\n }\r\n ArrowMove(arrow, _dir, target) {\r\n if (target) {\r\n if (this.m_arrow.destroyed)\r\n return;\r\n if (arrow.transform.position.z >= target.transform.position.z) {\r\n let npcrunner = target.getComponent(NpcRunner);\r\n npcrunner.frontdie = true;\r\n Laya.timer.clear(this, this.ArrowMove);\r\n target.addChild(arrow);\r\n Laya.timer.once(2000, this, () => {\r\n GamePool.Instance.RecoveryModel(arrow);\r\n });\r\n }\r\n else {\r\n var sp = GameTools.Instance.lerp(this.speed, this.arrowspeed, 0.1);\r\n this.speed = sp;\r\n Vector3.scale(_dir, this.speed, this.arrowoffset);\r\n Vector3.add(arrow.transform.position, this.arrowoffset, this.arrowcurpos);\r\n Vector3.lerp(arrow.transform.position, this.arrowcurpos, 0.15, this.arrowcurpos);\r\n arrow.transform.position = this.arrowcurpos;\r\n }\r\n }\r\n else {\r\n var sp = GameTools.Instance.lerp(this.speed, this.arrowspeed, 0.1);\r\n this.speed = sp;\r\n Vector3.scale(_dir, this.speed, this.arrowoffset);\r\n Vector3.add(arrow.transform.position, this.arrowoffset, this.arrowcurpos);\r\n Vector3.lerp(arrow.transform.position, this.arrowcurpos, 0.15, this.arrowcurpos);\r\n arrow.transform.position = this.arrowcurpos;\r\n Laya.timer.once(2000, this, () => {\r\n Laya.timer.clear(this, this.ArrowMove);\r\n GamePool.Instance.RecoveryModel(arrow);\r\n });\r\n }\r\n }\r\n AnimatorState() {\r\n if (this.m_animator.getCurrentAnimatorPlayState(0).normalizedTime >= 1) {\r\n Laya.timer.clear(this, this.AnimatorState);\r\n if (!this.m_arrowpos.destroyed) {\r\n this.CreatArrow();\r\n this.shoot = false;\r\n this.m_animator.play(\"idle\");\r\n console.log(\"动画播放完毕--\");\r\n }\r\n }\r\n }\r\n CreatArrow() {\r\n var arrow = GamePool.Instance.GetModel(AssetManager.Instance.Prop.get(17), \"\");\r\n AssetManager.Instance.mainscene.addChild(arrow);\r\n arrow.transform.position = this.m_arrowpos.transform.position.clone();\r\n var euler = this.m_arrowpos.transform.rotationEuler.clone();\r\n let scale = arrow.transform.scale.clone();\r\n scale.z = 0.5;\r\n scale.x = 0.5;\r\n scale.y = 0.5;\r\n arrow.transform.scale = scale;\r\n this.m_arrow = arrow;\r\n Laya.timer.frameLoop(1, this, this.ArrowFollow, [arrow, this.m_arrowpos]);\r\n }\r\n ArrowFollow(arrow, arrowpos) {\r\n if (!arrowpos.destroyed) {\r\n arrow.transform.position = arrowpos.transform.position.clone();\r\n arrow.transform.rotationEuler = arrowpos.transform.rotationEuler.clone();\r\n }\r\n else {\r\n Laya.timer.clear(this, this.ArrowFollow);\r\n }\r\n }\r\n CancelFollow() {\r\n Laya.timer.clear(this, this.ArrowFollow);\r\n }\r\n}\r\n",
- "references": [
- "E:/LayaProject/ArcherWorrior/src/Tools/GameTools.ts",
- "E:/LayaProject/ArcherWorrior/src/Tools/EventManager.ts",
- "E:/LayaProject/ArcherWorrior/src/Tools/AssetManager.ts",
- "E:/LayaProject/ArcherWorrior/src/Tools/GamePool.ts",
- "E:/LayaProject/ArcherWorrior/src/Game/GameManager.ts",
- "E:/LayaProject/ArcherWorrior/src/Game/NpcRunner.ts"
- ]
- }
|