You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

102 regels
1.7 KiB

  1. define([
  2. 'js/renderer',
  3. 'js/system/events'
  4. ], function(
  5. renderer,
  6. events
  7. ) {
  8. var scale = 40;
  9. var scaleMult = 5;
  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 = this.obj.x;
  25. this.pathPos.y = this.obj.y;
  26. },
  27. onDeath: function() {
  28. this.path.forEach(function(p) {
  29. renderer.destroyObject({
  30. layerName: 'effects',
  31. sprite: p.sprite
  32. });
  33. });
  34. this.path = [];
  35. this.pathPos.x = this.obj.x;
  36. this.pathPos.y = this.obj.y;
  37. },
  38. add: function(x, y) {
  39. this.path.push({
  40. x: x,
  41. y: y,
  42. sprite: renderer.buildRectangle({
  43. layerName: 'effects',
  44. color: this.pathColor,
  45. alpha: this.pathAlpha,
  46. x: (x * scale) + scaleMult,
  47. y: (y * scale) + scaleMult,
  48. w: scale - (scaleMult * 2),
  49. h: scale - (scaleMult * 2)
  50. })
  51. });
  52. },
  53. update: function() {
  54. var x = this.obj.x;
  55. var y = this.obj.y;
  56. if (this.path.length == 0) {
  57. this.pathPos.x = x;
  58. this.pathPos.y = y;
  59. }
  60. if ((x == this.lastX) && (y == this.lastY))
  61. return;
  62. this.lastX = x;
  63. this.lastY = y;
  64. for (var i = 0; i < this.path.length; i++) {
  65. var p = this.path[i];
  66. if ((p.x == x) && (p.y == y)) {
  67. for (var j = 0; j <= i; j++) {
  68. renderer.destroyObject({
  69. layerName: 'effects',
  70. sprite: this.path[j].sprite
  71. });
  72. }
  73. this.path.splice(0, i + 1);
  74. return;
  75. }
  76. }
  77. },
  78. setPath: function(path) {
  79. this.path = this.path.concat(path);
  80. this.pathPos.x = path[path.length - 1].x;
  81. this.pathPos.y = path[path.length - 1].y;
  82. }
  83. };
  84. });