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.
 
 
 

108 lines
2.4 KiB

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