1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { _decorator, Node, PhysicsGroup, Vec3 } from 'cc';
- import { Role, RoleState } from '../Role';
- import { RoleData } from '../../../DataItem/ItemData';
- import { LifeBar } from './LifeBar';
- import { MyRole } from './MyRole';
- 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) {
- super.update(deltaTime);
- super.stop();
-
- }
- stop(): void {
- if (this.node.getWorldPosition().x <= 200) {
- this.playAnimation(RoleState.Idle);
- this.moveSpeed = 0;
- }
- }
- //必须实现抽象方法
- protected _getCollisionGroup(): number {
- return PhysicsGroup.Enemy; //实际分组值根据项目设置
- }
- protected _isValidTarget(target: Role): boolean {
- //通过组件类型判断是否为敌人
- return target instanceof MyRole;
- }
- }
|