123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import { _decorator, Component, Node, sp, UITransform, Vec2, Vec3 ,Animation, Color, tween} from 'cc';
- import { ObjectUtil } from '../../../../framework/util/ObjectUtil';
- import { BattleNodeBase } from './BattleNodeBase';
- import { RenderPriority } from '../data/BattleEnum';
- const { ccclass, property } = _decorator;
- // 敌人基类
- @ccclass('Enemy')
- export class Enemy extends BattleNodeBase {
- @property({ type: sp.Skeleton, tooltip: '骨骼动画' })
- modelSpine: sp.Skeleton = null;
- @property({ type: Node, tooltip: '血条' })
- lifeNode: Node = null;
- private _bHurtAnimation: boolean = false;
- life: number = 0;
- lifeMax: number = 0;
- speedVector: Vec2 = new Vec2(0, 0);
-
- hurtColor = new Color(255,100,100,255)
- hurtTime = 0
- bStand: boolean = false;
- dieCallback: Function = null;
- protected onLoad(): void {
- this.priority = RenderPriority.Enemy;
- this.modelSpine.setCompleteListener(this.actionComplete.bind(this))
- }
- start() {
-
- }
- //用自定义更新,不用系统更新
- battleUpdate(deltaTime: number) {
- if(this.hurtTime > 0){
- this.hurtTime -= deltaTime
- if(this.hurtTime <= 0){
- this.modelSpine.color = Color.WHITE;
- this._bHurtAnimation = false
- }
- }
- if((!this.bStand) && (this.life > 0)){
- this.node.position = new Vec3(this.node.position.x+this.speedVector.x*deltaTime,this.node.position.y+this.speedVector.y*deltaTime,0)
- }
- }
- resetData(typeID:number,ID:number,pos:Vec3,life:number,lifeMax:number) {
- this.typeID = typeID;
- this.ID = ID;
- this.node.position = pos
- this.lifeNode.scale = new Vec3(1,1,1)
- this.life = life;
- this.lifeMax = lifeMax;
- this.bStand = false;
- this.dieCallback = null;
- this.updateLife()
- }
-
- startMove(animationName:string){
- this.node.active = true;
- this.modelSpine.setAnimation(0, 'idle', true);
- this.modelSpine.color = Color.WHITE;
- // this.lineAnimation.play(animationName);
- }
- hurt(value:number) {
- this.life -= value;
- this.hurtTime = 0.5
- this.updateLife()
- if(this._bHurtAnimation) return
- this._bHurtAnimation = true
- // this.modelSpine.setAnimation(0, 'hurt', false);
- this.modelSpine.color = this.hurtColor;
- }
- stand() {
- this.bStand = true;
- if(!this.modelSpine.node.active) return;
- this._bHurtAnimation = false;
- this.modelSpine.setAnimation(0, 'idle', true);
- this.modelSpine.color = Color.WHITE;
- // this._attackCallback = null;
- }
- updateLife(){
- if(this.life < 0) {
- this.lifeNode.scale = new Vec3(0,1,1);
- }
- else {
- this.lifeNode.scale = new Vec3(this.life / this.lifeMax,1,1);
- }
- }
- clearData() {
- this.node.active = false
- }
-
- die(callback?:Function) {
-
- this.dieCallback = callback;
- tween(this.node).delay(0.5).call(() => {
- this.node.active = false
- this.modelSpine.color = Color.WHITE;
- this.dieCallback && this.dieCallback()
- }).start()
- }
- actionComplete(trackEntry:sp.spine.TrackEntry){
- // console.log("动作完成:",trackEntry.animation.name,this._posID)
- if (trackEntry.animation.name && trackEntry.animation.name.includes("hurt")) {
- this._bHurtAnimation = false;
- this.modelSpine.addAnimation(0, 'idle', true);
- this.modelSpine.color = Color.WHITE;
- }
- }
-
- }
|