ShockUtils.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0});
  5. const s = t("App");
  6. i.default = class {
  7. constructor() {
  8. (this.MAP = 0),
  9. (this.SPRITE = 1),
  10. (this.mapPoss = [new cc.Vec2(0, 3), new cc.Vec2(0, 0), new cc.Vec2(0, -2)]),
  11. (this.spritePoss = [new cc.Vec2(5, -5), new cc.Vec2(-5, 5), new cc.Vec2(5, 0)]),
  12. (this._shockLength = 0),
  13. (this._shockCount = 0),
  14. (this._rx = 0),
  15. (this._ry = 0),
  16. (this._type = 0),
  17. (this._repeatCount = 0);
  18. }
  19. destroy() {
  20. this.stop();
  21. }
  22. shock(t = 0, e = null, i = 3) {
  23. this._target ||
  24. ((this._type = t),
  25. (this._target = e),
  26. this._type == this.MAP
  27. ? ((this._shockPoss = this.mapPoss.concat()), (this._shockLength = this._shockPoss.length))
  28. : this._type == this.SPRITE &&
  29. ((this._shockPoss = this.spritePoss.concat()), (this._shockLength = this._shockPoss.length)),
  30. this.start(i));
  31. }
  32. start(t = 1) {
  33. (this.repeatCount = t),
  34. (this._shockCount = 0),
  35. this._target &&
  36. (this._type != this.MAP && (this._rx = this._target.x),
  37. (this._ry = this._target.y),
  38. s.default.TimerManager.doFrame(1, 0, this.onShockEnter, this));
  39. }
  40. stop() {
  41. this._target &&
  42. (this._type != this.MAP && (this._target.x = this._rx),
  43. (this._target.y = this._ry),
  44. s.default.TimerManager.remove(this.onShockEnter, this)),
  45. (this._target = null);
  46. }
  47. onShockEnter(t) {
  48. var e = this._shockLength * this._repeatCount;
  49. this._shockCount >= e
  50. ? this.stop()
  51. : ((e = this._shockCount % this._shockLength),
  52. (e = this._shockPoss[e]),
  53. this._target &&
  54. (this._type != this.MAP && (this._target.x = this._rx + e.x), (this._target.y = this._ry + e.y)),
  55. this._shockCount++);
  56. }
  57. get repeatCount() {
  58. return this._repeatCount;
  59. }
  60. set repeatCount(t) {
  61. this._repeatCount = t;
  62. }
  63. };