Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

105 linhas
2.4 KiB

  1. define([
  2. 'js/rendering/renderer',
  3. 'picture'
  4. ], function (
  5. renderer,
  6. picture
  7. ) {
  8. return {
  9. type: 'lightPatch',
  10. color: 'f7ffb2',
  11. patches: [],
  12. rays: [],
  13. init: function (blueprint) {
  14. this.blueprint = this.blueprint || {};
  15. let obj = this.obj;
  16. let x = obj.x;
  17. let y = obj.y;
  18. let maxDistance = Math.sqrt(Math.pow(obj.width / 2, 2) + Math.pow(obj.height / 2, 2));
  19. for (let i = 0; i < obj.width; i++) {
  20. for (let j = 0; j < obj.height; j++) {
  21. let distance = maxDistance - Math.sqrt(Math.pow((obj.width / 2) - i, 2) + Math.pow((obj.width / 2) - i, 2));
  22. let alpha = distance / maxDistance;
  23. let sprite = renderer.buildObject({
  24. x: (x + i),
  25. y: (y + j),
  26. sheetName: 'white',
  27. cell: 0,
  28. layerName: 'lightPatches'
  29. });
  30. sprite.alpha = (0.2 + (Math.random() * 1)) * alpha;
  31. sprite.tint = '0x' + this.color;
  32. sprite.blendMode = PIXI.BLEND_MODES.OVERLAY;
  33. sprite.pluginName = 'picture';
  34. this.patches.push(sprite);
  35. }
  36. }
  37. let rCount = ((obj.width * obj.height) / 10) + ~~(Math.random() + 2);
  38. for (let i = 0; i < rCount; i++) {
  39. let nx = x + 3 + ~~(Math.random() * (obj.width - 1));
  40. let ny = y - 4 + ~~(Math.random() * (obj.height));
  41. let w = 1 + ~~(Math.random() * 2);
  42. let h = 6 + ~~(Math.random() * 13);
  43. let hm = 2;
  44. let rContainer = renderer.buildContainer({
  45. layerName: 'lightBeams'
  46. });
  47. this.rays.push(rContainer);
  48. for (let j = 0; j < h; j++) {
  49. let ray = renderer.buildObject({
  50. x: nx,
  51. y: ny,
  52. cell: 0,
  53. sheetName: 'white',
  54. parent: rContainer
  55. });
  56. ray.x = ~~((nx * scale) - (scaleMult * j));
  57. ray.y = (ny * scale) + (scaleMult * j * hm);
  58. ray.alpha = ((1.0 - (j / h)) * 0.4);
  59. ray.width = w * scaleMult;
  60. ray.height = scaleMult * hm;
  61. ray.tint = 0xffeb38;
  62. ray.blendMode = PIXI.BLEND_MODES.ADD;
  63. }
  64. }
  65. },
  66. update: function () {
  67. let rays = this.rays;
  68. let rLen = rays.length;
  69. for (let i = 0; i < rLen; i++) {
  70. let r = rays[i];
  71. r.alpha += (Math.random() * 0.03) - 0.015;
  72. if (r.alpha < 0.3)
  73. r.alpha = 0.3;
  74. else if (r.alpha > 1)
  75. r.alpha = 1;
  76. }
  77. },
  78. destroy: function () {
  79. this.patches.forEach(function (p) {
  80. p.parent.removeChild(p);
  81. });
  82. this.patches = [];
  83. this.rays.forEach(function (r) {
  84. r.parent.removeChild(r);
  85. });
  86. this.rays = [];
  87. }
  88. };
  89. });