bbc1638b-508c-413c-82cb-1d99f122caab.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. "use strict";
  2. cc._RF.push(module, 'bbc16OLUIxBPILLHZnxIsqr', 'mb');
  3. // scripts/Game/mb.ts
  4. "use strict";
  5. // Learn TypeScript:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  7. // Learn Attribute:
  8. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  9. // Learn life-cycle callbacks:
  10. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  11. var __extends = (this && this.__extends) || (function () {
  12. var extendStatics = function (d, b) {
  13. extendStatics = Object.setPrototypeOf ||
  14. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  15. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  16. return extendStatics(d, b);
  17. };
  18. return function (d, b) {
  19. extendStatics(d, b);
  20. function __() { this.constructor = d; }
  21. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  22. };
  23. })();
  24. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  25. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  26. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  27. 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;
  28. return c > 3 && r && Object.defineProperty(target, key, r), r;
  29. };
  30. Object.defineProperty(exports, "__esModule", { value: true });
  31. var CocosZ_1 = require("../Framework/CocosZ");
  32. var Constant_1 = require("../Framework/Constant");
  33. var gameMgr_1 = require("./gameMgr");
  34. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  35. var MB = /** @class */ (function (_super) {
  36. __extends(MB, _super);
  37. function MB() {
  38. var _this = _super !== null && _super.apply(this, arguments) || this;
  39. _this.clip = null;
  40. _this._spAni = null;
  41. _this.time = -1;
  42. _this.isAtk = false;
  43. _this.isHart = false;
  44. _this.canChangeState = true;
  45. return _this;
  46. }
  47. MB.prototype.onLoad = function () {
  48. // spine动画
  49. this._spAni = this.node.getChildByName("ani").getComponent(sp.Skeleton);
  50. };
  51. MB.prototype.start = function () {
  52. this.node.zIndex = Constant_1.ZindexLayer.zindex_mb;
  53. this._spAni.setAnimation(0, "daiji", false);
  54. };
  55. MB.prototype.update = function (dt) {
  56. if (CocosZ_1.cocosz.isPause || !gameMgr_1.gameMgr.isGameStart || gameMgr_1.gameMgr.isWin || gameMgr_1.gameMgr.isFail) {
  57. return;
  58. }
  59. if (++this.time % 15 == 0) {
  60. if (gameMgr_1.gameMgr && gameMgr_1.gameMgr.playerTs && gameMgr_1.gameMgr.playerTs.isDeath == false) {
  61. var p1 = this.node.getPosition();
  62. var p2 = gameMgr_1.gameMgr.playerTs.node.getPosition();
  63. var dis = p1.subSelf(p2).mag();
  64. if (dis < 400) {
  65. this.atkStart();
  66. if (dis < 300) {
  67. this.atkEnemy();
  68. }
  69. }
  70. else {
  71. this.atkEnd();
  72. }
  73. }
  74. else {
  75. this.atkEnd();
  76. }
  77. }
  78. };
  79. MB.prototype.atkEnemy = function () {
  80. if (this.isHart && gameMgr_1.gameMgr && gameMgr_1.gameMgr.playerTs) {
  81. gameMgr_1.gameMgr.playerTs.hart(1, null);
  82. }
  83. };
  84. MB.prototype.atkStart = function () {
  85. var _this = this;
  86. if (this.canChangeState && this.isAtk == false) {
  87. this.canChangeState = false;
  88. this.isAtk = true;
  89. this.node.stopAllActions();
  90. cc.tween(this.node)
  91. .call(function () {
  92. _this._spAni.setAnimation(0, "doudong", true);
  93. })
  94. .delay(0.5)
  95. .call(function () {
  96. if (_this.clip && _this.clip.isValid)
  97. gameMgr_1.gameMgr.playClip(_this.clip, _this.node);
  98. _this._spAni.setAnimation(0, "zheng", false);
  99. _this._spAni.addAnimation(0, "zheng2", true);
  100. _this.isHart = true;
  101. })
  102. .delay(3)
  103. .call(function () {
  104. _this.canChangeState = true;
  105. })
  106. .start();
  107. }
  108. };
  109. MB.prototype.atkEnd = function () {
  110. if (this.canChangeState && this.isAtk == true) {
  111. this.isAtk = false;
  112. this.isHart = false;
  113. this._spAni.setAnimation(0, "daiji", false);
  114. }
  115. };
  116. __decorate([
  117. property({ type: cc.AudioClip, tooltip: "音效" })
  118. ], MB.prototype, "clip", void 0);
  119. MB = __decorate([
  120. ccclass
  121. ], MB);
  122. return MB;
  123. }(cc.Component));
  124. exports.default = MB;
  125. cc._RF.pop();