"use strict";
cc._RF.push(module, 'bbcb1nm5dBMPapiV+lYynqt', 'GuideManager');
// Script/GuideManager.ts

"use strict";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
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 GameData_1 = require("./GameData");
var Notification_1 = require("./tool/Notification");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GuideManager = /** @class */ (function (_super) {
    __extends(GuideManager, _super);
    function GuideManager() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.Camera = null;
        _this.topUI = null;
        _this.Player = null;
        _this.Ground = null;
        _this.Xin = null;
        _this.time = null;
        _this.Tip = null;
        _this.blockPrefab = [];
        return _this;
        // update (dt) {}
    }
    // LIFE-CYCLE CALLBACKS:
    GuideManager.prototype.onLoad = function () {
        // 示例使用
        var manager = cc.director.getCollisionManager();
        manager.enabled = true;
        GameData_1.default._instance.GM_INFO.probation = true;
    };
    GuideManager.prototype.onEnable = function () {
        Notification_1.Notification.on("createBlock", this.createBlock, this);
        Notification_1.Notification.on("addScore", this.addScore, this);
        Notification_1.Notification.on("createCrackBlock", this.createCrackBlock, this);
        Notification_1.Notification.on("showGround", this.showGround, this);
        Notification_1.Notification.on("death", this.getDeath, this);
        Notification_1.Notification.on("jump", this.jump, this);
    };
    GuideManager.prototype.onDestroy = function () {
        Notification_1.Notification.off("createBlock", this.createBlock);
        Notification_1.Notification.off("addScore", this.addScore);
        Notification_1.Notification.off("createBlock", this.createCrackBlock);
        Notification_1.Notification.off("death", this.getDeath);
        Notification_1.Notification.off("jump", this.jump);
        Notification_1.Notification.off("showGround", this.showGround);
    };
    GuideManager.prototype.init = function () {
        this.score = 0;
        this.oldSpeed = 10;
        this.begin = true;
        this.over = false;
        this.interfere = false;
        this.round = 0;
        this.level = 0;
        GameData_1.default._instance.GM_INFO.levelMax = 1;
        GameData_1.default._instance.GM_INFO.difficultyMax = 1;
        GameData_1.default._instance.GM_INFO.life = 3;
        this.blockArray = [];
        this.cameraMove = false;
        this.countTime = 12;
        this.topUI.getChildByName("xin1").active = true;
        this.topUI.getChildByName("xin2").active = true;
        this.topUI.getChildByName("xin3").active = true;
        this.topUI.getChildByName("star1").active = false;
        this.topUI.getChildByName("star2").active = false;
        this.topUI.getChildByName("star3").active = false;
        GameData_1.default._instance.LEVEL_init();
    };
    GuideManager.prototype.start = function () {
        // this.node.on(cc.Node.EventType.TOUCH_START, this.jump, this);
        this.fit();
        this.init();
        this.startGuide();
        this.startGame();
    };
    //根据是否全面屏，做独立适配方面
    GuideManager.prototype.fit = function () {
        this.node.getChildByName("bg2").y = -2167.675;
        var jg = this.setFit();
        if (!jg) {
            this.node.getChildByName("bg2").y = -2100;
        }
    };
    //判断全面屏
    GuideManager.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;
    };
    //判断全面屏适配
    GuideManager.prototype.setFit = function () {
        var flag = this.getSetScreenResolutionFlag();
        if (flag) {
        }
        else {
        }
        return flag;
    };
    GuideManager.prototype.startGuide = function () {
        //打开卷
        var left = this.Tip.getChildByName("left");
        var right = this.Tip.getChildByName("right");
        var tip = this.Tip.getChildByName("tip");
        left.width = 0;
        right.width = 0;
        tip.opacity = 0;
        cc.tween(left)
            .to(0.25, { width: 348 })
            .start();
        cc.tween(right)
            .to(0.25, { width: 348 })
            .start();
        cc.tween(tip)
            .delay(0.15)
            .to(0.15, { opacity: 255 })
            .start();
    };
    GuideManager.prototype.showGround = function (tempY) {
        var _this = this;
        setTimeout(function () {
            _this.Ground.active = true;
            _this.Ground.y = tempY;
        }, 500);
    };
    GuideManager.prototype.jump = function () {
        this.Player.getComponent("Player").jump();
    };
    GuideManager.prototype.startGame = function () {
        this.createBlock();
    };
    GuideManager.prototype.addScore = function (score) {
    };
    GuideManager.prototype.createBlock = function () {
        if (this.over == false && this.begin == true) {
            this.Ground.active = false;
            var num = Math.floor(Math.random() * 12);
            if (this.round <= 10 && num == 5) {
                num = Math.floor(Math.random() * 6 + 6);
            }
            // num = 2;
            var block = cc.instantiate(this.blockPrefab[num]);
            var height = this.Player.getComponent("Player").basicHeight + GameData_1.default._instance.GM_INFO.blockMin;
            if (num > GameData_1.default._instance.GM_INFO.blockScale) {
                height += block.height + GameData_1.default._instance.GM_INFO.blockMax;
                GameData_1.default._instance.CLICK_DATA.height = true;
            }
            if (height >= -120 && this.cameraMove == false) {
                this.countHeight = this.Player.getComponent("Player").basicHeight - this.Camera.node.y;
                this.cameraMove = true;
            }
            block.setPosition(cc.v2(this.round % 2 == 0 ? 500 : -500, height));
            block.parent = this.node.getChildByName("Block");
            this.round += 1;
            this.level += 1;
            if (this.round > GameData_1.default._instance.GM_INFO.levelMax)
                GameData_1.default._instance.GM_INFO.levelMax = this.round;
            GameData_1.default._instance.CLICK_DATA.level = this.round;
            GameData_1.default._instance.CLICK_DATA.round = this.level;
            GameData_1.default._instance.LEVEL_INFO.layer += GameData_1.default._instance.LEVEL_INFO.layerAdd;
            GameData_1.default._instance.LEVEL_INFO.speed += GameData_1.default._instance.LEVEL_INFO.addSpeed;
            if (GameData_1.default._instance.LEVEL_INFO.reduceSpeed <= 100)
                GameData_1.default._instance.LEVEL_INFO.reduceSpeed += GameData_1.default._instance.LEVEL_INFO.jiansu;
            if (this.round == GameData_1.default._instance.LEVEL_INFO.round1)
                GameData_1.default._instance.LEVEL_INFO.jiansu = 2;
            else if (this.round == GameData_1.default._instance.LEVEL_INFO.round2)
                GameData_1.default._instance.LEVEL_INFO.jiansu = 1;
            else if (this.round == GameData_1.default._instance.LEVEL_INFO.round3)
                GameData_1.default._instance.LEVEL_INFO.jiansu = 0.5;
        }
    };
    //虚假碎裂块
    GuideManager.prototype.createCrackBlock = function () {
        this.interfere = true;
        GameData_1.default._instance.CLICK_DATA.fake = this.interfere;
        if (this.round > 1)
            this.destroyBlock();
        if (this.over == false && this.begin == true) {
            var block = cc.instantiate(this.blockPrefab[12]);
            var height = this.Player.getComponent("Player").basicHeight;
            if (GameData_1.default._instance.CLICK_DATA.height == true) {
                height += block.height / 2;
            }
            block.setPosition(cc.v2(this.round % 2 == 0 ? 500 : -500, height));
            block.parent = this.node.getChildByName("CrackBlock");
        }
    };
    GuideManager.prototype.destroyBlock = function () {
        if (this.node) {
            if (this.node.getChildByName("CrackBlock")) {
                if (this.node.getChildByName("CrackBlock").children) {
                    var block2 = this.node.getChildByName("CrackBlock").children;
                    for (var i = 0; i < block2.length; i++) {
                        if (block2[i]) {
                            block2[i].getComponent("Block").hide();
                        }
                    }
                }
            }
        }
    };
    GuideManager.prototype.xinAction = function () {
    };
    //死亡
    GuideManager.prototype.getDeath = function () {
        this.getDevive(1);
    };
    //复活
    GuideManager.prototype.getDevive = function (time) {
        var _this = this;
        this.round = 0;
        GameData_1.default._instance.LEVEL_init();
        if (this.topUI.getChildByName("star3").active == true) {
            // GameData._instance.LEVEL_INFO.scoreMax = 150000;
        }
        this.interfere = false;
        GameData_1.default._instance.CLICK_DATA.fake = this.interfere;
        var block = this.node.getChildByName("Block").children;
        for (var i = 0; i < block.length; i++) {
            if (block[i]) {
                block[i].getComponent("Block").hide();
            }
        }
        var block2 = this.node.getChildByName("CrackBlock").children;
        for (var i = 0; i < block2.length; i++) {
            if (block2[i]) {
                block2[i].getComponent("Block").hide();
            }
        }
        // this.blockArray = [];
        var actionTime = 0.5;
        if (this.Player.y > 500) {
            actionTime = (this.Player.y + 500) / 1000 * actionTime;
        }
        cc.tween(this.Player)
            .to(actionTime, { position: cc.v3(0, -500, 0) })
            .call(function () {
            _this.Player.getComponent("Player").xinAction();
        })
            .delay(0.5)
            .call(function () {
            _this.xinAction();
            _this.Player.getComponent("Player").init();
            if (time > 1) {
                _this.Xin.parent.active = true;
                _this.Xin.getComponent(cc.Sprite).fillRange = 0;
                cc.tween(_this.Xin.getComponent(cc.Sprite))
                    .to(time, { fillRange: 1 })
                    .delay(0.3)
                    .call(function () {
                    _this.Xin.parent.active = false;
                })
                    .delay(0)
                    .call(function () {
                    _this.createBlock();
                })
                    .start();
            }
            else {
                setTimeout(function () {
                    _this.createBlock();
                }, (time + 0.5) * 1000);
            }
        })
            .start();
    };
    __decorate([
        property(cc.Camera)
    ], GuideManager.prototype, "Camera", void 0);
    __decorate([
        property(cc.Node)
    ], GuideManager.prototype, "topUI", void 0);
    __decorate([
        property(cc.Node)
    ], GuideManager.prototype, "Player", void 0);
    __decorate([
        property(cc.Node)
    ], GuideManager.prototype, "Ground", void 0);
    __decorate([
        property(cc.Node)
    ], GuideManager.prototype, "Xin", void 0);
    __decorate([
        property(cc.Label)
    ], GuideManager.prototype, "time", void 0);
    __decorate([
        property(cc.Node)
    ], GuideManager.prototype, "Tip", void 0);
    __decorate([
        property([cc.Prefab])
    ], GuideManager.prototype, "blockPrefab", void 0);
    GuideManager = __decorate([
        ccclass
    ], GuideManager);
    return GuideManager;
}(cc.Component));
exports.default = GuideManager;

cc._RF.pop();