選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

123 行
2.8 KiB

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