80 lines
1.8 KiB
TypeScript
Raw Permalink Normal View History

2025-04-24 17:03:28 +08:00
import GameObject from "./NGameObject";
const {ccclass, property} = cc._decorator;
@ccclass
export default class NLivingThing extends GameObject{
@property(cc.ProgressBar)
hpBar:cc.ProgressBar=null;
actList:any[];
livingState:number;
hp:number;
mp:number;
isDie:Boolean;
livingType:number;
onLoad() {
super.onLoad();
this.actList = []; // 行動隊列,{type:t, info:i}.type:(0 idle 1 attack 2 move 3 dead)
this.livingState = 0; // 狀態 0 idle 1 attack 2 move 3 dead
this.hp = 100;
this.mp = 0;
this.isDie = false;
this.livingType = 0;
this.onlyId = 0;
}
playStop() {
if (this.livingState == 0) {
return;
}
this.livingState = 0;
}
playAtk() {
this.livingState = 1;
}
playHit(hp:number) {
if (this.hpBar) {
this.hpBar.node.active = true;
this.hpBar.progress = hp / this.hp;
}
//播放被打動畫
}
playDie() {
this.livingState = 3;
//播放死亡動畫
this.isDie = true;
this.node.runAction(cc.sequence(cc.fadeOut(1), cc.removeSelf()));
}
start() {
this.schedule(this.objUpdate, 0.1, cc.macro.REPEAT_FOREVER, 0.1);
}
objUpdate() {
this.node.zIndex = Math.round(576 - (this.node.parent.convertToWorldSpaceAR(cc.v2(this.node.x, this.node.y))).y);
if (this.actList.length > 0) {
if (this.actList[0].type == 2 && this.livingState != 2) {
let act = this.actList.shift();
this.objMove(act.info.r, act.info.l);
}
} else {
this.playStop();
}
}
setInfo(objInfo:any) {
this.onlyId = objInfo.onlyid;
}
objMove(row:number,line:number) {
this.livingState = 2;
}
}