1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { _decorator, Node, PhysicsGroup, Vec3 } from 'cc';
- import { Role, RoleState } from '../Role';
- import { RoleData } from '../../../DataItem/ItemData';
- import { LifeBar } from './LifeBar';
- import { Enemy } from './Enemy';
- const { ccclass, property } = _decorator;
- @ccclass('MyRole')
- export class MyRole extends Role {
- private _lifeBar: LifeBar = null;
- protected onLoad(): void {
- this._lifeBar = this.node.getComponent(LifeBar);
- }
- init(name: string, pos: Vec3, data: RoleData[]) {
- super.init(name, pos, data, 1)
- 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 >= 1160){
- super.playAnimation(RoleState.Idle);
- this.moveSpeed = 0;
- }
- }
- //必须实现抽象方法
- protected _getCollisionGroup(): number {
- return PhysicsGroup.Role; //实际分组值根据项目设置
- }
- protected _isValidTarget(target: Role): boolean {
- //通过组件类型判断是否为敌人
- return target instanceof Enemy;
- }
- }
|