You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.8 KiB
101 lines
2.8 KiB
import { _decorator, CCBoolean, CCInteger, Collider2D, Component, Contact2DType, IPhysics2DContact, Label, Node } from 'cc';
|
|
import { GEvent } from 'db://assets/mx/module/event/GEvent';
|
|
import { atgSkill } from './atgSkill';
|
|
import { monsterScript } from './monsterScript';
|
|
import { gaoyaguo } from './gaoyaguo';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('atgMonster')
|
|
export class atgMonster extends Component {
|
|
@property(CCBoolean)
|
|
isBoos: boolean = false;
|
|
@property(CCInteger)
|
|
booldNum:number = 1
|
|
attackEffect:Node = null;
|
|
|
|
isDie: boolean = false;
|
|
monsterCore:monsterScript = null;
|
|
|
|
|
|
|
|
setMonstrData(HPCount){
|
|
|
|
this.booldNum = HPCount;
|
|
this.isDie = false;
|
|
|
|
}
|
|
|
|
protected onDisable(): void {
|
|
let collider = this.getComponent(Collider2D);
|
|
if (collider) {
|
|
collider.off(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
|
}
|
|
}
|
|
|
|
protected onEnable(): void {
|
|
let collider = this.getComponent(Collider2D);
|
|
if (collider) {
|
|
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
|
}
|
|
}
|
|
|
|
onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null){
|
|
//selfCollider 怪物
|
|
//otherCollider 子弹
|
|
//当怪物碰到了墙或者主角
|
|
|
|
if(this.isDie){
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
this.booldNum--;
|
|
if(this.booldNum <= 0){
|
|
gaoyaguo.Instance.skillMonsterNum++;
|
|
this.isDie = true;
|
|
// 物理回调里直接 active=false/destroy/改刚体会报警告:先关碰撞,再延迟到下一帧隐藏
|
|
if (selfCollider) selfCollider.enabled = false;
|
|
this.scheduleOnce(() => {
|
|
if (!this.node?.isValid) return;
|
|
//回收
|
|
this.node.active = false;
|
|
}, 0);
|
|
//console.log('gaoyaguo.Instance.skillMonsterNum', gaoyaguo.Instance.skillMonsterNum)
|
|
|
|
}
|
|
if(this.isBoos){
|
|
let lab = this.node.getChildByName('Label')
|
|
if(lab){
|
|
lab.active = true
|
|
lab.getComponent(Label).string = this.booldNum.toString()
|
|
}
|
|
}
|
|
|
|
otherCollider.getComponent(atgSkill)?.removeZidan();
|
|
if(gaoyaguo.Instance.skillMonsterNum>=300*10+1){
|
|
//成功了
|
|
gaoyaguo.Instance.gameoverSuccess();
|
|
}
|
|
}
|
|
|
|
|
|
removeMonster(){
|
|
this.node.destroy()
|
|
}
|
|
|
|
start() {
|
|
this.attackEffect = this.node.getChildByName('attackEffect');
|
|
}
|
|
|
|
// update(deltaTime: number) {
|
|
// //
|
|
// if(gaoyaguo.Instance.jiedianIndex == 3 || gaoyaguo.Instance.jiedianIndex == 4){
|
|
// //当前阶段开始移动
|
|
|
|
// }
|
|
|
|
// }
|
|
}
|
|
|
|
|
|
|