"use strict";
cc._RF.push(module, '7fd74nqW4BCN6aFalN5nmyL', 'Player');
// Script/Player.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 GameManager_1 = require("./GameManager");
var AudioManager_1 = require("./tool/AudioManager");
var Notification_1 = require("./tool/Notification");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
0;
var NewClass = /** @class */ (function (_super) {
    __extends(NewClass, _super);
    function NewClass() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.add = null;
        _this.plist = null;
        return _this;
    }
    // LIFE-CYCLE CALLBACKS:
    // onLoad () {}
    NewClass.prototype.start = function () {
        this.init();
    };
    NewClass.prototype.init = function () {
        this.jumpState = 0;
        this.jumpHeight = this.node.y;
        this.basicHeight = this.node.y;
        this.up = true;
        this.double = false;
        this.death = false;
        this.jumpAction = null;
        this.block = null;
        this.interfere = false;
        this.jumpPause = true;
    };
    //跳动
    NewClass.prototype.jump = function () {
        var _this = this;
        if (this.jumpState < 2) {
            if (this.jumpState == 0) {
                if (this.death == false) {
                    this.node.getChildByName("sp").getComponent(sp.Skeleton).setAnimation(1, "jump", false);
                }
            }
            else if (this.jumpState == 1 || this.node.y > (this.jumpHeight + GameData_1.default._instance.GM_INFO.jumpHeight - 5)) {
                if (this.death == false) {
                    if (GameManager_1.default._instance.guide > 0 && GameManager_1.default._instance.guide < 3) {
                        return;
                    }
                    this.node.getChildByName("sp").getComponent(sp.Skeleton).setAnimation(1, "jump", false);
                }
            }
            setTimeout(function () {
                if (_this.jumpState == 0) {
                    if (_this.jumpPause == true) {
                        return;
                    }
                    if (_this.block) {
                        if (_this.block.name != "block13") {
                            _this.block.getComponent("Block").hide();
                        }
                        else {
                            _this.block.active = false;
                            _this.jumpPause = true;
                        }
                        _this.block = null;
                    }
                    if (GameManager_1.default._instance.guide == 1) {
                        GameManager_1.default._instance.guide = 2;
                        GameManager_1.default._instance.startGuide(2, false);
                    }
                    GameData_1.default._instance.CLICK_DATA.jumps = 1;
                    AudioManager_1.default._instance.playJump();
                    // this.basicHeight = this.node.y;
                    _this.jumpState += 1;
                    _this.up = true;
                    Notification_1.Notification.emit("showGround", _this.node.y);
                    _this.jumpAction = cc.tween(_this.node)
                        .to(GameData_1.default._instance.GM_INFO.jumpUpTime, { position: cc.v3(0, _this.jumpHeight + GameData_1.default._instance.GM_INFO.jumpHeight, 0) }, { easing: 'quadOut' })
                        .call(function () {
                        _this.up = false;
                        _this.jumpState = -1;
                        var temp = _this.node.y - _this.jumpHeight;
                    })
                        .to(GameData_1.default._instance.GM_INFO.jumpDownTime, { position: cc.v3(0, _this.jumpHeight, 0) }, { easing: 'cubicIn' })
                        .call(function () {
                        _this.jumpHeight = _this.node.y;
                        _this.jumpState = -1;
                        _this.up = true;
                    })
                        .start();
                }
                else if (_this.jumpState == 1 || _this.node.y > (_this.jumpHeight + GameData_1.default._instance.GM_INFO.jumpHeight - 15)) {
                    if (GameManager_1.default._instance.guide > 0 && GameManager_1.default._instance.guide < 3) {
                        return;
                    }
                    if (GameManager_1.default._instance.guide == 6) {
                        _this.jumpPause = true;
                        GameManager_1.default._instance.startGuide(6, false);
                    }
                    if (_this.jumpAction)
                        _this.jumpAction.stop();
                    AudioManager_1.default._instance.playJump();
                    GameData_1.default._instance.CLICK_DATA.jumps = 2;
                    _this.jumpState = 2;
                    _this.up = true;
                    _this.jumpAction = cc.tween(_this.node)
                        .to(GameData_1.default._instance.GM_INFO.jumpUpTime, { position: cc.v3(0, _this.node.y + GameData_1.default._instance.GM_INFO.jumpHeight, 0) }, { easing: 'quadOut' })
                        .call(function () {
                        _this.up = false;
                    })
                        .to(GameData_1.default._instance.GM_INFO.jumpDownTime * 1.5, { position: cc.v3(0, _this.jumpHeight, 0) }, { easing: 'cubicIn' })
                        .call(function () {
                        _this.jumpState = -1;
                        _this.jumpHeight = _this.node.y;
                        _this.up = true;
                    })
                        .start();
                }
            }, 100);
        }
    };
    NewClass.prototype.onCollisionEnter = function (other, self) {
        if (GameManager_1.default._instance) {
            if (GameManager_1.default._instance.over == true) {
                return;
            }
        }
        var max = other.name.length;
        var num = 6;
        if (other.node.name != "Ground") {
            if (GameManager_1.default._instance.guide == -1) {
                if (other.node.getComponent("Block").num > 9)
                    num = 7;
            }
            else {
                num = 7;
            }
        }
        var ColliderName = other.name.substring(num, max);
        //获取碰撞体名字
        if (ColliderName == "<PolygonCollider>") {
            if (this.node.y <= other.node.y && this.up == true && this.death == false) {
                if (this.jumpAction)
                    this.jumpAction.stop();
                this.jumpState = -1;
                AudioManager_1.default._instance.playGround();
                console.log("死亡1");
                this.gameDeath();
            }
            else if (other.node.name == "Ground" && this.death == false) {
                // if(this.jumpAction)this.jumpAction.stop();
                this.jumpState = -1;
                console.log("死亡2");
                this.gameDeath();
            }
            else {
                // console.log("没碰到边缘",this.up,this.node.y,other.node.y,this.jumpState,this.up);
            }
        }
        if (ColliderName == "<BoxCollider>") {
            if (this.death == true) {
                console.log("已经死亡");
                return;
            }
            //
            var portrait = Math.abs(this.node.y - other.node.y);
            var width = other.node.width / 2;
            var pos = Math.abs(this.node.x - other.node.x);
            var distance = pos / width;
            // console.log("我的位置:",this.node.x,"块的位置:",other.node.x,"块的宽度:",width,"百分比:",distance);
            if (this.up == true) {
                console.log("死亡4");
                AudioManager_1.default._instance.playGround();
                this.gameDeath();
            }
            else {
                if (distance * 100 < GameData_1.default._instance.GM_INFO.distanceMin && this.jumpState != 0) {
                    // console.log("成功1");
                    // console.log("百分比:",distance*100+"%");
                    this.success(other, distance * 100);
                }
                else {
                    if (portrait >= 20 || distance * 100 > GameData_1.default._instance.GM_INFO.distanceMax) {
                        console.log("死亡3", "落差:", portrait, "状态:", this.up);
                        AudioManager_1.default._instance.playGround();
                        this.gameDeath();
                    }
                    else {
                        // console.log("成功2");
                        console.log("百分比:", distance * 100 + "%");
                        this.success(other, distance * 100);
                    }
                }
            }
        }
    };
    NewClass.prototype.success = function (other, distance) {
        this.jumpPause = true;
        if (GameManager_1.default._instance.guide != -1) {
            this.basicHeight = this.node.y;
            other.node.stopAllActions();
            if (GameManager_1.default._instance.guide == 3 || GameManager_1.default._instance.guide == 4) {
                GameManager_1.default._instance.startGuide(4, false);
                if (GameManager_1.default._instance.guide == 4) {
                    GameManager_1.default._instance.guide = 5;
                }
            }
            else if (GameManager_1.default._instance.guide == 5) {
                this.jumpPause = true;
                var tip = GameManager_1.default._instance.Tip.getChildByName("good");
                cc.tween(tip)
                    .to(0.3, { opacity: 255, scale: 1 })
                    .delay(0.5)
                    .to(0.2, { opacity: 0 })
                    .call(function () {
                    GameManager_1.default._instance.startGuide(5, false);
                })
                    .start();
            }
            else if (GameManager_1.default._instance.guide == 7) {
                GameManager_1.default._instance.startGuide(8, false);
            }
            else if (GameManager_1.default._instance.guide == 8) {
                this.jumpPause = true;
                var tip = GameManager_1.default._instance.Tip.getChildByName("perfet");
                cc.tween(tip)
                    .to(0.3, { opacity: 255, scale: 1 })
                    .delay(0.5)
                    .to(0.2, { opacity: 0 })
                    .call(function () {
                    GameManager_1.default._instance.startGuide(9, false);
                })
                    .start();
            }
        }
        var percent = parseInt(distance * 10 + "") / 10;
        GameData_1.default._instance.CLICK_DATA.percent = percent;
        if (GameManager_1.default._instance)
            GameManager_1.default._instance.destroyBlock(true);
        this.add.active = true;
        this.add.opacity = 0;
        var number = 1;
        if (distance <= 10)
            number = 3;
        else if (distance <= 20)
            number = 2;
        GameData_1.default._instance.CLICK_DATA.accuracy = number;
        this.add.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.plist.getSpriteFrames()[number];
        this.add.getChildByName("jia").getComponent(cc.Sprite).spriteFrame = this.plist.getSpriteFrames()[number + 3];
        this.addAction();
        this.node.getChildByName("guang").active = true;
        this.node.getChildByName("guang").getComponent(sp.Skeleton).setAnimation(0, "double_1", false);
        if (this.jumpAction)
            this.jumpAction.stop();
        if (this.death == false) {
            this.node.getChildByName("sp").getComponent(sp.Skeleton).setAnimation(1, "jump", false);
        }
        this.basicHeight = this.node.y;
        if (number > 1) {
            AudioManager_1.default._instance.playPz();
            if (this.double == false) {
                this.double = true;
                GameData_1.default._instance.LEVEL_INFO.doubleHit = 1.05;
            }
            else {
                GameData_1.default._instance.LEVEL_INFO.doubleHit += GameData_1.default._instance.LEVEL_INFO.doubleAdd;
            }
            var combo = (GameData_1.default._instance.LEVEL_INFO.doubleHit - 1) * (1 / 0.05);
            GameData_1.default._instance.CLICK_DATA.combo = parseInt(combo + "");
        }
        else {
            AudioManager_1.default._instance.playLuo();
            this.double = false;
            GameData_1.default._instance.CLICK_DATA.combo = 0;
        }
        this.block = other.node;
        if (this.block.name != "block13") {
            this.block.getComponent("Block").setScore(number);
            Notification_1.Notification.emit("setData", null);
        }
        setTimeout(function () {
            if (GameManager_1.default._instance.guide == -1) {
                Notification_1.Notification.emit("createBlock", null);
                if (GameData_1.default._instance.LEVEL_INFO.doubleSuccess == 0) {
                    setTimeout(function () {
                        Notification_1.Notification.emit("createCrackBlock", null);
                    }, 100);
                }
            }
        }, 10);
        if (number > 1 && GameData_1.default._instance.LEVEL_INFO.doubleSuccess != 0) {
            GameData_1.default._instance.LEVEL_INFO.doubleSuccess -= 1;
        }
        else {
            if (GameData_1.default._instance.LEVEL_INFO.doubleSuccess != 0 && GameData_1.default._instance.LEVEL_INFO.doubleSuccess < 3) {
                GameData_1.default._instance.LEVEL_INFO.doubleSuccess = 3;
            }
        }
        if (GameData_1.default._instance.LEVEL_INFO.doubleSuccess == 0) {
        }
        else {
            GameManager_1.default._instance.interfere = false;
            GameData_1.default._instance.CLICK_DATA.fake = GameManager_1.default._instance.interfere;
        }
        this.jumpState = 0;
        this.up = true;
        this.node.y = other.node.y - 3 + other.node.height / 2;
        this.jumpHeight = this.node.y;
    };
    NewClass.prototype.gameDeath = function () {
        // console.log("条失败");
        this.jumpPause = true;
        if (!GameData_1.default._instance.GM_INFO.probation) {
            GameData_1.default._instance.CLICK_DATA.combo = 0;
            GameData_1.default._instance.CLICK_DATA.accuracy = 0;
            GameData_1.default._instance.CLICK_DATA.percent = -1;
            Notification_1.Notification.emit("setData", null);
            this.double = false;
            GameData_1.default._instance.LEVEL_INFO.doubleSuccess = 3;
            this.death = true;
            if (this.jumpAction)
                this.jumpAction.stop();
            this.jumpState = -1;
            Notification_1.Notification.emit("death", false);
        }
        else {
            this.death = true;
            if (GameManager_1.default._instance.guide == 6) {
                GameManager_1.default._instance.tipHide("tip4", null);
            }
            if (this.jumpAction)
                this.jumpAction.stop();
            this.jumpState = -1;
            Notification_1.Notification.emit("death", true);
        }
    };
    NewClass.prototype.xinAction = function () {
        if (GameData_1.default._instance.GM_INFO.life >= 0) {
            var xin = this.node.getChildByName("xin");
            xin.y = 120;
            cc.tween(xin)
                .to(0.2, { opacity: 255, y: xin.y + 50 })
                .delay(0.5)
                .to(0.3, { opacity: 0, y: xin.y + 100 })
                .call(function () {
            })
                .start();
        }
    };
    NewClass.prototype.addAction = function () {
        var _this = this;
        this.add.y = 120;
        cc.tween(this.add)
            .to(0.2, { opacity: 255, y: this.add.y + 50 })
            .delay(0.5)
            .to(0.3, { opacity: 0, y: this.add.y + 100 })
            .call(function () {
            _this.add.active = false;
        })
            .start();
    };
    NewClass.prototype.update = function (dt) {
        // if(this.death == true && this.node.y > -500 && GameManager._instance.over == false){
        //     // this.node.y -= 3;
        //     // if(this.node.y <= -500){
        //     //     this.node.y = -500;
        //     // } 
        // }
    };
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "add", void 0);
    __decorate([
        property(cc.SpriteAtlas)
    ], NewClass.prototype, "plist", void 0);
    NewClass = __decorate([
        ccclass
    ], NewClass);
    return NewClass;
}(cc.Component));
exports.default = NewClass;

cc._RF.pop();