123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- import FF from "../../FF";
- import FSprite from "../../object/FSprite";
- const { ccclass, property } = cc._decorator;
- enum BoomStatus {
- safe, //安全阶段
- warning, //警告阶段
- boom, //爆炸阶段
- end, //爆炸结束
- }
- enum RoleArea {
- safe, // 安全
- hit, // 受伤
- }
- /**
- * 定时炸弹
- */
- @ccclass
- export default class FBomb extends cc.Component {
- @property({
- displayName: "怪物ID"
- })
- monsterId: number = 0;
- @property({
- displayName: '爆炸动画',
- type: sp.Skeleton
- })
- spine: sp.Skeleton = null;
- @property({
- displayName: "警告区域",
- })
- warningArea = new cc.Vec2();
- @property({
- displayName: "爆炸范围",
- })
- boomArea = new cc.Vec2();
- @property({
- displayName: "警告时间(秒)"
- })
- warningTime: number = 0;
- @property({
- displayName: "爆炸时间(秒)"
- })
- boomTime: number = 0;
- ff: FF;
- public spriteList: Array<FSprite> = [];
- boomStatus: BoomStatus = BoomStatus.safe;
- // roleArea: RoleArea = RoleArea.safe;
- tempTime: number = 0;
- isHit: boolean = false;
- isWarning: boolean = false;
- start() {
- let boxs = this.node.getComponents(cc.PhysicsBoxCollider)
- boxs[0].size = new cc.Size(this.warningArea.x, this.warningArea.y);
- boxs[1].size = new cc.Size(this.boomArea.x, this.boomArea.y);
- }
- // public onBegin(tag: number) {
- // // this.roleArea = tag == 1 ? RoleArea.hit : RoleArea.safe;
- // if (tag == 0) {
- // if (!this.isWarning) {
- // this.warning();
- // }
- // }
- // }
- // public onEnd(tag: number) {
- // if (tag == 1) {
- // // this.roleArea = RoleArea.safe;
- // }
- // }
- onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
- if (other.node.group == 'A' && self.tag == 1) {
- let obj = other.node.getComponent(FSprite);
- if (this.spriteList.indexOf(obj) == -1) {
- this.spriteList.push(obj);
- }
- }
- if (other.node.group == 'A' && other.tag == 1) {
- let obj = other.node.getComponent(FSprite);
- this.ff = obj.ff;
- if (self.tag == 0) {
- if (!this.isWarning) {
- this.warning();
- }
- }
- }
- }
- onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
- if (other.node.group == 'A' && self.tag == 1) {
- let obj = other.node.getComponent(FSprite);
- this.removeSprite(obj);
- }
- }
- private removeSprite(sprite: FSprite) {
- for (let i = 0; i < this.spriteList.length; i++) {
- const element = this.spriteList[i];
- if (element == sprite) {
- this.spriteList.splice(i, 1);
- break
- }
- }
- }
- // 警告
- warning() {
- this.isWarning = true;
- this.spine.setAnimation(0, "boom", true);
- this.boomStatus = BoomStatus.warning;
- let tempTime = 0;
- let call = () => {
- tempTime += 0.1;
- if (tempTime >= this.warningTime) {
- // console.log("===警告结束===");
- this.boom();
- this.unschedule(call);
- }
- }
- this.schedule(call, 0.1);
- }
- //爆炸
- boom() {
- this.spine.setAnimation(0, "boom2", false);
- this.boomStatus = BoomStatus.boom;
- let tempTime = 0;
- let call = () => {
- tempTime += 0.1;
- if (tempTime >= this.boomTime) {
- this.end();
- this.unschedule(call);
- } else {
- if (!this.isHit) {
- this.hit();
- }
- // if (this.roleArea == RoleArea.hit && !this.isHit) {
- // this.hit();
- // }
- }
- }
- this.schedule(call, 0.1);
- }
- hit() {
- this.isHit = true;
- this.spriteList.forEach(sprite => {
- let main = this.ff.main;
- let attrData = main.sManage.getMonsterData(this.monsterId);
- sprite.bAtkjs(attrData)
- })
- }
- //爆炸结束
- end() {
- this.boomStatus = BoomStatus.end;
- this.node.active = false;
- }
- }
|