123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import { _decorator, Component, Node, Vec3 } from 'cc';
- import { Role } from '../Role';
- import { LevelData, RoleData } from '../../../DataItem/ItemData';
- import { LifeBar } from './LifeBar';
- const { ccclass, property } = _decorator;
- @ccclass('Enemy')
- export class Enemy extends Role {
- private _lifeBar: LifeBar = null;
- private _roles: Node = null;
- protected onLoad(): void {
- this._lifeBar = this.node.getComponent(LifeBar);
- this._roles = this.node.parent.parent.getChildByPath("Road/Roles");
- }
- init(name: string, pos: Vec3, data: RoleData[], dir?: number) {
- super.init(name, pos, data, dir);
- this._initLifeBar();
- }
- //初始化血条
- private _initLifeBar(){
- this._lifeBar._curHp = this.hp;
- this._lifeBar._totalHp = this.hp;
- }
- update(deltaTime: number) {
- if (!this.isStop) {
- this.move(deltaTime)
- }
- this.stop();
- if(!this.isAttacking){
- super.getEnemiesAhead(this._roles);
- }
- }
- stop(): void {
- if (this.node.getWorldPosition().x <= 200) {
- this.isStop = true;
- }
- }
- }
|