123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- import FF from "../../FF";
- import FSprite from "../../object/FSprite";
- /**
- * 掉落的石头
- */
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class FStoneDrop extends cc.Component {
- @property({
- displayName: '数值(怪物id)'
- })
- public monsterId = 1001;
- @property({
- displayName: '每次滚动停留时间(秒)'
- })
- public interval = 2;
- @property({
- type: sp.Skeleton,
- displayName: '滚动动画'
- })
- public spine: sp.Skeleton = null;
- @property({
- displayName: "警告",
- type: cc.Node
- })
- warnNode: cc.Node = null;
- private ff: FF;
- private isRoll = false;
- private isHit: boolean = false;
- private isWarn: boolean = false;
- private tempTime: number = 0;
- public spriteList: Array<FSprite> = [];
- callFunc: Function = null;
- onLoad() {
- cc.tween(this.node).sequence(
- cc.delayTime(this.interval),
- cc.fadeIn(0),
- cc.callFunc(() => {
- this.isRoll = true;
- this.spine.setAnimation(0, "atk", false);
- // this.spine.setEndListener(() => {
- // this.isRoll = false;
- // this.isHit = false;
- // })
- }),
- cc.delayTime(1),
- cc.fadeOut(0.2),
- cc.callFunc(() => {
- this.isRoll = false;
- this.isHit = false;
- this.tempTime = 0;
- this.isWarn = false;
- })
- ).repeatForever().start();
- }
- onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
- if (other.node.group == 'A' && other.tag == 1) {
- let obj = other.node.getComponent(FSprite);
- this.ff = obj.ff;
- if (this.spriteList.indexOf(obj) == -1) {
- this.spriteList.push(obj);
- }
- }
- }
- onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
- if (other.node.group == 'A' && other.tag == 1) {
- let obj = other.node.getComponent(FSprite);
- this.removeSprite(obj);
- this.isHit = false;
- }
- }
- 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
- }
- }
- }
- hit() {
- this.isHit = true;
- this.spriteList.forEach(sprite => {
- let main = this.ff.main;
- let attrData = main.sManage.getMonsterData(this.monsterId);
- sprite.bAtkjs(attrData)
- })
- }
- warnAction() {
- if (this.isWarn) return
- this.warnNode.stopActionByTag(1);
- this.isWarn = true;
- this.warnNode.opacity = 0;
- let action = cc.tween(this.warnNode).sequence(
- cc.fadeIn(0.1),
- cc.fadeOut(0.1),
- ).repeat(6).start();
- action.tag(1);
- }
- update(dt) {
- if (this.isRoll && !this.isHit) {
- this.hit();
- }
- this.tempTime += dt;
- if (this.interval - this.tempTime <= 1) {
- this.warnAction();
- }
- }
- }
|