Advertisement
Rio6

Hitbox shower

Nov 24th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. var slice = [].slice;
  2.  
  3. v2.cross = function(a, b) {
  4. return a[0] * b[1] - b[0] * a[1];
  5. };
  6.  
  7. types.Unit.prototype.fromSpec = function(spec) {
  8. var data, i, j, l, len, len1, len2, len3, len4, len5, n, o, p, part, partNum, q, ref, ref1, ref2, ref3, ref4, ref5, results, thrust, w, x;
  9. this.cost = 0;
  10. this.hp = 5;
  11. this.jumpDistance = 0;
  12. this.jumpCount = 0;
  13. this.speed = 0;
  14. this.turnSpeed = 1;
  15. this.mass = 0;
  16. this.energy = 0;
  17. this.baseGenEnergy = 2.5;
  18. this.genEnergy = this.baseGenEnergy;
  19. this.storeEnergy = 0;
  20. this.genShield = 0;
  21. this.shield = 0;
  22. this.cloak = 0;
  23. this.radius = 20;
  24. this.weaponArc = 0;
  25. this.minArc = 0;
  26. thrust = 0;
  27. data = fromShort(spec);
  28. this.name = data.name || "";
  29. this.aiRules = data.aiRules || [];
  30. ref = data.parts;
  31. for (partNum = j = 0, len = ref.length; j < len; partNum = ++j) {
  32. p = ref[partNum];
  33. if (!window.parts[p.type]) {
  34. continue;
  35. }
  36. part = new window.parts[p.type];
  37. part.unit = this;
  38. part.pos = v2.create(p.pos);
  39. part.dir = p.dir || 0;
  40. part.partNum = partNum;
  41. if (part.weapon) {
  42. this.weapons.push(part);
  43. }
  44. if (p.ghostCopy) {
  45. part.ghostCopy = true;
  46. }
  47. this.parts.push(part);
  48. this.cost += part.cost || 0;
  49. this.hp += part.hp || 0;
  50. thrust += part.thrust || 0;
  51. this.mass += part.mass;
  52. this.turnSpeed += part.turnSpeed || 0;
  53. this.genEnergy += part.genEnergy || 0;
  54. this.storeEnergy += part.storeEnergy || 0;
  55. this.genShield += part.genShield || 0;
  56. this.shield += part.shield || 0;
  57. this.jumpCount += part.jumpCount || 0;
  58. this.limitBonus += part.limitBonus || 0;
  59. if (part.arc && this.weaponArc < part.arc) {
  60. this.weaponArc = part.arc;
  61. }
  62. if (part.arc && (this.minArc === 0 || this.minArc > part.arc)) {
  63. this.minArc = part.arc;
  64. }
  65. }
  66. this.maxHP = this.hp;
  67. this.energy = this.storeEnergy;
  68. this.turnSpeed = this.turnSpeed / this.mass;
  69. this.maxSpeed = thrust / this.mass * 9;
  70. this.maxShield = this.shield;
  71. this.damageRatio = 1;
  72. this.jumpDistance = this.jump = Math.min(this.maxJump / 500, 41 * this.jumpCount / this.mass) * 500;
  73. this.computeCenter();
  74. ref1 = this.parts;
  75. for (l = 0, len1 = ref1.length; l < len1; l++) {
  76. part = ref1[l];
  77. if (typeof part.init === "function") {
  78. part.init();
  79. }
  80. }
  81. this.computeRadius();
  82. this.computeBoundary();
  83. this.weaponRange = 0;
  84. this.weaponDPS = 0;
  85. this.weaponDamage = 0;
  86. ref2 = this.weapons;
  87. for (n = 0, len2 = ref2.length; n < len2; n++) {
  88. w = ref2[n];
  89. w.applyBuffs();
  90. w.reloadTime = Math.ceil(w.reloadTime);
  91. if (w.reloadTime < 1) {
  92. w.reloadTime = 1;
  93. }
  94. if (w.range > this.weaponRange) {
  95. this.weaponRange = w.range;
  96. }
  97. w.dps = w.damage / w.reloadTime;
  98. this.weaponDamage += w.damage;
  99. this.weaponDPS += w.dps;
  100. }
  101. this.weapons.sort(function(a, b) {
  102. return b.dps - a.dps;
  103. });
  104. this.mainWeapon = this.weapons[0];
  105. ref3 = this.weapons;
  106. for (i = o = 0, len3 = ref3.length; o < len3; i = ++o) {
  107. w = ref3[i];
  108. w.turretNum = i;
  109. }
  110. this.moveEnergy = 0;
  111. ref4 = this.parts;
  112. for (q = 0, len4 = ref4.length; q < len4; q++) {
  113. part = ref4[q];
  114. if (part.thrust > 0) {
  115. this.moveEnergy += part.useEnergy;
  116. }
  117. }
  118. this.fireEnergy = 0;
  119. ref5 = this.parts;
  120. results = [];
  121. for (x = 0, len5 = ref5.length; x < len5; x++) {
  122. part = ref5[x];
  123. if (part.fireEnergy > 0) {
  124. results.push(this.fireEnergy += part.fireEnergy);
  125. } else {
  126. results.push(void 0);
  127. }
  128. }
  129. return results;
  130. };
  131.  
  132. types.Unit.prototype.computeBoundary = function() {
  133. var diffCross, extend, findPartPoints, left, max, min, points, right, split, u, v;
  134. findPartPoints = (function(_this) {
  135. return function() {
  136. var fn1, j, l, len, len1, p, part, partPoints, ref, rst;
  137. partPoints = function(part) {
  138. var size;
  139. if (part.dir % 2 === 0) {
  140. size = [part.size[0], part.size[1]];
  141. } else {
  142. size = [part.size[1], part.size[0]];
  143. }
  144. v2.scale(size, 10);
  145. return [v2.add(v2.create([-size[0], size[1]]), part.pos), v2.add(v2.create([size[0], size[1]]), part.pos), v2.add(v2.create([size[0], -size[1]]), part.pos), v2.add(v2.create([-size[0], -size[1]]), part.pos)];
  146. };
  147. rst = [];
  148. ref = _this.parts;
  149. for (j = 0, len = ref.length; j < len; j++) {
  150. part = ref[j];
  151. if (!part.decal) {
  152. rst.push.apply(rst, partPoints(part));
  153. }
  154. }
  155. fn1 = function(p) {
  156. return v2.sub(p, _this.center);
  157. };
  158. for (l = 0, len1 = rst.length; l < len1; l++) {
  159. p = rst[l];
  160. fn1(p);
  161. }
  162. return rst;
  163. };
  164. })(this);
  165. diffCross = function(u, v, p) {
  166. return v2.cross(v2.sub(p, u, [0, 0]), v2.sub(v, u, [0, 0]));
  167. };
  168. min = function(points, fn) {
  169. return points.sort(function(a, b) {
  170. return fn(a) - fn(b);
  171. })[0];
  172. };
  173. max = function(points, fn) {
  174. return points.sort(function(a, b) {
  175. return fn(b) - fn(a);
  176. })[0];
  177. };
  178. split = function(u, v, points) {
  179. var p;
  180. return (function() {
  181. var j, len, results;
  182. results = [];
  183. for (j = 0, len = points.length; j < len; j++) {
  184. p = points[j];
  185. if (diffCross(u, v, p) < 0) {
  186. results.push(p);
  187. }
  188. }
  189. return results;
  190. })();
  191. };
  192. extend = function(u, v, points) {
  193. var p1, p2, w;
  194. if (!(points != null ? points.length : void 0)) {
  195. return [];
  196. }
  197. w = min(points, function(p) {
  198. return diffCross(u, v, p);
  199. });
  200. p1 = split(w, v, points);
  201. p2 = split(u, w, points);
  202. return slice.call(extend(w, v, p1)).concat([w], slice.call(extend(u, w, p2)));
  203. };
  204. points = findPartPoints();
  205. u = min(points, function(p) {
  206. return p[0];
  207. });
  208. v = max(points, function(p) {
  209. return p[0];
  210. });
  211. left = split(u, v, points);
  212. right = split(v, u, points);
  213. return this.boundPoints = [v].concat(slice.call(extend(u, v, left)), [u], slice.call(extend(v, u, right)), [v]);
  214. };
  215.  
  216. types.Unit.prototype.draw = function() {
  217. var a, color, drawLine, i, j, l, len, len1, n, part, partNum, r, ref, ref1, ref2, s, t, toWorld, value;
  218. if (this.dead) {
  219. return;
  220. }
  221. ref = this.parts;
  222. for (j = 0, len = ref.length; j < len; j++) {
  223. part = ref[j];
  224. if (typeof part.preDraw === "function") {
  225. part.preDraw();
  226. }
  227. part.computeWorldPos();
  228. }
  229. if (this.maxShield > 0) {
  230. s = this.warpIn * 2 - 1;
  231. if (s > 0) {
  232. color = [this.color[0], this.color[1], this.color[2], 255 * this.shield / this.maxShield * s];
  233. r = (this.radius + 40) / 255;
  234. baseAtlas.drawSprite("img/point02.png", this.pos, [r, r], 0, color);
  235. }
  236. }
  237. if (this.warpIn < 1) {
  238. this.warpIn += 1 / 60;
  239. }
  240. ref1 = this.parts;
  241. for (partNum = l = 0, len1 = ref1.length; l < len1; partNum = ++l) {
  242. part = ref1[partNum];
  243. value = part.pos[1] / 700 - .5 + this.warpIn;
  244. if (value > 0) {
  245. part.draw();
  246. } else if (value > -0.2) {
  247. a = -Math.sin(value / Math.PI * 50);
  248. baseAtlas.drawSprite("img/unitBar/fire02.png", part.worldPos, [1, 1], 0, [255, 255, 255, 255 * a]);
  249. continue;
  250. }
  251. }
  252. if (this.energy / this.storeEnergy < .05) {
  253. t = Math.abs(Math.sin(Date.now() / 300));
  254. baseAtlas.drawSprite("img/unitBar/energy1.png", [this.pos[0], this.pos[1] + 100 + this.radius], [1, 1], 0, [255, 100, 100, t * 200]);
  255. }
  256. drawLine = function(from, to) {
  257. var d, offset, rot;
  258. offset = [0, 0];
  259. v2.sub(to, from, offset);
  260. rot = v2.angle(offset);
  261. d = v2.mag(offset) / 380;
  262. v2.scale(offset, .5);
  263. v2.add(offset, from);
  264. return baseAtlas.drawSprite("img/laser01.png", offset, [.2, d], rot, [0, 255, 0, 255]);
  265. };
  266. toWorld = (function(_this) {
  267. return function(from) {
  268. var p;
  269. p = v2.create(from);
  270. v2.rotate(p, _this.rot + Math.PI);
  271. return v2.add(p, _this.pos);
  272. };
  273. })(this);
  274. if(this.boundPoints) {
  275. for (i = n = 0, ref2 = this.boundPoints.length - 1; 0 <= ref2 ? n < ref2 : n > ref2; i = 0 <= ref2 ? ++n : --n) {
  276. drawLine(toWorld(this.boundPoints[i]), toWorld(this.boundPoints[i + 1]));
  277. }
  278. }
  279. if (control.debug && (this._pos2 != null) && this._pos) {
  280. a = 16;
  281. _offset[0] = this._pos2[0] + (this._pos[0] - this._pos2[0]) * a;
  282. _offset[1] = this._pos2[1] + (this._pos[1] - this._pos2[1]) * a;
  283. baseAtlas.drawSprite("img/pip1.png", this._pos, [1, 1], 0, [0, 255, 0, 255]);
  284. baseAtlas.drawSprite("img/pip1.png", this.pos, [1, 1], 0);
  285. return baseAtlas.drawSprite("img/pip1.png", this._pos2, [1, 1], 0, [255, 0, 0, 255]);
  286. }
  287. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement