ZergurVorghiz

Zergur's Gen. 2 HP/E Bars

May 15th, 2020
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.90 KB | None | 0 0
  1. // Created by Zergur Vorghiz
  2.  
  3. /* Changelog:
  4.  
  5. 5/15/2020
  6. - Early in the morning: Started development
  7. - Later that day: Initial release
  8.  
  9. */
  10.  
  11. // --------------------------------------------------------------------------------------------------------------
  12.  
  13. shieldBarScale = function (gen, totl) {
  14. maxx = (gen * 16) + totl;
  15. if (maxx === 0) {
  16. return 0;
  17. } else if (maxx < 500) {
  18. return 0.5;
  19. } else if(maxx < 5000) {
  20. return 1.58;
  21. } else if(maxx < 200000) {
  22. return 5;
  23. } else {
  24. return 15.81
  25. }
  26. }
  27.  
  28. colors.redOrOrange = function(c) {
  29. if (c[1] > 75) {
  30. return [255, 0, 0, 255]
  31. } else {
  32. return [255, 150, 0, 255]
  33. }
  34. };
  35.  
  36. _pipPos = v2.create()
  37.  
  38. types.Unit.prototype.drawHPBar = function() {
  39. var burnColor, color, healthScale, i, j, max, number, pipScale, ref, results, s;
  40. burnColor = colors.redOrOrange(this.color);
  41. max = this.maxHP;
  42. if (max < 1000) {
  43. healthScale = 10;
  44. pipScale = 0.5;
  45. } else if(max < 10000) {
  46. healthScale = 100;
  47. pipScale = 1.58;
  48. } else if(max < 100000) {
  49. healthScale = 1000;
  50. pipScale = 5;
  51. } else {
  52. healthScale = 10000;
  53. pipScale = 15.81;
  54. }
  55. number = Math.round(this.maxHP / healthScale);
  56. results = [];
  57. for (i = j = 0, ref = number; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
  58. s = 20;
  59. _pipPos[0] = (i * s - number * s / 2 - s / 2) * pipScale;
  60. _pipPos[1] = [(this.radius * -0.8) - 100 + ((pipScale + shieldBarScale(this.genShield, this.maxShield)) * 18)];
  61. if (i < Math.round(this.maxHP / healthScale)) {
  62. if (i < Math.round(this.hp / healthScale)) {
  63. color = [this.color[0], this.color[1], this.color[2], 255];
  64. } else {
  65. color = [20, 20, 20, 150];
  66. }
  67. if (i < this.cloak / this.mass * this.maxHP / healthScale) {
  68. color[3] = 80;
  69. } else if (this.cloakFade > 0) {
  70. color[3] = 180;
  71. }
  72. } else {
  73. if (i < Math.round(this.maxHP / healthScale)) {
  74. color = [this.color[0], this.color[1], this.color[2], 100];
  75. } else {
  76. color = [0, 0, 0, 60];
  77. }
  78. }
  79. v2.add(this.pos, _pipPos, _pipPos);
  80. baseAtlas.drawSprite("img/pip1.png", _pipPos, [pipScale, pipScale], 0, color);
  81. if (Math.round((this.hp + this.shield - this.burn) / healthScale) < i && i < Math.round(this.hp / healthScale)) {
  82. results.push(baseAtlas.drawSprite("img/unitBar/flame.png", _pipPos, [pipScale * .25, pipScale * .25], Math.PI, burnColor));
  83. } else {
  84. results.push(void 0);
  85. }
  86. }
  87. return results;
  88. };
  89.  
  90. types.Unit.prototype.drawShieldBar = function() {
  91. var burnColor, color, healthScale, i, j, max, number, pipScale, ref, results, s;
  92. burnColor = colors.redOrOrange(this.color);
  93. max = (this.genShield * 16) + this.maxShield;
  94. if (max < 500) {
  95. healthScale = 10;
  96. pipScale = 0.5;
  97. } else if(max < 5000) {
  98. healthScale = 100;
  99. pipScale = 1.58;
  100. } else if(max < 200000) {
  101. healthScale = 1000;
  102. pipScale = 5;
  103. } else {
  104. healthScale = 50000;
  105. pipScale = 15.81;
  106. }
  107. number = Math.round(((this.genShield * 16) + this.maxShield) / healthScale);
  108. results = [];
  109. for (i = j = 0, ref = number; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
  110. s = 20;
  111. _pipPos[0] = (i * s - number * s / 2 - s / 2) * pipScale;
  112. _pipPos[1] = [(this.radius * -0.8) - 100];
  113. if (i < ((Math.round(this.genShield * 16) + Math.round(this.maxShield)) / healthScale)) {
  114. if (i < Math.round((this.genShield * 16) / healthScale)) {
  115. color = [this.color[0], this.color[1], this.color[2], 220];
  116. } else if (i <= Math.round(this.genShield * 16 / healthScale) + Math.round(this.shield / healthScale)) {
  117. color = [this.color[0], this.color[1], this.color[2], 140];
  118. } else {
  119. color = [255, 255, 255, 30];
  120. }
  121. }
  122. v2.add(this.pos, _pipPos, _pipPos);
  123. if (i >= Math.round((this.genShield * 16) / healthScale)) {
  124. baseAtlas.drawSprite("img/pip1.png", _pipPos, [pipScale, pipScale], 0, color);
  125. } else {
  126. results.push(baseAtlas.drawSprite("img/unitBar/energyPip.png", _pipPos, [pipScale, pipScale], 0, color));
  127. }
  128. if (((this.genShield * 16) + this.maxShield - this.burn) / healthScale <= i && i >= Math.round((this.genShield * 16) / healthScale)) {
  129. results.push(baseAtlas.drawSprite("img/unitBar/flame.png", _pipPos, [pipScale * .25, pipScale * .25], Math.PI, burnColor));
  130. }
  131. }
  132. return results;
  133. };
  134.  
  135. types.Unit.prototype.drawEnergyBar = function() {
  136. var color, healthScale, i, j, max, number, pipScale, ref, results, s;
  137. max = this.storeEnergy;
  138. if (max < 48001) {
  139. healthScale = 1000;
  140. pipScale = 0.4;
  141. } else if(max < 160001){
  142. healthScale = 8000;
  143. pipScale = 1.13;
  144. } else {
  145. healthScale = 32000;
  146. pipScale = 2.26;
  147. }
  148. number = Math.round(this.storeEnergy / healthScale);
  149. results = [];
  150. for (i = j = 0, ref = number; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
  151. s = 20;
  152. _pipPos[0] = (i * s - number * s / 2 - s / 2) * pipScale;
  153. _pipPos[1] = [(this.radius * -0.8) - 100 - ((pipScale + shieldBarScale(this.genShield, this.maxShield)) * 18)];
  154. if (i < this.energy / healthScale) {
  155. color = [80, 255, 255, 255];
  156. } else {
  157. color = [20, 20, 20, 80];
  158. }
  159. v2.add(this.pos, _pipPos, _pipPos);
  160. results.push(baseAtlas.drawSprite("img/unitBar/energyPip.png", _pipPos, [pipScale, pipScale], 0, color));
  161. }
  162. return results;
  163. };
  164.  
  165. types.Unit.prototype.drawSelection = function() {
  166. var alpha, angle, distance, i, j, len, order, orders, prev, results, target;
  167. this.drawHPBar();
  168. this.drawEnergyBar();
  169. this.drawShieldBar();
  170. if (this.holdPosition) {
  171. baseAtlas.drawSprite("img/unitBar/circle.png", this.pos, [1, 1], 0, [255, 255, 255, 100]);
  172. }
  173. while (this.preOrders.length > 0 && this.preOrders[0].id < this.onOrderId) {
  174. this.preOrders.shift();
  175. }
  176. if (!battleMode.shiftOrder && battleMode.ordering) {
  177. return;
  178. }
  179. if (this.owner === commander.number) {
  180. prev = this.pos;
  181. orders = this.preOrders;
  182. results = [];
  183. for (i = j = 0, len = orders.length; j < len; i = ++j) {
  184. order = orders[i];
  185. if (order.type === "Move") {
  186. if (order.dest == null) {
  187. continue;
  188. }
  189. distance = v2.distance(order.dest, prev);
  190. if (i === 0 && distance < 255 + 10) {
  191. alpha = distance - 10;
  192. } else {
  193. alpha = 255;
  194. }
  195. angle = v2.angle(v2.sub(order.dest, prev, v2.create()));
  196. if (orders.length - 1 === i) {
  197. baseAtlas.drawSprite("img/arrow01.png", order.dest, [.9, .9], angle, [255, 255, 255, alpha]);
  198. } else {
  199. baseAtlas.drawSprite("img/arrow01.png", order.dest, [.8, .8], angle, [255, 255, 255, alpha]);
  200. }
  201. results.push(prev = order.dest);
  202. } else if (order.type === "Follow") {
  203. target = intp.things[order.targetId];
  204. if (target != null) {
  205. results.push(baseAtlas.drawSprite("img/unitBar/target.png", target.pos, [1, 1], 0, [255, 0, 0, 100]));
  206. } else {
  207. results.push(void 0);
  208. }
  209. } else {
  210. results.push(void 0);
  211. }
  212. }
  213. return results;
  214. }
  215. };
Add Comment
Please, Sign In to add comment