"use strict";
cc._RF.push(module, 'bd769BizYREq7pMZmW+fkhf', 'Playcontroler');
// Script/Playcontroler.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 Global_1 = require("./Global");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var Playcontroler = /** @class */ (function (_super) {
    __extends(Playcontroler, _super);
    function Playcontroler() {
        // LIFE-CYCLE CALLBACKS:
        var _this = _super !== null && _super.apply(this, arguments) || this;
        // parent:cc.Node = null;
        _this.MainScene = null;
        return _this;
    }
    Playcontroler.prototype.onLoad = function () {
        // this.parent = this.node.parent;
        this.MainScene = Global_1.default.instance.getMN();
    };
    Playcontroler.prototype.start = function () {
    };
    Playcontroler.prototype.update = function (dt) {
        if (Global_1.default.instance.OverFlag) {
            this.enabled = false;
        }
        else {
            if (!Global_1.default.instance.CollisionFlag) {
                this.node.y -= Global_1.default.instance.InitSpeed;
            }
            else {
                var name = Global_1.default.instance.TheHolder.name;
                if (name == "") {
                    return;
                }
                this.node.y = Global_1.default.instance.TheHolder.y
                    + Global_1.default.instance.TheHolder.getComponent(name).NodeH - 10; //here ,this way isnot a good Processing method,should be optimizated
            }
        }
        if (Global_1.default.instance.CollisionWithDing) {
            this.node.stopAllActions();
            Global_1.default.instance.CollisionWithDing = false;
            Global_1.default.instance.CollisionFlag = false;
        }
    };
    /**
     * player与墙壁的碰撞检测
     * @param other 被撞物体
     * @param self 碰撞体
     */
    Playcontroler.prototype.onCollisionEnter = function (other, self) {
        var rootSelf = this;
        switch (other.node.name) {
            case "Bg_0CollisionR": {
                self.node.x = 180;
                break;
            }
            case "Bg_0CollisionL": {
                self.node.x = -180;
                break;
            }
            case "Bg_1CollisionR": {
                self.node.x = 180;
                break;
            }
            case "Bg_1CollisionL": {
                self.node.x = -180;
                break;
            }
            // case "tanhuang":{
            //     if(other.node.x+75>self.node.x&&other.node.x-75<self.node.x){
            //         let main = Global.instance.getMN();
            //         main.getChildByName("output").getComponent(cc.Label).string = "tanhuang";
            //     }
            // }
            case "ding": {
                Global_1.default.instance.CollisionWithDing = true;
                self.node.stopAllActions();
                rootSelf.LifeZero();
                Global_1.default.instance.CollisionFlag = false;
                self.node.getComponent(cc.BoxCollider).enabled = false;
                rootSelf.scheduleOnce(function (err) {
                    self.node.getComponent(cc.BoxCollider).enabled = true;
                }, 0.3);
                break;
            }
            default: {
                // this.MainScene.getComponent("MainScene").Score();//得分
                break;
            }
        }
    };
    Playcontroler.prototype.LifeZero = function () {
        var main = Global_1.default.instance.getMN();
        var lifeChil = main.getChildByName("BgNode").getChildByName("LifeDing").children;
        var life = new Array();
        var lifeNum = 0;
        for (var i = 0; i < lifeChil.length; i++) {
            if (lifeChil[i].name == "lifeBG") {
                life.push(lifeChil[i]);
            }
        }
        for (var i = 0; i < life.length; i++) {
            if (life[i].active) {
                lifeNum++;
            }
        }
        if (lifeNum == 0) {
            return;
        }
    };
    Playcontroler = __decorate([
        ccclass
    ], Playcontroler);
    return Playcontroler;
}(cc.Component));
exports.default = Playcontroler;
/**
 * 1.下落速度加快；
 * 2.玻璃：先停一会在碎掉；
 * 3.传送带速度快一点；
 * 4.
 */ 

cc._RF.pop();