您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

120 行
2.0 KiB

  1. define([
  2. 'js/rendering/renderer',
  3. 'js/system/events'
  4. ], function (
  5. renderer,
  6. events
  7. ) {
  8. let round = Math.round.bind(Math);
  9. let maxPathLength = 50;
  10. return {
  11. type: 'pather',
  12. path: [],
  13. pathColor: '0x48edff',
  14. pathAlpha: 0.2,
  15. pathPos: {
  16. x: 0,
  17. y: 0
  18. },
  19. lastX: 0,
  20. lastY: 0,
  21. init: function () {
  22. events.on('onDeath', this.onDeath.bind(this));
  23. events.on('onClearQueue', this.onDeath.bind(this));
  24. this.pathPos.x = round(this.obj.x);
  25. this.pathPos.y = round(this.obj.y);
  26. },
  27. clearPath: function () {
  28. this.path.forEach(function (p) {
  29. renderer.destroyObject({
  30. layerName: 'effects',
  31. sprite: p.sprite
  32. });
  33. });
  34. this.path = [];
  35. },
  36. onDeath: function () {
  37. this.clearPath();
  38. this.pathPos.x = round(this.obj.x);
  39. this.pathPos.y = round(this.obj.y);
  40. },
  41. add: function (x, y) {
  42. if (this.path.length >= maxPathLength || this.obj.moveAnimation)
  43. return;
  44. pather.pathPos.x = x;
  45. pather.pathPos.y = y;
  46. this.path.push({
  47. x: x,
  48. y: y,
  49. sprite: renderer.buildRectangle({
  50. layerName: 'effects',
  51. color: this.pathColor,
  52. alpha: this.pathAlpha,
  53. x: (x * scale) + scaleMult,
  54. y: (y * scale) + scaleMult,
  55. w: scale - (scaleMult * 2),
  56. h: scale - (scaleMult * 2)
  57. })
  58. });
  59. client.request({
  60. cpn: 'player',
  61. method: 'move',
  62. priority: !this.path.length,
  63. data: {
  64. x: x,
  65. y: y
  66. }
  67. });
  68. },
  69. update: function () {
  70. if (this.obj.moveAnimation)
  71. this.clearPath();
  72. let x = this.obj.x;
  73. let y = this.obj.y;
  74. if (this.path.length === 0) {
  75. this.pathPos.x = round(x);
  76. this.pathPos.y = round(y);
  77. }
  78. if ((x === this.lastX) && (y === this.lastY))
  79. return;
  80. this.lastX = x;
  81. this.lastY = y;
  82. for (let i = 0; i < this.path.length; i++) {
  83. let p = this.path[i];
  84. if ((p.x === x) && (p.y === y)) {
  85. for (let j = 0; j <= i; j++) {
  86. renderer.destroyObject({
  87. layerName: 'effects',
  88. sprite: this.path[j].sprite
  89. });
  90. }
  91. this.path.splice(0, i + 1);
  92. return;
  93. }
  94. }
  95. }
  96. };
  97. });