b374726e021160756863a0f3fcf70e0bbd6c5f75 5.6 KB

12345678910111213141516171819
  1. {
  2. "code": "import { Role, RoleState, RoleData } from \"./Role\";\r\nvar Vector3 = Laya.Vector3;\r\nimport { AssetManager } from \"./AssetManager\";\r\nimport PoolManager from \"../Util/PoolManager\";\r\nimport { SceneManager } from \"./SceneManager\";\r\nimport { ColliderLay, GameState } from \"./DataMaker\";\r\nimport { EventManager, EventType } from \"./EventManager\";\r\nimport { GameUtils } from \"../Util/GameUtils\";\r\nimport { LevelManager } from \"./LevelManager\";\r\nimport { Player } from \"./Player\";\r\nimport { GameManager } from \"./GameManager\";\r\nexport class GirlData extends RoleData {\r\n constructor(_id, _startpos) {\r\n super(_id, _startpos);\r\n }\r\n}\r\nexport class Girl extends Role {\r\n constructor() {\r\n super(...arguments);\r\n this.awakedistance = 8;\r\n this.life = false;\r\n }\r\n static Create(_data) {\r\n var roleid = _data.id;\r\n var roleasset = AssetManager.girl.getValue(roleid);\r\n var model = PoolManager.GetSprite3D(roleasset);\r\n SceneManager.mainscene.addChild(model);\r\n model.transform.position = new Vector3(_data.startpos.x, _data.startpos.y, _data.startpos.z);\r\n model.transform.rotationEuler = new Vector3(model.transform.rotationEuler.x, 360 - _data.startpos.w, model.transform.rotationEuler.z);\r\n var monster = model.addComponent(Girl);\r\n monster.Init(model);\r\n monster.collider = model.getChildAt(1).getComponent(Laya.PhysicsCollider);\r\n monster.collider.collisionGroup = ColliderLay.monster;\r\n monster.OnInit();\r\n return monster;\r\n }\r\n OnInit() {\r\n this.mlevel = LevelManager.Instance.curlevel;\r\n this.RegEvent();\r\n }\r\n OnClear() {\r\n EventManager.Off(EventType.Cut, this, this.OnCut);\r\n EventManager.Off(EventType.Running, this, this.OnRunning);\r\n }\r\n RegEvent() {\r\n EventManager.On(EventType.Cut, this, this.OnCut);\r\n EventManager.On(EventType.Running, this, this.OnRunning);\r\n }\r\n OnCut(_collider) {\r\n if (_collider != this.collider)\r\n return;\r\n this.ChangeState(RoleState.Die);\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 var dis = GameUtils.Vector32Length(mainplayerpos, curpos);\r\n return dis;\r\n }\r\n OnRunning(_playerpos) {\r\n if (this.life)\r\n return;\r\n var curpos = this.cursprite.transform.position.clone();\r\n var dis = GameUtils.Vector32Length(_playerpos, curpos);\r\n if (dis < this.awakedistance && this.currolestate == RoleState.Idle) {\r\n this.ChangeState(RoleState.Awake);\r\n }\r\n }\r\n OnLife() {\r\n if (Player.mainpalyer.currolestate == RoleState.Die)\r\n return;\r\n this.ChangeState(RoleState.Awake);\r\n }\r\n onStateChange(_state, _data) {\r\n Laya.timer.clearAll(this);\r\n Laya.timer.clear(this, this.OnLife);\r\n if (_state == RoleState.Awake) {\r\n this.OnEnterAwake();\r\n }\r\n else if (_state == RoleState.Die) {\r\n this.OnEnterDie();\r\n }\r\n else if (_state == RoleState.Attack) {\r\n this.OnEnterAttack();\r\n }\r\n else if (_state == RoleState.Idle) {\r\n this.OnEnterIdle();\r\n }\r\n }\r\n OnEnterIdle() {\r\n this.curanimator.play(\"idle\");\r\n if (this.life) {\r\n Laya.timer.frameOnce(40, this, () => {\r\n Laya.timer.clear(this, this.OnLife);\r\n Laya.timer.frameLoop(1, this, this.OnLife);\r\n });\r\n }\r\n }\r\n OnEnterAttack() {\r\n Laya.timer.clear(this, this.AttackLoop);\r\n this.AttackLoop();\r\n }\r\n AttackLoop() {\r\n this.curanimator.play(\"help\");\r\n var attackduation = 80;\r\n Laya.timer.frameOnce(attackduation, this, () => {\r\n this.ChangeState(RoleState.Idle);\r\n });\r\n }\r\n OnEnterAwake() {\r\n this.life = true;\r\n }\r\n OnEnterDie() {\r\n this.curanimator.play(\"die\");\r\n Laya.timer.frameOnce(50, this, () => {\r\n this.FallLand(0, () => {\r\n this.Clear();\r\n });\r\n GameManager.Instance.ChangeGameState(GameState.Lose);\r\n });\r\n }\r\n OnEnterLose() {\r\n }\r\n onUpdate() {\r\n }\r\n EscapeLoop() {\r\n }\r\n AwakeLoop() {\r\n }\r\n onTriggerEnter(_collider) {\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/Main/AssetManager.ts",
  6. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/PoolManager.ts",
  7. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/SceneManager.ts",
  8. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/DataMaker.ts",
  9. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/EventManager.ts",
  10. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/GameUtils.ts",
  11. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/LevelMaker.ts",
  12. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/LevelManager.ts",
  13. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/Player.ts",
  14. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/PathMove.ts",
  15. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/RigObj.ts",
  16. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/GameManager.ts"
  17. ]
  18. }