MyRole.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { _decorator, Node, Vec3 } from 'cc';
  2. import { Role } from '../Role';
  3. import { RoleData } from '../../../DataItem/ItemData';
  4. import { LifeBar } from './LifeBar';
  5. import { GameMgr } from '../../GameFrameWork/GameMgr';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('MyRole')
  8. export class MyRole extends Role {
  9. private _lifeBar: LifeBar = null;
  10. private _enemies: Node = null;
  11. protected onLoad(): void {
  12. this._lifeBar = this.node.getComponent(LifeBar);
  13. this._enemies = this.node.parent.parent.parent.getChildByName("EnemyMgr");
  14. //this._enemies = find("GameRoot/EnemyMgr");
  15. }
  16. init(name: string, pos: Vec3, data: RoleData[]) {
  17. super.init(name, pos, data, 1)
  18. this._initLifeBar();
  19. }
  20. //初始化血条
  21. private _initLifeBar(){
  22. this._lifeBar._curHp = this.hp;
  23. this._lifeBar._totalHp = this.hp;
  24. }
  25. update(deltaTime: number) {
  26. super.update(deltaTime)
  27. super.stop()
  28. if(!this.isAttacking){
  29. super.getEnemiesAhead(this._enemies);
  30. }
  31. }
  32. stop(): void {
  33. if(this.node.getWorldPosition().x >= 1160){
  34. this.isStop = true;
  35. }
  36. }
  37. }