cc.Class({
    extends: cc.Component,

    properties: {
        ballPrefab:cc.Prefab,
        curtain:require('Curtain'),
    },

    // use this for initialization
    onLoad: function () {
        cc.gamectl = this;
        this.node.on('touchstart', function (event) {
            cc.log(event.getLocationX());
            cc.log(event.getLocationY());
        });
    },

    startGame() {
        cc.director.getPhysicsManager().enabled = true;
    },

    stopGame(){
        cc.director.getPhysicsManager().enabled = false;
    },

    pauseGame(){
        cc.director.getPhysicsManager().enabled = !cc.director.getPhysicsManager().enabled;
    },
    
    onBallContactBrick(ball, brick) {
        if (ball.isAttackAble) {
            let newBallNode = cc.instantiate(this.ballPrefab);
            newBallNode.position = ball.node.position;
            // newBallNode.getComponent(cc.RigidBody).linearVeiocity = cc.v2(-50, -30);
            newBallNode.parent = ball.node.parent;
            ball.isAttackAble = false;

            // brick.node.parent = null;
            this.curtain.removeBrick(brick.node);
            // setTimeout(()=>{
            //      this.curtain.addBrick(1);
            // },0);
            this.curtain.addBrick(1);
        }
    },

    onBallContactPaddle(ball, paddle) {
        ball.isAttackAble = true;
    },

    onBallContactGround(ball, ground) {
        ball.node.parent = null;
    },


});