import { GameNotificationKey } from "../utils/GameEnum";

cc.Class({
    extends: cc.Component,

    properties: {
        catNode: cc.Node,
        catSkeleton: sp.Skeleton,
    },

    onLoad() {

    },

    fly(startPosition, endPosition) {
        this.catNode.setPosition(startPosition);
        this.catNode.setScale(0.1);
        let moveTo = cc.moveTo(0.4, 0, 0);
        let scaleTo = cc.scaleTo(0.4, 1, 1);
        this.catNode.runAction(cc.spawn(moveTo, scaleTo));

        this.catSkeleton.setAnimation(0, 'hit2', false);

        this.catSkeleton.setCompleteListener(() => {
            this.catSkeleton.setAnimation(0, 'fly', true);

            let move = cc.moveTo(0.5, endPosition.x, endPosition.y);
            let scale = cc.scaleTo(0.5, 0.1, 0.1);
            let a = cc.spawn(move, scale);


            let finish = cc.callFunc(() => {
                GameEvent.fire(GameNotificationKey.afterCatFly);
                this.node.destroy();
            }, this);

            let s = cc.sequence(a, finish)
            this.catNode.runAction(s);
        });
    },

    start() {

    },

});
