cc.Class({
    extends: cc.Component,

    properties: {
        perfect: {
            default: null,
            type: cc.Node,
            serializable: true,
        },
        combo: {
            default: null,
            type: cc.Node,
            serializable: true,
        },
        x: {
            default: null,
            type: cc.Node,
            serializable: true,
        },
        num: {
            default: null,
            type: cc.Node,
            serializable: true,
        },
        hitAudio: {
            default: null,
            type: cc.AudioClip,
            serializable: true,
        },
        perfectAudio: {
            default: null,
            type: cc.AudioClip,
            serializable: true,
        },
        counting:0,
    },
    onLoad()
    {
        this.centerPosition = this.node.position;
        this.tween = cc.tween;
    },
    triggleCombo()
    {
        this.node.stopAllActions();
        this.node.position = this.centerPosition;
        this.node.opacity = 255;
        this.node.scale = 1;
        this.unschedule(this.unTriggleCombo);
        this.scheduleOnce(this.unTriggleCombo,2);

        if(this.counting == 10)
        {
            this.counting = 0;
            this.combo.active = false;
            this.x.active = false;
            this.num.active = false;
            this.perfect.active = true;

            cc.audioEngine.play(this.perfectAudio, false, 1);

            this.tween(this.node)
                .parallel(
                    this.tween().to(1, { opacity: 0 }),
                    this.tween().by(1, { scale: 1.2 }),
                    this.tween().by(1, { position: cc.v2(0, 100) })
                )
                .start();

            return;
        }

        this.combo.active = true;
        this.x.active = true;
        this.num.active = true;
        this.perfect.active = false;

        this.counting++;

        this.num.getComponent(cc.Label).string = this.counting.toString();

        cc.audioEngine.play(this.hitAudio, false, 1);

        this.tween(this.node)
            .by(0.1, { position: cc.v2(0, 100) })
            .parallel(
                this.tween().to(1, { opacity: 0 }),
                this.tween().by(1, { position: cc.v2(0, 100) })
            )
            .start()
    },
    unTriggleCombo()
    {
        this.counting = 0;
        this.combo.active = false;
        this.x.active = false;
        this.num.active = false;
        this.perfect.active = false;
    },
});
