'use strict';

cc.Class({
    extends: cc.Component,

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

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

    startGame: function startGame() {
        cc.director.getPhysicsManager().enabled = true;
    },
    stopGame: function stopGame() {
        cc.director.getPhysicsManager().enabled = false;
    },
    pauseGame: function pauseGame() {
        cc.director.getPhysicsManager().enabled = !cc.director.getPhysicsManager().enabled;
    },
    onBallContactBrick: function onBallContactBrick(ball, brick) {
        if (ball.isAttackAble) {
            var 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: function onBallContactPaddle(ball, paddle) {
        ball.isAttackAble = true;
    },
    onBallContactGround: function onBallContactGround(ball, ground) {
        ball.node.parent = null;
    }
});