"use strict";
cc._RF.push(module, 'b0432BA295DjIOcuitdGKO1', 'GameManager');
// Script/GameManager.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
// 主游戏控制类
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GameManager = /** @class */ (function (_super) {
    __extends(GameManager, _super);
    function GameManager() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.ball = null;
        _this.qiu1 = null;
        _this.qiu2 = null;
        _this.qiu3 = null;
        _this.linePrefab = null;
        _this.hit = null;
        _this.bg1 = null;
        _this.bg2 = null;
        _this.time = null;
        _this.begin = false;
        _this.fuhuo = false;
        _this.over = false;
        _this.show = false;
        _this.levelLabel = null;
        return _this;
    }
    GameManager.prototype.onLoad = function () { };
    GameManager.prototype.start = function () {
        this.fit();
        this.init();
    };
    //初始化数据
    GameManager.prototype.init = function () {
        this.node.getChildByName("GameOver").zIndex = 100;
        this.node.getChildByName("GameOver").active = false;
        this.ball.zIndex = 100;
        this.bg1 = this.node.getChildByName("bg1");
        this.bg2 = this.node.getChildByName("bg2");
        this.time = this.node.getChildByName("Top").getChildByName("time").getComponent(cc.Label);
        this.node.getChildByName("showBtn").active = false;
        this.begin = false;
        this.over = false;
        this.fuhuo = true;
        this.pause = true;
        this.show = false;
        this.round = 0;
        this.level = 2;
        this.countTime = 60;
        if (cc.fx.GameConfig.GM_INFO.custom != 0) {
            this.level = cc.fx.GameConfig.GM_INFO.custom;
            // this.levelLabel.string = this.level + "";
            cc.fx.GameConfig.GM_INFO.custom += 1;
            this.countTime = 12000000;
        }
        // this.levelLabel.string = this.level + "";
        this.timeCount = 0.1;
        this.clickNow = 0;
        this.clickCount = 0;
        this.timeStart = 0;
        this.repeat = -1;
        this.numberRepeat = -1;
        this.route_Array = [];
        this.moveArray = [];
        this.now_Array = [];
        this.ball_Array = [];
        this.Pos_Array = [];
        this.time_Array = [];
        this.color_Array = [];
        cc.fx.GameConfig.GAME_DATA = [];
        cc.fx.GameConfig.GM_INFO.success = false;
        this.startTime = 0;
        this.overTime = 0;
        this.winTime = 0;
        cc.fx.GameConfig.GM_INFO.total = 0;
        cc.fx.GameConfig.GM_INFO.mean_Time = 0;
        this.schedule(this.updateCountDownTime, 1);
        this.startGame();
    };
    //根据是否全面屏，做独立适配方面
    GameManager.prototype.fit = function () {
        this.fitTop = 450; //600
        this.fitBot = -600; //-700
        var jg = this.setFit();
        if (!jg) {
            this.fitTop = 600;
            this.fitBot = -700;
        }
    };
    //判断全面屏
    GameManager.prototype.getSetScreenResolutionFlag = function () {
        var size = cc.winSize;
        var width = size.width;
        var height = size.height;
        if ((height / width) > (16.2 / 9))
            return false;
        return true;
    };
    //判断全面屏适配
    GameManager.prototype.setFit = function () {
        var flag = this.getSetScreenResolutionFlag();
        if (flag) {
        }
        else {
        }
        return flag;
    };
    //返回首页
    GameManager.prototype.backScene = function () {
        cc.director.loadScene("LoadScene");
    };
    //下一关，或者重新开始，或者返回上一关，根据level决定
    GameManager.prototype.reStart = function (type) {
        // if(cc.fx.GameConfig.GM_INFO.custom != 0){
        //     cc.director.loadScene("LoadScene");
        //     return;
        // }
        this.node.getChildByName("showBtn").active = false;
        this.destroyLine();
        this.timeCount = 0.1;
        this.clickNow = 0;
        this.timeStart = 0;
        this.repeat = -1;
        this.numberRepeat = -1;
        this.begin = false;
        this.route_Array = [];
        this.now_Array = [];
        this.ball_Array = [];
        this.Pos_Array = [];
        this.moveArray = [];
        this.time_Array = [];
        this.color_Array = [];
        if (type == 0) {
            this.bgMove(1);
        }
        else if (type == 1) {
            this.startGame();
        }
        else if (type == 2) {
            this.bgMove(-1);
        }
    };
    //获取时间戳
    GameManager.prototype.getTime = function () {
        var timestamp = new Date().getTime();
        return timestamp;
    };
    //获胜
    GameManager.prototype.passLevel = function () {
        var _this = this;
        this.destroyLine();
        if (this.over == false && this.countTime >= 0) {
            var timeArray_1 = [];
            var timeCount = 0;
            var ball_1 = this.ball_Array[0];
            for (var i = 1; i < this.ball_Array.length; i++) {
                var time = this.calculateDistance(this.ball_Array[i].x, this.ball_Array[i].y, this.ball_Array[i - 1].x, this.ball_Array[i - 1].y, 2);
                timeArray_1.push(time);
            }
            var _loop_1 = function (k) {
                setTimeout(function () {
                    cc.tween(ball_1)
                        .to(timeArray_1[k - 1], { x: _this.ball_Array[k].x, y: _this.ball_Array[k].y })
                        .call(function () {
                        _this.ball_Array[k].active = false;
                        if (k == _this.ball_Array.length - 1) {
                            setTimeout(function () {
                                _this.ball.opacity = 255;
                                _this.ball.position = cc.v3(ball_1.x, ball_1.y, 0);
                                ball_1.active = false;
                                _this.clearSun();
                                _this.reStart(0);
                            }, 200);
                        }
                    })
                        .start();
                }, timeCount * 1000);
                timeCount += (timeArray_1[k - 1] + 0.1);
            };
            for (var k = 1; k < this.ball_Array.length; k++) {
                _loop_1(k);
            }
        }
    };
    //失败
    GameManager.prototype.loseLevel = function (type) {
        var _this = this;
        this.destroyLine();
        if (this.over == false && this.countTime >= 0) {
            var ball_2 = this.ball_Array[0];
            var _loop_2 = function (k) {
                cc.tween(this_1.ball_Array[k])
                    .to(2, { x: ball_2.x, y: ball_2.y })
                    .call(function () {
                    _this.ball_Array[k].active = false;
                    if (k == _this.ball_Array.length - 1) {
                        _this.ball.opacity = 255;
                        _this.ball.position = cc.v3(ball_2.x, ball_2.y, 0);
                        _this.clearSun();
                        _this.reStart(type);
                    }
                })
                    .start();
            };
            var this_1 = this;
            for (var k = 1; k < this.ball_Array.length; k++) {
                _loop_2(k);
            }
        }
    };
    //清理太阳
    GameManager.prototype.clearSun = function () {
        for (var k = 0; k < this.ball_Array.length; k++) {
            this.ball_Array[k].removeFromParent();
            this.ball_Array[k] = null;
        }
    };
    //点击太阳执行方法
    GameManager.prototype.clickSun = function (data) {
        var _this = this;
        if (this.begin == true) {
            this.clickCount += 1;
            var clickTime = cc.fx.GameTool.getTime();
            this.time_Array.push((clickTime - this.timeStart));
            this.timeStart = cc.fx.GameTool.getTime();
            if (data == this.clickNow) {
                cc.fx.AudioManager._instance.playAudioButton();
                if (this.clickNow > 0) {
                    this.createLine(cc.v2(this.ball_Array[this.clickNow - 1].x, this.ball_Array[this.clickNow - 1].y), cc.v2(this.ball_Array[this.clickNow].x, this.ball_Array[this.clickNow].y), 0.2);
                }
                this.clickNow += 1;
                if (this.ball_Array[this.clickNow - 1])
                    this.ball_Array[this.clickNow - 1].getChildByName("guang").active = false;
                if (this.clickNow == this.now_Array.length) {
                    this.pause = true;
                    cc.fx.GameConfig.GM_INFO.total += this.clickNow;
                    this.overTime = cc.fx.GameTool.getTime();
                    if (this.startTime > 0 && this.overTime > 0) {
                        cc.fx.GameConfig.GM_INFO.mean_Time += (this.overTime - this.startTime);
                    }
                    var finish_time = parseInt((this.overTime - this.startTime) / 100 + "");
                    this.startTime = 0;
                    this.overTime = 0;
                    var color = "y";
                    if (this.level < 4 && this.level > 1)
                        color = "yr";
                    else if (this.level >= 4)
                        color = "yrb";
                    var win_1 = this.node.getChildByName("Win");
                    win_1.active = true;
                    win_1.setScale(0);
                    cc.fx.AudioManager._instance.playWin();
                    this.round += 1;
                    var sunArray = [];
                    if (this.moveArray.length > 0) {
                        for (var m = 0; m < this.moveArray.length; m++) {
                            if (m == this.repeat || m == this.numberRepeat) {
                                this.moveArray[m] = 2;
                            }
                            sunArray.push(this.moveArray[m]);
                        }
                    }
                    else {
                        for (var m = 0; m < this.ball_Array.length; m++) {
                            if (m == this.repeat || m == this.numberRepeat) {
                                sunArray.push(2);
                            }
                            else
                                sunArray.push(0);
                        }
                    }
                    cc.fx.GameConfig.CLICK_DATA =
                        {
                            type: 1,
                            success: true,
                            round: this.round,
                            totalSunCount: this.now_Array.length,
                            movedSunCount: cc.fx.GameConfig.LEVEL_INFO[this.level - 1].moveNumber,
                            sunSpeed: cc.fx.GameConfig.LEVEL_INFO[this.level - 1].moveSpeed,
                            overlapSunCount: cc.fx.GameConfig.LEVEL_INFO[this.level - 1].repeat,
                            colorList: this.color_Array,
                            duration: finish_time / 10,
                            difficultyLevel: this.level,
                            sunList: sunArray,
                            stepTimeList: this.time_Array,
                            remainder: this.countTime
                        };
                    if (cc.fx.GameConfig.CLICK_DATA.duration > 50) {
                        cc.fx.GameConfig.CLICK_DATA.duration = 50;
                    }
                    this.setData();
                    cc.tween(win_1)
                        .delay(0.4)
                        .to(0.01, { scale: 2.5 })
                        .to(0.35, { scale: 1 })
                        .delay(0.4)
                        .call(function () {
                        win_1.active = false;
                        _this.destroyLine();
                        if (_this.over == false && _this.countTime >= 0) {
                            if (_this.level >= 15) {
                                cc.fx.GameConfig.GM_INFO.success = true;
                                _this.level += 0;
                                // this.levelLabel.string = this.level + "";
                                _this.fuhuo = true;
                                _this.passLevel();
                            }
                            else {
                                _this.level += 1;
                                // this.levelLabel.string = this.level + "";
                                _this.fuhuo = true;
                                _this.passLevel();
                            }
                        }
                    })
                        .start();
                }
            }
            else {
                this.setLoss();
            }
        }
    };
    //执行失败
    GameManager.prototype.setLoss = function () {
        cc.fx.AudioManager._instance.playWarning();
        this.begin = false;
        this.overTime = cc.fx.GameTool.getTime();
        if (this.startTime > 0 && this.overTime > 0) {
            cc.fx.GameConfig.GM_INFO.mean_Time += (this.overTime - this.startTime);
        }
        var finish_time = parseInt((this.overTime - this.startTime) / 100 + "");
        if (finish_time > 58)
            finish_time = 58;
        this.startTime = 0;
        this.overTime = 0;
        var color = "y";
        if (this.level < 4 && this.level > 1)
            color = "yr";
        else if (this.level >= 4)
            color = "yrb";
        this.round += 1;
        var sunArray = [];
        if (this.moveArray.length > 0) {
            for (var m = 0; m < this.moveArray.length; m++) {
                if (m == this.repeat || m == this.numberRepeat) {
                    this.moveArray[m] = 2;
                }
                sunArray.push(this.moveArray[m]);
            }
        }
        else {
            for (var m = 0; m < this.ball_Array.length; m++) {
                if (m == this.repeat || m == this.numberRepeat) {
                    sunArray.push(2);
                }
                else
                    sunArray.push(0);
            }
        }
        cc.fx.GameConfig.CLICK_DATA =
            {
                type: 1,
                success: false,
                round: this.round,
                totalSunCount: this.now_Array.length,
                movedSunCount: cc.fx.GameConfig.LEVEL_INFO[this.level - 1].moveNumber,
                sunSpeed: cc.fx.GameConfig.LEVEL_INFO[this.level - 1].moveSpeed,
                overlapSunCount: cc.fx.GameConfig.LEVEL_INFO[this.level - 1].repeat,
                colorList: this.color_Array,
                duration: finish_time / 10,
                difficultyLevel: this.level,
                sunList: sunArray,
                stepTimeList: this.time_Array,
                remainder: this.countTime
            };
        if (cc.fx.GameConfig.CLICK_DATA.duration > 50) {
            cc.fx.GameConfig.CLICK_DATA.duration = 50;
        }
        this.setData();
        if (this.fuhuo == true) {
            this.fuhuo = false;
            this.loseLevel(1);
        }
        else {
            if (this.level > 2) {
                this.level -= 1;
                // this.levelLabel.string = this.level + "";
                this.fuhuo = true;
                // this.fuhuo = false;
                this.loseLevel(2);
            }
            else {
                this.loseLevel(1);
            }
        }
        var over = this.node.getChildByName("Over");
        cc.tween(over)
            .to(0.25, { opacity: 255 })
            .delay(0.1)
            .to(0.2, { opacity: 0 })
            .delay(0.1)
            .to(0.15, { opacity: 255 })
            .delay(0.1)
            .to(0.1, { opacity: 0 })
            .start();
    };
    //开始游戏
    GameManager.prototype.startGame = function () {
        if (this.over == false && this.countTime > 0) {
            this.pause = true;
            this.createSun();
            this.begin = false;
            cc.tween(this.ball)
                .to(0.5, { opacity: 255, scale: 1.3 })
                .start();
        }
    };
    //执行太阳运行动画，以及后面移动动画
    GameManager.prototype.runGame = function () {
        var _this = this;
        var time = -650;
        var _loop_3 = function (i) {
            time = this_2.now_Array[i].time * 1000 + time;
            setTimeout(function () {
                if (_this.over == false) {
                    var temp = _this.now_Array[i].timeCount;
                    if (temp > 0.5)
                        temp = 0.5;
                    if (i != 0) {
                        if (_this.ball && _this.now_Array[i]) {
                            _this.createLine(cc.v2(_this.ball.x, _this.ball.y), cc.v2(_this.now_Array[i].x, _this.now_Array[i].y), _this.now_Array[i].time - temp);
                        }
                    }
                    cc.tween(_this.ball)
                        .to(_this.now_Array[i].time - temp, { x: _this.now_Array[i].x, y: _this.now_Array[i].y })
                        .to(0.1, { scale: 1 })
                        .call(function () {
                        _this.createBall(i, _this.now_Array[i].color, _this.now_Array[i].speed, _this.now_Array[i].repeat);
                        if (i == _this.now_Array.length - 1) {
                            _this.ball.opacity = 0;
                            setTimeout(function () {
                                _this.destroyLine();
                                _this.beginGame();
                                if (cc.fx.GameConfig.LEVEL_INFO[_this.level - 1].moveNumber < 1) {
                                    _this.pause = false;
                                }
                                else {
                                    _this.moveAction();
                                }
                            }, 150);
                        }
                    })
                        .start();
                }
            }, time);
        };
        var this_2 = this;
        for (var i = 0; i < this.now_Array.length; i++) {
            _loop_3(i);
        }
    };
    //设置移动重叠数据
    GameManager.prototype.createMove = function () {
        var _this = this;
        if (this.over == false) {
            var info = cc.fx.GameConfig.LEVEL_INFO[this.level - 1];
            //改变移动速度
            var speed = 7;
            if (info.moveSpeed >= 2) {
                speed = 7 - info.moveSpeed / 2;
            }
            if (info.repeat == 1) {
                this.repeat = parseInt((Math.random() * (info.number - 1) + 1) + "");
                var tempNumber = 0;
                // this.repeat = 4;
                if (this.repeat > 4) {
                    this.numberRepeat = parseInt(Math.random() * 4 + "");
                    if (this.repeat == (info.number - 1)) //如果是最后一个 不能跟第一个重叠
                        this.numberRepeat = this.repeat - parseInt((Math.random() * 3 + 2) + "");
                    tempNumber = this.Pos_Array[this.numberRepeat];
                    this.Pos_Array[this.repeat] = tempNumber;
                }
                else { // 0 1 2 3 4 5 
                    // 6 - 3 - 1  = 2 4  01 4
                    if (this.repeat == 0)
                        this.repeat = 1;
                    if ((info.number - 1 - this.repeat) == 2) {
                        this.numberRepeat = info.number - 1;
                        tempNumber = this.Pos_Array[this.numberRepeat];
                    }
                    else if ((info.number - 1 - this.repeat) == 1) {
                        this.numberRepeat = this.repeat - 2;
                        tempNumber = this.Pos_Array[this.numberRepeat];
                    }
                    else if ((info.number - 1 - this.repeat) == 0) {
                        this.numberRepeat = this.repeat - 2;
                        tempNumber = this.Pos_Array[this.numberRepeat];
                    }
                    else if ((info.number - 1 - this.repeat) > 2) {
                        this.numberRepeat = parseInt(Math.random() * (info.number - this.repeat - 2) + "") + this.repeat + 2;
                        tempNumber = this.Pos_Array[this.numberRepeat];
                    }
                    else {
                        this.numberRepeat = this.repeat - 2;
                        tempNumber = this.Pos_Array[this.numberRepeat];
                    }
                    this.Pos_Array[this.repeat] = tempNumber;
                }
            }
            if (info.moveNumber > 0) {
                //0 1 2 3 4 5 6 7 8 9
                //可移动区分
                var pos_1 = cc.v2(0, 0);
                for (var z = 0; z < info.number; z++) {
                    this.moveArray[z] = 0;
                }
                for (var p = 0; p < info.moveNumber; p++) {
                    this.moveArray[info.number - 1 - p] = 1;
                }
                var timeOut = 0;
                //打乱可移动顺序
                this.moveArray.sort(function () { return Math.random() - 0.5; });
                if (this.moveArray[0] == 1) {
                    for (var r = info.number - 1; r >= 0; r--) {
                        if (this.moveArray[r] == 0) {
                            this.moveArray[r] = 1;
                            this.moveArray[0] = 0;
                            r = -1;
                        }
                    }
                }
                //将重叠的设置为不可移动  1 1 1 1 0 0 1 0 0 0   / 2 7
                for (var k = 0; k < this.moveArray.length; k++) {
                    if (this.moveArray[k] == 1 && (k == this.repeat || k == this.numberRepeat)) {
                        for (var m = this.moveArray.length - 1; m >= 0; m--) {
                            if (m != k && this.moveArray[m] == 0 && m != this.repeat && m != this.numberRepeat) {
                                this.moveArray[m] = 1;
                                this.moveArray[k] = 0;
                                m = -1;
                            }
                        }
                    }
                }
                var _loop_4 = function (i) {
                    if (this_3.moveArray[i] == 1) {
                        timeOut += 1;
                        setTimeout(function () {
                            pos_1 = _this.getPos2(true, i);
                            _this.Pos_Array[i] = pos_1;
                        }, timeOut * 300);
                    }
                };
                var this_3 = this;
                for (var i = 0; i < this.Pos_Array.length; i++) {
                    _loop_4(i);
                }
            }
        }
    };
    //移动后数据 重新刷一遍赋值
    GameManager.prototype.updateArray = function () {
        for (var i = 0; i < this.now_Array.length - 1; i++) {
            this.now_Array[i].x = this.Pos_Array[i].x;
            this.now_Array[i].y = this.Pos_Array[i].y;
        }
    };
    //太阳初始化后移动方法
    GameManager.prototype.moveAction = function () {
        var _this = this;
        this.updateArray();
        var moveArray = this.moveArray;
        var info = cc.fx.GameConfig.LEVEL_INFO[this.level - 1];
        //改变移动速度
        var speed = 7;
        if (info.moveSpeed >= 2) {
            speed = 7 - info.moveSpeed / 2;
        }
        if (info.moveNumber > 0) {
            //0 1 2 3 4 5 6 7 8 9
            //可移动区分
            //将重叠的设置为不可移动  1 1 1 1 0 0 1 0 0 0   / 2 7
            for (var k = 0; k < this.moveArray.length; k++) {
                if (this.moveArray[k] == 1 && (k == this.repeat || k == this.numberRepeat)) {
                    for (var m = this.moveArray.length - 1; m >= 0; m--) {
                        if (m != k && this.moveArray[m] == 0 && m != this.repeat && m != this.numberRepeat) {
                            this.moveArray[m] = 1;
                            this.moveArray[k] = 0;
                            m = -1;
                        }
                    }
                }
            }
            var lastNumber = 0;
            //锁定最后一个可移动的
            for (var j = 0; j < moveArray.length; j++) {
                if (moveArray[j] == 1) {
                    lastNumber = j;
                }
            }
            var _loop_5 = function (i) {
                if (moveArray[i] == 1) {
                    if (i != lastNumber) { //如果不是最后一个移动的
                        var time = speed * this_4.calculateDistance(this_4.ball_Array[i].x, this_4.ball_Array[i].y, this_4.Pos_Array[i].x, this_4.Pos_Array[i].y, 3);
                        this_4.ball_Array[i].getComponent("Sun").move = true;
                        cc.tween(this_4.ball_Array[i])
                            .to(time, { position: this_4.Pos_Array[i] })
                            .call(function () {
                            _this.ball_Array[i].getComponent("Sun").move = false;
                        })
                            .start();
                    }
                    //如果是最后一个
                    else {
                        var time = speed * this_4.calculateDistance(this_4.ball_Array[i].x, this_4.ball_Array[i].y, this_4.Pos_Array[i].x, this_4.Pos_Array[i].y, 3);
                        this_4.ball_Array[i].getComponent("Sun").move = true;
                        cc.tween(this_4.ball_Array[i])
                            .to(time, { position: this_4.Pos_Array[i] })
                            .call(function () {
                            _this.ball_Array[i].getComponent("Sun").move = false;
                        })
                            .start();
                    }
                }
            };
            var this_4 = this;
            for (var i = 0; i < this.ball_Array.length; i++) {
                _loop_5(i);
            }
        }
    };
    //每次重新开始新一轮儿游戏
    GameManager.prototype.beginGame = function () {
        this.begin = true;
        this.startTime = cc.fx.GameTool.getTime();
        this.timeStart = cc.fx.GameTool.getTime();
        this.pause = false;
        // this.node.getChildByName("showBtn").active = true;
    };
    //创建太阳所需数据
    GameManager.prototype.createSun = function () {
        var _this = this;
        var levelData = cc.fx.GameConfig.LEVEL_INFO[this.level - 1];
        var tiemOut = 0;
        var _loop_6 = function (l) {
            tiemOut += 1;
            setTimeout(function () {
                if (_this.over == false) {
                    var pos = _this.getPos(false, l);
                    _this.Pos_Array.push(pos);
                    if (_this.Pos_Array.length == levelData.number) {
                        _this.createMove();
                        _this.createPos();
                    }
                }
            }, tiemOut * 100);
        };
        for (var l = 0; l < levelData.number; l++) {
            _loop_6(l);
        }
    };
    //创建太阳位置，颜色信息等数据
    GameManager.prototype.createPos = function () {
        var data = { x: this.ball.x, y: this.ball.y, time: 0, timeCount: 0, color: 0, speed: 0, repeat: false };
        var levelData = cc.fx.GameConfig.LEVEL_INFO[this.level - 1];
        //颜色区分
        var colorArray = [0, 1];
        for (var j = 0; j < levelData.number - 2; j++) {
            var colorTemp = parseInt(Math.random() * 3 + "");
            if (levelData.number < 6 && colorTemp == 2)
                colorTemp = 0;
            colorArray.push(colorTemp);
            colorArray.sort(function () { return Math.random() - 0.5; });
        }
        colorArray.sort(function () { return Math.random() - 0.5; });
        if (levelData.number == 4)
            colorArray = [0, 0, 0, 0];
        this.color_Array = colorArray;
        //存储太阳数据
        for (var i = 0; i < levelData.number; i++) {
            var timeCount = this.timeCount + (0.6 - this.calculateDistance(this.ball.x, this.ball.y, this.Pos_Array[i].x, this.Pos_Array[i].y, 1));
            var time = this.calculateDistance(this.ball.x, this.ball.y, this.Pos_Array[i].x, this.Pos_Array[i].y, 1) + timeCount;
            data = { x: this.Pos_Array[i].x, y: this.Pos_Array[i].y, time: time, timeCount: timeCount, color: colorArray[i], speed: levelData.moveSpeed, repeat: false };
            if (this.repeat == i) {
                data.repeat = true;
            }
            else if (this.numberRepeat == i) {
                data.repeat = true;
            }
            this.now_Array.push(data);
        }
        this.runGame();
    };
    //获取，N个太阳位置的方法，和POS2分开两个方法，防止递归溢出
    GameManager.prototype.getPos = function (type, num) {
        var posX = Math.random() * 620 - 310;
        var posY = Math.random() * (this.fitTop - this.fitBot) + this.fitBot;
        var point = cc.v2(posX, posY);
        if (this.Pos_Array.length > 0) {
            for (var i = 0; i < this.Pos_Array.length; i++) {
                var distance = false;
                var pd = false;
                if (i == num)
                    pd = true;
                distance = this.getDistance(posX, posY, this.Pos_Array[i].x, this.Pos_Array[i].y, pd);
                if (distance == false) {
                    i = 10000;
                    point = this.getPos(type, num);
                }
                if (distance == true && i == (this.Pos_Array.length - 1)) {
                    i = 10000;
                }
            }
        }
        return point;
    };
    //获取，N个太阳可移动位置的方法，和POS分开算防止递归溢出
    GameManager.prototype.getPos2 = function (type, num) {
        var posX = Math.random() * 620 - 310;
        var posY = Math.random() * (this.fitTop - this.fitBot) + this.fitBot;
        var point = cc.v2(posX, posY);
        if (this.Pos_Array.length > 0) {
            for (var i = 0; i < this.Pos_Array.length; i++) {
                var distance = false;
                var pd = false;
                if (i == num)
                    pd = true;
                distance = this.getDistance2(posX, posY, this.Pos_Array[i].x, this.Pos_Array[i].y, pd);
                if (distance == false) {
                    i = 10000;
                    point = this.getPos2(type, num);
                }
                if (distance == true && i == (this.Pos_Array.length - 1)) {
                    i = 10000;
                }
            }
        }
        return point;
    };
    //获取两点之间距离，返回判断是否在一定范围内 将来提出到工具类
    GameManager.prototype.getDistance = function (x1, y1, x2, y2, num) {
        var jg = false;
        var dx = x2 - x1;
        var dy = y2 - y1;
        var distance = Math.sqrt(dx * dx + dy * dy);
        if (distance > 160) {
            if (num == true) {
                cc.fx.GameConfig;
                if (distance < cc.fx.GameConfig.LEVEL_INFO[this.level - 1].maxMove) {
                    jg = true;
                }
                else
                    jg = false;
            }
            else {
                if (distance < cc.fx.GameConfig.LEVEL_INFO[this.level - 1].maxMove) {
                    jg = true;
                }
                else
                    jg = false;
            }
        }
        return jg;
    };
    //命中动画
    GameManager.prototype.hitAction = function (data) {
        var _this = this;
        this.hit.active = true;
        this.hit.opacity = 0;
        this.hit.setPosition;
        this.hit.setPosition(this.ball_Array[data].x + 35, this.ball_Array[data].y + 35);
        cc.tween(this.hit)
            .to(0, { opacity: 255 })
            .to(0.2, { position: cc.v3(this.hit.x - 35, this.hit.y - 35, 0) })
            .delay(0.2)
            .to(0.1, { opacity: 0 })
            .call(function () {
            _this.hit.active = false;
        })
            .start();
    };
    //创造太阳
    GameManager.prototype.createBall = function (number, color, speed, repeat) {
        var ball = null;
        if (color == 0)
            ball = cc.instantiate(this.qiu1);
        else if (color == 1)
            ball = cc.instantiate(this.qiu2);
        else if (color == 2)
            ball = cc.instantiate(this.qiu3);
        ball.parent = this.node.getChildByName("Sun");
        ball.zIndex = this.now_Array.length - number;
        ball.setPosition(this.ball.x, this.ball.y);
        ball.getComponent("Sun").init(number, color, speed, repeat);
        this.ball_Array.push(ball);
    };
    //销毁连线
    GameManager.prototype.destroyLine = function () {
        for (var i = 0; i < this.node.getChildByName("Line").children.length; i++) {
            if (this.node.getChildByName("Line").children[i]) {
                this.node.getChildByName("Line").children[i].removeFromParent();
                this.node.getChildByName("Line").children[i] = null;
            }
        }
        this.node.getChildByName("Line").removeAllChildren();
    };
    //创建连线
    GameManager.prototype.createLine = function (start, end, time) {
        var line = cc.instantiate(this.linePrefab);
        line.parent = this.node.getChildByName("Line");
        line.setPosition(start.x, start.y);
        var dx = end.x - start.x;
        var dy = end.y - start.y;
        var distance = Math.sqrt(dx * dx + dy * dy);
        line.height = distance;
        line.getComponent(cc.Sprite).fillRange = 0;
        line.angle = -this.calculateAngle(start.x, start.y, end.x, end.y);
        cc.tween(line.getComponent(cc.Sprite))
            .to(time, { fillRange: 1 })
            .start();
    };
    //获取两点之间的角度，将来都可放工具类
    GameManager.prototype.calculateAngle = function (x1, y1, x2, y2) {
        var angle = Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI - 90;
        return -angle;
    };
    //获取两点之间的距离 返回对应时间
    GameManager.prototype.calculateDistance = function (x1, y1, x2, y2, num) {
        var dx = x2 - x1;
        var dy = y2 - y1;
        var time = 0;
        var distance = Math.sqrt(dx * dx + dy * dy);
        if (num == 1) {
            if (distance > 800)
                distance = 800;
            time = distance / 800 * 0.6;
        }
        else if (num == 2) {
            if (distance > 1200)
                distance = 1200;
            time = distance / 1200 * 1;
        }
        else if (num == 3) {
            if (distance > 1200)
                distance = 1200;
            time = distance / 1200 * 1.5;
        }
        return time;
    };
    //获取两点之间距离  返回距离判断
    GameManager.prototype.getDistance2 = function (x1, y1, x2, y2, num) {
        var jg = false;
        var dx = x2 - x1;
        var dy = y2 - y1;
        var distance = Math.sqrt(dx * dx + dy * dy);
        if (distance > 160) {
            if (num == true) {
                if (distance < cc.fx.GameConfig.LEVEL_INFO[this.level - 1].maxDistance)
                    jg = true;
                else
                    jg = false;
            }
            else {
                jg = true;
            }
        }
        return jg;
    };
    //背景移动
    GameManager.prototype.bgMove = function (type) {
        var _this = this;
        var random = Math.random() * 300 + 300;
        var posX = Math.random() * 600 - 300;
        var y1 = this.bg1.y - random * type;
        var time1 = 0.7 * (random / 400);
        cc.tween(this.ball)
            .to(0.3, { scale: 1.3 })
            .to(time1, { x: posX })
            .start();
        cc.tween(this.bg1)
            .delay(0.3)
            .to(time1, { y: y1 })
            .start();
        setTimeout(function () {
            if (_this.over == false)
                _this.startGame();
        }, time1 * 1500);
    };
    //如果是倒计时 调用此方法
    GameManager.prototype.updateCountDownTime = function () {
        if (this.countTime > 0 && this.pause == false) {
            this.countTime -= 1;
            this.time.string = cc.fx.GameTool.getTimeMargin(this.countTime);
            if (this.countTime < 5) {
                cc.tween(this.time.node)
                    .to(0.25, { scale: 1.5, color: cc.color(255, 0, 0) })
                    .to(0.25, { scale: 1, color: cc.color(255, 255, 255) })
                    .start();
                var over = this.node.getChildByName("Over");
                cc.tween(over)
                    .to(0.2, { opacity: 255 })
                    .delay(0.1)
                    .to(0.2, { opacity: 0 })
                    .start();
            }
            if (this.countTime <= 0) {
                this.begin = false;
                this.over = true;
                this.unschedule(this.updateCountDownTime);
                this.setLoss();
                var time = 0;
                if (this.clickCount > 0)
                    time = parseInt(cc.fx.GameConfig.GM_INFO.mean_Time / this.clickCount + "");
                cc.fx.GameConfig.GM_INFO.mean_Time = parseInt(time / 100 + "");
                cc.fx.GameConfig.GM_INFO.mean_Time = cc.fx.GameConfig.GM_INFO.mean_Time / 10;
                if (time > 10000)
                    time = (Math.random() * 10 + 5) * 100;
                this.gameOver(time);
            }
        }
    };
    //上传每次操作数据
    GameManager.prototype.setData = function () {
        cc.fx.GameTool.setGameData();
    };
    //上传排行榜数据
    GameManager.prototype.gameOver = function (time) {
        cc.fx.GameTool.setRank(time);
        this.node.getChildByName("GameOver").active = true;
        this.node.getChildByName("GameOver").opacity = 0;
        cc.tween(this.node.getChildByName("GameOver"))
            .to(0.4, { opacity: 255 })
            .delay(2)
            .to(0.4, { opacity: 50 })
            .call(function () {
            cc.director.loadScene("OverScene");
        })
            .start();
    };
    //作弊，测试用
    GameManager.prototype.showNumber = function () {
        if (this.show == false)
            this.show = true;
        else if (this.show == true)
            this.show = false;
        for (var i = 0; i < this.ball_Array.length; i++) {
            this.ball_Array[i].getComponent("Sun").showNumber(this.show);
        }
    };
    GameManager.prototype.onEnable = function () {
        cc.fx.Notifications.on("clickSun", this.clickSun, this);
    };
    GameManager.prototype.onDisable = function () {
        cc.fx.Notifications.off("clickSun", this.clickSun);
    };
    GameManager.prototype.update = function (dt) {
    };
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "ball", void 0);
    __decorate([
        property(cc.Prefab)
    ], GameManager.prototype, "qiu1", void 0);
    __decorate([
        property(cc.Prefab)
    ], GameManager.prototype, "qiu2", void 0);
    __decorate([
        property(cc.Prefab)
    ], GameManager.prototype, "qiu3", void 0);
    __decorate([
        property(cc.Prefab)
    ], GameManager.prototype, "linePrefab", void 0);
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "hit", void 0);
    __decorate([
        property(cc.Label)
    ], GameManager.prototype, "levelLabel", void 0);
    GameManager = __decorate([
        ccclass
    ], GameManager);
    return GameManager;
}(cc.Component));
exports.default = GameManager;

cc._RF.pop();