Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

122 wiersze
2.1 KiB

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