Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.05 KB | None | 0 0
  1. class nums {
  2. static lerp(a, b, m) {
  3. return (1.0 - m) * a + m * b;
  4. }
  5. static easyFilter(y, x, m) {
  6. return y * m + (1.0 - m) * x;
  7. }
  8. static scale(val, s, d) {
  9. return val * d / s;
  10. }
  11. static vmap(val, s0, s1, d0, d1) {
  12. return (val - s0) * (d1 - d0) / (s1 - s0) + d0;
  13. }
  14. }
  15. (function(wHandle, wjQuery) {
  16. var portlar = ['443', '444', '446', '447', '448', '449'];
  17. var port = portlar[Math.floor(Math.random() * portlar.length)];
  18. var CONNECTION_URL = "92.222.155.41:" + port;
  19. SKIN_URL = "./skins/";
  20. wHandle.setserver = function(arg) {
  21. if (arg != CONNECTION_URL) {
  22. CONNECTION_URL = arg;
  23. showConnecting();
  24. }
  25. };
  26. var touchX, touchY, touchable = 'createTouch' in document,
  27. touches = [];
  28. var leftTouchID = -1,
  29. leftTouchPos = new Vector2(0, 0),
  30. leftTouchStartPos = new Vector2(0, 0),
  31. leftVector = new Vector2(0, 0);
  32. var useHttps = "https:" == wHandle.location.protocol;
  33.  
  34. function gameLoop() {
  35. ma = true;
  36. document.getElementById("canvas").focus();
  37. var isTyping = false;
  38. var chattxt;
  39. mainCanvas = nCanvas = document.getElementById("canvas");
  40. ctx = mainCanvas.getContext("2d");
  41. mainCanvas.onmousemove = function(event) {
  42. rawMouseX = event.clientX;
  43. rawMouseY = event.clientY;
  44. mouseCoordinateChange()
  45. };
  46. if (touchable) {
  47. mainCanvas.addEventListener('touchstart', onTouchStart, false);
  48. mainCanvas.addEventListener('touchmove', onTouchMove, false);
  49. mainCanvas.addEventListener('touchend', onTouchEnd, false);
  50. }
  51. mainCanvas.onmouseup = function() {};
  52. if (/firefox/i.test(navigator.userAgent)) {
  53. document.addEventListener("DOMMouseScroll", handleWheel, false);
  54. } else {
  55. document.body.onmousewheel = handleWheel;
  56. }
  57. mainCanvas.onfocus = function() {
  58. isTyping = false;
  59. };
  60. document.getElementById("chat_textbox").onblur = function() {
  61. isTyping = false;
  62. };
  63. document.getElementById("chat_textbox").onfocus = function() {
  64. isTyping = true;
  65. };
  66. var spacePressed = false,
  67. qPressed = false,
  68. ePressed = false,
  69. rPressed = false,
  70. tPressed = false,
  71. pPressed = false,
  72. wPressed = false;
  73. wHandle.onkeydown = function(event) {
  74. switch (event.keyCode) {
  75. case 13:
  76. if (isTyping || hideChat) {
  77. isTyping = false;
  78. document.getElementById("chat_textbox").blur();
  79. chattxt = document.getElementById("chat_textbox").value;
  80. if (chattxt.length > 0) {
  81. sendChat(chattxt); sendChat(chattxt); sendChat(chattxt); sendChat(chattxt);sendChat(chattxt);sendChat(chattxt);sendChat(chattxt);sendChat(chattxt);sendChat(chattxt);sendChat(chattxt);sendChat(chattxt);sendChat(chattxt);sendChat(chattxt);sendChat(chattxt);
  82. }
  83. document.getElementById("chat_textbox").value = "";
  84. } else {
  85. if (!hasOverlay) {
  86. document.getElementById("chat_textbox").focus();
  87. isTyping = true;
  88. }
  89. }
  90. break;
  91. case 32:
  92. if ((!spacePressed) && (!isTyping)) {
  93. sendMouseMove();
  94. sendUint8(17);
  95. spacePressed = true;
  96. }
  97. break;
  98. case 87:
  99. if ((!wPressed) && (!isTyping)) {
  100. sendMouseMove();
  101. sendUint8(21);
  102. wPressed = true;
  103. }
  104. break;
  105. case 81:
  106. if ((!qPressed) && (!isTyping)) {
  107. sendUint8(18);
  108. qPressed = true;
  109. }
  110. break;
  111. case 69:
  112. if (!isTyping) {
  113. sendMouseMove();
  114. sendUint8(21);
  115. }
  116. break;
  117. case 82:
  118. if (!rPressed && (!isTyping)) {
  119. sendMouseMove();
  120. sendUint8(23);
  121. if (!rMacro) rPressed = true;
  122. }
  123. break;
  124. case 84:
  125. if (!tPressed && (!isTyping)) {
  126. sendMouseMove();
  127. sendUint8(24);
  128. tPressed = true;
  129. }
  130. break;
  131. case 80:
  132. if (!pPressed && (!isTyping)) {
  133. sendMouseMove();
  134. sendUint8(25);
  135. pPressed = true;
  136. }
  137. break;
  138. case 27:
  139. showOverlays(true);
  140. break;
  141. }
  142. };
  143. wHandle.onkeyup = function(event) {
  144. switch (event.keyCode) {
  145. case 32:
  146. spacePressed = false;
  147. break;
  148. case 87:
  149. wPressed = false;
  150. break;
  151. case 81:
  152. if (qPressed) {
  153. sendUint8(19);
  154. qPressed = false;
  155. }
  156. break;
  157. case 82:
  158. rPressed = false;
  159. break;
  160. case 84:
  161. tPressed = false;
  162. break;
  163. case 80:
  164. pPressed = false;
  165. break;
  166. }
  167. };
  168. wHandle.onblur = function() {
  169. sendUint8(19);
  170. wPressed = spacePressed = qPressed = ePressed = rPressed = tPressed = pPressed = false
  171. };
  172. wHandle.onresize = canvasResize;
  173. canvasResize();
  174. if (wHandle.requestAnimationFrame) {
  175. wHandle.requestAnimationFrame(redrawGameScene);
  176. } else {
  177. setInterval(drawGameScene, 1E3 / 60);
  178. }
  179. setInterval(sendMouseMove, 40);
  180. null == ws && showConnecting();
  181. wjQuery("#overlays").show();
  182. }
  183.  
  184. function onTouchStart(e) {
  185. for (var i = 0; i < e.changedTouches.length; i++) {
  186. var touch = e.changedTouches[i];
  187. if ((leftTouchID < 0) && (touch.clientX < canvasWidth / 2)) {
  188. leftTouchID = touch.identifier;
  189. leftTouchStartPos.reset(touch.clientX, touch.clientY);
  190. leftTouchPos.copyFrom(leftTouchStartPos);
  191. leftVector.reset(0, 0);
  192. }
  193. var size = ~~(canvasWidth / 7);
  194. if ((touch.clientX > canvasWidth - size) && (touch.clientY > canvasHeight - size)) {
  195. sendMouseMove();
  196. sendUint8(17);
  197. }
  198. if ((touch.clientX > canvasWidth - size) && (touch.clientY > canvasHeight - 2 * size - 10) && (touch.clientY < canvasHeight - size - 10)) {
  199. sendMouseMove();
  200. sendUint8(21);
  201. }
  202. }
  203. touches = e.touches;
  204. }
  205.  
  206. function onTouchMove(e) {
  207. e.preventDefault();
  208. for (var i = 0; i < e.changedTouches.length; i++) {
  209. var touch = e.changedTouches[i];
  210. if (leftTouchID == touch.identifier) {
  211. leftTouchPos.reset(touch.clientX, touch.clientY);
  212. leftVector.copyFrom(leftTouchPos);
  213. leftVector.minusEq(leftTouchStartPos);
  214. rawMouseX = leftVector.x * 3 + canvasWidth / 2;
  215. rawMouseY = leftVector.y * 3 + canvasHeight / 2;
  216. mouseCoordinateChange();
  217. sendMouseMove();
  218. }
  219. }
  220. touches = e.touches;
  221. }
  222.  
  223. function onTouchEnd(e) {
  224. touches = e.touches;
  225. for (var i = 0; i < e.changedTouches.length; i++) {
  226. var touch = e.changedTouches[i];
  227. if (leftTouchID == touch.identifier) {
  228. leftTouchID = -1;
  229. leftVector.reset(0, 0);
  230. break;
  231. }
  232. }
  233. }
  234.  
  235. function handleWheel(event) {
  236. zoom *= Math.pow(.9, event.wheelDelta / -120 || event.detail / 3 || 0);
  237. 0.7 > zoom && (zoom = 0.7);
  238. zoom > 4 / viewZoom && (zoom = 4 / viewZoom)
  239. }
  240.  
  241. function buildQTree() {
  242. if (.4 > viewZoom) qTree = null;
  243. else {
  244. var a = Number.POSITIVE_INFINITY,
  245. b = Number.POSITIVE_INFINITY,
  246. c = Number.NEGATIVE_INFINITY,
  247. d = Number.NEGATIVE_INFINITY,
  248. e = 0;
  249. for (var i = 0; i < nodelist.length; i++) {
  250. var node = nodelist[i];
  251. if (node.shouldRender() && !node.prepareData && 20 < node.size * viewZoom) {
  252. e = Math.max(node.size, e);
  253. a = Math.min(node.x, a);
  254. b = Math.min(node.y, b);
  255. c = Math.max(node.x, c);
  256. d = Math.max(node.y, d);
  257. }
  258. }
  259. qTree = Quad.init({
  260. minX: a - (e + 100),
  261. minY: b - (e + 100),
  262. maxX: c + (e + 100),
  263. maxY: d + (e + 100),
  264. maxChildren: 2,
  265. maxDepth: 4
  266. });
  267. for (i = 0; i < nodelist.length; i++) {
  268. node = nodelist[i];
  269. if (node.shouldRender() && !(20 >= node.size * viewZoom)) {
  270. for (a = 0; a < node.points.length; ++a) {
  271. b = node.points[a].x;
  272. c = node.points[a].y;
  273. b < nodeX - canvasWidth / 2 / viewZoom || c < nodeY - canvasHeight / 2 / viewZoom || b > nodeX + canvasWidth / 2 / viewZoom || c > nodeY + canvasHeight / 2 / viewZoom || qTree.insert(node.points[a]);
  274. }
  275. }
  276. }
  277. }
  278. }
  279.  
  280. function mouseCoordinateChange() {
  281. X = (rawMouseX - canvasWidth / 2) / viewZoom + nodeX;
  282. Y = (rawMouseY - canvasHeight / 2) / viewZoom + nodeY
  283. }
  284.  
  285. function hideOverlays() {
  286. hasOverlay = false;
  287. wjQuery("#overlays").hide();
  288. }
  289.  
  290. function showOverlays(arg) {
  291. hasOverlay = true;
  292. userNickName = null;
  293. wjQuery("#overlays").fadeIn(arg ? 200 : 3E3);
  294. }
  295.  
  296. function showConnecting() {
  297. if (ma) {
  298. wjQuery("#connecting").show();
  299. wsConnect((useHttps ? "wss://" : "ws://") + CONNECTION_URL)
  300. }
  301. }
  302.  
  303. function wsConnect(wsUrl) {
  304. if (ws) {
  305. ws.onopen = null;
  306. ws.onmessage = null;
  307. ws.onclose = null;
  308. try {
  309. ws.close()
  310. } catch (b) {}
  311. ws = null
  312. }
  313. var c = CONNECTION_URL;
  314. wsUrl = (useHttps ? "wss://" : "ws://") + c;
  315. nodesOnScreen = [];
  316. playerCells = [];
  317. nodes = {};
  318. taymir = 0;
  319. nodelist = [];
  320. Cells = [];
  321. leaderBoard = [];
  322. mainCanvas = teamScores = null;
  323. userScore = 0;
  324. ws = new WebSocket(wsUrl);
  325. ws.binaryType = "arraybuffer";
  326. ws.onopen = onWsOpen;
  327. ws.onmessage = onWsMessage;
  328. ws.onclose = onWsClose;
  329. }
  330.  
  331. function prepareData(a) {
  332. return new DataView(new ArrayBuffer(a))
  333. }
  334.  
  335. function wsSend(a) {
  336. ws.send(a.buffer)
  337. }
  338.  
  339. function onWsOpen() {
  340. var msg;
  341. delay = 500;
  342. wjQuery("#connecting").hide();
  343. msg = prepareData(5);
  344. msg.setUint8(0, 254);
  345. msg.setUint32(1, 5, true);
  346. wsSend(msg);
  347. msg = prepareData(5);
  348. msg.setUint8(0, 255);
  349. msg.setUint32(1, 0, true);
  350. wsSend(msg);
  351. sendNickName();
  352. }
  353.  
  354. function onWsClose() {
  355. setTimeout(showConnecting, delay);
  356. delay *= 1.5;
  357. }
  358.  
  359. function onWsMessage(msg) {
  360. handleWsMessage(new DataView(msg.data));
  361. }
  362.  
  363. function handleWsMessage(msg) {
  364. function getString() {
  365. var text = '',
  366. char;
  367. while ((char = msg.getUint16(offset, true)) != 0) {
  368. offset += 2;
  369. text += String.fromCharCode(char);
  370. }
  371. offset += 2;
  372. return text;
  373. }
  374. var offset = 0,
  375. setCustomLB = false;
  376. 240 == msg.getUint8(offset) && (offset += 5);
  377. switch (msg.getUint8(offset++)) {
  378. case 16:
  379. updateNodes(msg, offset);
  380. break;
  381. case 17:
  382. posX = msg.getFloat32(offset, true);
  383. offset += 4;
  384. posY = msg.getFloat32(offset, true);
  385. offset += 4;
  386. posSize = msg.getFloat32(offset, true);
  387. offset += 4;
  388. break;
  389. case 20:
  390. playerCells = [];
  391. nodesOnScreen = [];
  392. break;
  393. case 21:
  394. lineX = msg.getInt16(offset, true);
  395. offset += 2;
  396. lineY = msg.getInt16(offset, true);
  397. offset += 2;
  398. if (!drawLine) {
  399. drawLine = true;
  400. drawLineX = lineX;
  401. drawLineY = lineY;
  402. }
  403. break;
  404. case 32:
  405. nodesOnScreen.push(msg.getUint32(offset, true));
  406. offset += 4;
  407. break;
  408. case 31:
  409. ping = Math.floor(Date.now() - pingtaym);
  410. break;
  411. case 48:
  412. setCustomLB = true;
  413. noRanking = true;
  414. break;
  415. case 49:
  416. if (!setCustomLB) {
  417. noRanking = false;
  418. }
  419. teamScores = null;
  420. var LBplayerNum = msg.getUint32(offset, true);
  421. offset += 4;
  422. leaderBoard = [];
  423. for (i = 0; i < LBplayerNum; ++i) {
  424. var nodeId = msg.getUint32(offset, true);
  425. offset += 4;
  426. leaderBoard.push({
  427. id: nodeId,
  428. name: getString()
  429. })
  430. }
  431. drawLeaderBoard();
  432. break;
  433. case 50:
  434. teamScores = [];
  435. var LBteamNum = msg.getUint32(offset, true);
  436. offset += 4;
  437. for (var i = 0; i < LBteamNum; ++i) {
  438. teamScores.push(msg.getFloat32(offset, true));
  439. offset += 4;
  440. }
  441. drawLeaderBoard();
  442. break;
  443. case 64:
  444. leftPos = msg.getFloat64(offset, true);
  445. offset += 8;
  446. topPos = msg.getFloat64(offset, true);
  447. offset += 8;
  448. rightPos = msg.getFloat64(offset, true);
  449. offset += 8;
  450. bottomPos = msg.getFloat64(offset, true);
  451. offset += 8;
  452. posX = (rightPos + leftPos) / 2;
  453. posY = (bottomPos + topPos) / 2;
  454. posSize = 1;
  455. if (0 == playerCells.length) {
  456. nodeX = posX;
  457. nodeY = posY;
  458. viewZoom = posSize;
  459. }
  460. break;
  461. case 96:
  462. taymir = msg.getUint16(offset, true);
  463. break;
  464. case 99:
  465. addChat(msg, offset);
  466. break;
  467. }
  468. }
  469.  
  470. function addChat(view, offset) {
  471. function getString() {
  472. var text = '',
  473. char;
  474. while ((char = view.getUint16(offset, true)) != 0) {
  475. offset += 2;
  476. text += String.fromCharCode(char);
  477. }
  478. offset += 2;
  479. return text;
  480. }
  481. var flags = view.getUint8(offset++);
  482. if (flags & 0x80) {}
  483. if (flags & 0x40) {}
  484. if (flags & 0x20) {}
  485. var r = view.getUint8(offset++),
  486. g = view.getUint8(offset++),
  487. b = view.getUint8(offset++),
  488. color = (r << 16 | g << 8 | b).toString(16);
  489. while (color.length < 6) {
  490. color = '0' + color;
  491. }
  492. color = '#' + color;
  493. chatBoard.push({
  494. "name": asddc(getString())[1],
  495. "color": color,
  496. "message": getString(),
  497. "time": Date.now()
  498. });
  499. drawChatBoard();
  500. }
  501.  
  502. function drawChatBoard() {
  503. if (hideChat) {
  504. chatCanvas = null;
  505. return;
  506. }
  507. chatCanvas = document.createElement("canvas");
  508. var ctx = chatCanvas.getContext("2d");
  509. var scaleFactor = Math.min(Math.max(canvasWidth / 1200, 0.75), 1);
  510. chatCanvas.width = 1E3 * scaleFactor;
  511. chatCanvas.height = 550 * scaleFactor;
  512. ctx.scale(scaleFactor, scaleFactor);
  513. var nowtime = Date.now();
  514. var lasttime = 0;
  515. if (chatBoard.length >= 1)
  516. lasttime = chatBoard[chatBoard.length - 1].time;
  517. else return;
  518. var deltat = nowtime - lasttime;
  519. ctx.globalAlpha = 0.8 * Math.exp(-deltat / 25000);
  520. var len = chatBoard.length;
  521. var from = len - 15;
  522. if (from < 0) from = 0;
  523. for (var i = 0; i < (len - from); i++) {
  524. var chatName = new UText(18, chatBoard[i + from].color);
  525. chatName.setValue(chatBoard[i + from].name);
  526. var width = chatName.getWidth();
  527. var a = chatName.render();
  528. ctx.drawImage(a, 15, chatCanvas.height / scaleFactor - 24 * (len - i - from));
  529. var chatText = new UText(18, '#666666');
  530. chatText.setValue(':' + chatBoard[i + from].message);
  531. a = chatText.render();
  532. ctx.drawImage(a, 15 + width * 1.8, chatCanvas.height / scaleFactor - 24 * (len - from - i));
  533. }
  534. }
  535.  
  536. function updateNodes(view, offset) {
  537. timestamp = +new Date;
  538. var code = Math.random();
  539. ua = false;
  540. var queueLength = view.getUint16(offset, true);
  541. offset += 2;
  542. for (i = 0; i < queueLength; ++i) {
  543. var killer = nodes[view.getUint32(offset, true)],
  544. killedNode = nodes[view.getUint32(offset + 4, true)];
  545. offset += 8;
  546. if (killer && killedNode) {
  547. killedNode.destroy();
  548. killedNode.ox = killedNode.x;
  549. killedNode.oy = killedNode.y;
  550. killedNode.oSize = killedNode.size;
  551. killedNode.nx = killer.x;
  552. killedNode.ny = killer.y;
  553. killedNode.nSize = killedNode.size;
  554. killedNode.updateTime = timestamp;
  555. var colduren_kontrol = -1 != nodesOnScreen.indexOf(killer.id),
  556. oldurulen_kontrol = -1 != nodesOnScreen.indexOf(killedNode.id),
  557. boyut_kontrol = 80 > killedNode.size;
  558. colduren_kontrol && boyut_kontrol && ++foodEaten;
  559. }
  560. }
  561. for (var i = 0;;) {
  562. var nodeid = view.getUint32(offset, true);
  563. offset += 4;
  564. if (0 == nodeid) break;
  565. ++i;
  566. var size, posY, posX = view.getInt32(offset, true);
  567. offset += 4;
  568. posY = view.getInt32(offset, true);
  569. offset += 4;
  570. size = view.getInt16(offset, true);
  571. offset += 2;
  572. for (var r = view.getUint8(offset++), g = view.getUint8(offset++), b = view.getUint8(offset++), color = (r << 16 | g << 8 | b).toString(16); 6 > color.length;) color = "0" + color;
  573. var colorstr = "#" + color,
  574. flags = view.getUint8(offset++),
  575. flagVirus = !!(flags & 0x01),
  576. flagEjected = !!(flags & 0x20),
  577. flagAgitated = !!(flags & 0x10),
  578. _skin = "";
  579. flags & 2 && (offset += 4);
  580. if (flags & 4) {
  581. for (;;) {
  582. t = view.getUint8(offset, true) & 0x7F;
  583. offset += 1;
  584. if (0 == t) break;
  585. _skin += String.fromCharCode(t);
  586. }
  587. }
  588. for (var char, name = "";;) {
  589. char = view.getUint16(offset, true);
  590. offset += 2;
  591. if (0 == char) break;
  592. name += String.fromCharCode(char);
  593. }
  594. var node = null;
  595. if (nodes.hasOwnProperty(nodeid)) {
  596. node = nodes[nodeid];
  597. node.updatePos();
  598. node.ox = node.x;
  599. node.oy = node.y;
  600. node.oSize = node.size;
  601. node.color = colorstr;
  602. } else {
  603. node = new Cell(nodeid, posX, posY, size, colorstr, name, _skin);
  604. nodelist.push(node);
  605. nodes[nodeid] = node;
  606. node.ka = posX;
  607. node.la = posY;
  608. }
  609. node.isVirus = flagVirus;
  610. node.isEjected = flagEjected;
  611. node.isAgitated = flagAgitated;
  612. node.nx = posX;
  613. node.ny = posY;
  614. node.setSize(size);
  615. node.updateCode = code;
  616. node.updateTime = timestamp;
  617. node.flag = flags;
  618. name && node.setName(name);
  619. if (-1 != nodesOnScreen.indexOf(nodeid) && -1 == playerCells.indexOf(node)) {
  620. document.getElementById("overlays").style.display = "none";
  621. playerCells.push(node);
  622. if (1 == playerCells.length) {
  623. nodeX = node.x;
  624. nodeY = node.y;
  625. }
  626. }
  627. }
  628. queueLength = view.getUint32(offset, true);
  629. offset += 4;
  630. for (i = 0; i < queueLength; i++) {
  631. var nodeId = view.getUint32(offset, true);
  632. offset += 4;
  633. node = nodes[nodeId];
  634. null != node && node.destroy();
  635. }
  636. ua && 0 == playerCells.length && (showOverlays(false), experimental())
  637. }
  638.  
  639. function experimental() {
  640. var c = wjQuery(".progress-bar-star");
  641. var b = wjQuery(".warball-exp-bar .progress-bar-text");
  642. wjQuery.ajax({
  643. type: "POST",
  644. url: 'sxl.php',
  645. data: atob("eD0=") + foodEaten,
  646. success: function(m) {
  647. js = JSON.parse(m);
  648. wjQuery(".progress-bar-star").addClass("animated tada").one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function() {
  649. wjQuery(".progress-bar-star").removeClass("animated tada")
  650. });
  651. wjQuery(".warball-exp-bar .progress-bar").css("width", "0%");
  652. wjQuery(".warball-exp-bar .progress-bar").animate({
  653. width: js.width
  654. });
  655. b.text(js.xp + "/" + js.total + " XP");
  656. c.text(js.level)
  657. }
  658. })
  659. }
  660.  
  661. function sendMouseMove() {
  662. var msg;
  663. if (wsIsOpen()) {
  664. msg = rawMouseX - canvasWidth / 2;
  665. var b = rawMouseY - canvasHeight / 2;
  666. if (64 <= msg * msg + b * b && !(.01 > Math.abs(oldX - X) && .01 > Math.abs(oldY - Y))) {
  667. oldX = X;
  668. oldY = Y;
  669. msg = prepareData(21);
  670. msg.setUint8(0, 16);
  671. msg.setFloat64(1, X, true);
  672. msg.setFloat64(9, Y, true);
  673. msg.setUint32(17, 0, true);
  674. wsSend(msg);
  675. }
  676. }
  677. }
  678.  
  679. function sendNickName() {
  680. if (wsIsOpen() && null != userNickName) {
  681. var msg = prepareData(1 + 2 * userNickName.length);
  682. msg.setUint8(0, 0);
  683. for (var i = 0; i < userNickName.length; ++i) msg.setUint16(1 + 2 * i, userNickName.charCodeAt(i), true);
  684. wsSend(msg)
  685. }
  686. }
  687.  
  688. function sendChat(str) {
  689. if (wsIsOpen() && (str.length < 200) && (str.length > 0) && !hideChat) {
  690. var msg = prepareData(2 + 2 * str.length);
  691. var offset = 0;
  692. msg.setUint8(offset++, 99);
  693. msg.setUint8(offset++, 0);
  694. for (var i = 0; i < str.length; ++i) {
  695. msg.setUint16(offset, str.charCodeAt(i), true);
  696. offset += 2;
  697. }
  698. wsSend(msg);
  699. }
  700. }
  701.  
  702. function wsIsOpen() {
  703. return null != ws && ws.readyState == ws.OPEN
  704. }
  705.  
  706. function sendUint8(a) {
  707. if (wsIsOpen()) {
  708. var msg = prepareData(1);
  709. msg.setUint8(0, a);
  710. wsSend(msg)
  711. }
  712. }
  713.  
  714. function redrawGameScene() {
  715. drawGameScene();
  716. wHandle.requestAnimationFrame(redrawGameScene)
  717. }
  718.  
  719. function canvasResize() {
  720. window.scrollTo(0, 0);
  721. canvasWidth = wHandle.innerWidth;
  722. canvasHeight = wHandle.innerHeight;
  723. nCanvas.width = canvasWidth;
  724. nCanvas.height = canvasHeight;
  725. drawGameScene()
  726. }
  727.  
  728. function viewRange() {
  729. var ratio;
  730. ratio = Math.max(canvasHeight / 1080, canvasWidth / 1920);
  731. return ratio * zoom;
  732. }
  733.  
  734. function calcViewZoom() {
  735. if (0 != playerCells.length) {
  736. for (var newViewZoom = 0, i = 0; i < playerCells.length; i++) newViewZoom += playerCells[i].size;
  737. newViewZoom = Math.pow(Math.min(64 / newViewZoom, 1), .4) * viewRange();
  738. viewZoom = (9 * viewZoom + newViewZoom) / 10;
  739. }
  740. }
  741.  
  742. function drawGameScene() {
  743. var a, oldtime = Date.now();
  744. ++cb;
  745. timestamp = oldtime;
  746. if (0 < playerCells.length) {
  747. calcViewZoom();
  748. var c = a = 0;
  749. for (var d = 0; d < playerCells.length; d++) {
  750. playerCells[d].updatePos();
  751. a += playerCells[d].x / playerCells.length;
  752. c += playerCells[d].y / playerCells.length;
  753. }
  754. posX = a;
  755. posY = c;
  756. posSize = viewZoom;
  757. nodeX = (nodeX + a) / 2;
  758. nodeY = (nodeY + c) / 2
  759. } else {
  760. nodeX = (29 * nodeX + posX) / 30;
  761. nodeY = (29 * nodeY + posY) / 30;
  762. viewZoom = (9 * viewZoom + posSize * viewRange()) / 10;
  763. }
  764. buildQTree();
  765. mouseCoordinateChange();
  766. xa || ctx.clearRect(0, 0, canvasWidth, canvasHeight);
  767. if (xa) {
  768. if (showDarkTheme) {
  769. ctx.fillStyle = '#111111';
  770. ctx.globalAlpha = .05;
  771. ctx.fillRect(0, 0, canvasWidth, canvasHeight);
  772. ctx.globalAlpha = 1;
  773. } else {
  774. ctx.fillStyle = '#F2FBFF';
  775. ctx.globalAlpha = .05;
  776. ctx.fillRect(0, 0, canvasWidth, canvasHeight);
  777. ctx.globalAlpha = 1;
  778. }
  779. } else {
  780. drawGrid();
  781. }
  782. nodelist.sort(function(a, b) {
  783. return a.size === b.size ? a.id - b.id : a.size - b.size
  784. });
  785. ctx.save();
  786. ctx.translate(canvasWidth / 2, canvasHeight / 2);
  787. ctx.scale(viewZoom, viewZoom);
  788. ctx.translate(-nodeX, -nodeY);
  789. ctx.strokeStyle = '#8a8a8a';
  790. ctx.lineWidth = 30;
  791. ctx.beginPath();
  792. ctx.moveTo(leftPos, topPos);
  793. ctx.lineTo(rightPos, topPos);
  794. ctx.lineTo(rightPos, bottomPos);
  795. ctx.lineTo(leftPos, bottomPos);
  796. ctx.closePath();
  797. ctx.stroke();
  798. for (d = 0; d < Cells.length; d++) Cells[d].drawOneCell(ctx);
  799. for (d = 0; d < nodelist.length; d++) nodelist[d].drawOneCell(ctx);
  800. if (drawLine) {
  801. drawLineX = (3 * drawLineX + lineX) /
  802. 4;
  803. drawLineY = (3 * drawLineY + lineY) / 4;
  804. ctx.save();
  805. ctx.strokeStyle = "#FFAAAA";
  806. ctx.lineWidth = 10;
  807. ctx.lineCap = "round";
  808. ctx.lineJoin = "round";
  809. ctx.globalAlpha = .5;
  810. ctx.beginPath();
  811. for (d = 0; d < playerCells.length; d++) {
  812. ctx.moveTo(playerCells[d].x, playerCells[d].y);
  813. ctx.lineTo(drawLineX, drawLineY);
  814. }
  815. ctx.stroke();
  816. ctx.restore()
  817. }
  818. ctx.restore();
  819. lbCanvas && lbCanvas.width && ctx.drawImage(lbCanvas, canvasWidth - lbCanvas.width - 10, 10);
  820. if (chatCanvas != null) ctx.drawImage(chatCanvas, 0, canvasHeight - chatCanvas.height - 50);
  821. userScore = Math.max(userScore, calcUserScore());
  822. if (0 != userScore) {
  823. if (null == scoreText) {
  824. scoreText = new UText(24, '#fff');
  825. }
  826. scoreText.setValue('Score: ' + ~~(userScore / 100));
  827. c = scoreText.render();
  828. a = c.width;
  829. ctx.globalAlpha = .2;
  830. ctx.fillStyle = '#000000';
  831. ctx.fillRect(10, 10, a + 10, 34);
  832. ctx.globalAlpha = 1;
  833. ctx.drawImage(c, 15, 15);
  834. }
  835. drawSplitIcon(ctx);
  836. drawTouch(ctx);
  837. var deltatime = Date.now() - oldtime;
  838. deltatime > 1E3 / 60 ? z -= .01 : deltatime < 1E3 / 65 && (z += .01);.4 > z && (z = .4);
  839. 1 < z && (z = 1)
  840. }
  841.  
  842. function drawTouch(ctx) {
  843. ctx.save();
  844. if (touchable) {
  845. for (var i = 0; i < touches.length; i++) {
  846. var touch = touches[i];
  847. if (touch.identifier == leftTouchID) {
  848. ctx.beginPath();
  849. ctx.strokeStyle = "#0096ff";
  850. ctx.lineWidth = 6;
  851. ctx.arc(leftTouchStartPos.x, leftTouchStartPos.y, 40, 0, Math.PI * 2, true);
  852. ctx.stroke();
  853. ctx.beginPath();
  854. ctx.strokeStyle = "#0096ff";
  855. ctx.lineWidth = 2;
  856. ctx.arc(leftTouchStartPos.x, leftTouchStartPos.y, 60, 0, Math.PI * 2, true);
  857. ctx.stroke();
  858. ctx.beginPath();
  859. ctx.strokeStyle = "#0096ff";
  860. ctx.arc(leftTouchPos.x, leftTouchPos.y, 40, 0, Math.PI * 2, true);
  861. ctx.stroke();
  862. } else {
  863. ctx.beginPath();
  864. ctx.beginPath();
  865. ctx.strokeStyle = "#0096ff";
  866. ctx.lineWidth = "6";
  867. ctx.arc(touch.clientX, touch.clientY, 40, 0, Math.PI * 2, true);
  868. ctx.stroke();
  869. }
  870. }
  871. }
  872. ctx.restore();
  873. }
  874.  
  875. function drawGrid() {
  876. ctx.fillStyle = showDarkTheme ? "#181818" : "#eeeeee";
  877. ctx.fillRect(0, 0, canvasWidth, canvasHeight);
  878. ctx.save();
  879. }
  880.  
  881. function drawSplitIcon(ctx) {
  882. if (isTouchStart && splitIcon.width) {
  883. var size = ~~(canvasWidth / 7);
  884. ctx.drawImage(splitIcon, canvasWidth - size, canvasHeight - size, size, size);
  885. }
  886. if (isTouchStart && splitIcon.width) {
  887. var size = ~~(canvasWidth / 7);
  888. ctx.drawImage(ejectIcon, canvasWidth - size, canvasHeight - 2 * size - 10, size, size);
  889. }
  890. }
  891.  
  892. function calcUserScore() {
  893. for (var score = 0, i = 0; i < playerCells.length; i++) score += playerCells[i].nSize * playerCells[i].nSize;
  894. return score
  895. }
  896.  
  897. function asddc(c, a) {
  898. if (-1 != c.indexOf("{") & -1 != c.indexOf("}")) {
  899. var b = c.indexOf("{"),
  900. d = c.indexOf("}"),
  901. e = c.slice(d + 1);
  902. a && (e = "" == e ? "An unnamed cell" : c.slice(d + 1));
  903. return [c.slice(b + 1, d), e]
  904. }
  905. return ["", c]
  906. }
  907.  
  908. function drawLeaderBoard() {
  909. lbCanvas = null;
  910. var drawTeam = null != teamScores;
  911. if (drawTeam || 0 != leaderBoard.length)
  912. if (drawTeam || showName) {
  913. lbCanvas = document.createElement("canvas");
  914. var ctx = lbCanvas.getContext("2d"),
  915. boardLength = 60;
  916. boardLength = !drawTeam ? boardLength + 24 * leaderBoard.length : boardLength + 180;
  917. var scaleFactor = Math.min(0.22 * canvasHeight, Math.min(200, .3 * canvasWidth)) * 0.005;
  918. lbCanvas.width = 200 * scaleFactor;
  919. lbCanvas.height = boardLength * scaleFactor;
  920. ctx.scale(scaleFactor, scaleFactor);
  921. ctx.globalAlpha = .4;
  922. ctx.fillStyle = "#181818";
  923. ctx.fillRect(0, 0, 200, boardLength);
  924. ctx.globalAlpha = 1;
  925. ctx.fillStyle = "#FFFFFF";
  926. var c = "Leaderboard";
  927. ctx.font = "30px Russo One";
  928. ctx.fillText(c, 100 - ctx.measureText(c).width * 0.5, 40);
  929. var b, l;
  930. if (!drawTeam) {
  931. for (ctx.font = "20px Russo One", b = 0, l = leaderBoard.length; b < l; ++b) {
  932. c = leaderBoard[b].name || "An unnamed cell";
  933. if (!showName) {
  934. (c = "An unnamed cell");
  935. }
  936. var me = -1 != nodesOnScreen.indexOf(leaderBoard[b].id);
  937. if (me) playerCells[0].name && (c = asddc(playerCells[0].name, 1)[1]);
  938. me ? ctx.fillStyle = "#FFAAAA" : ctx.fillStyle = "#FFFFFF";
  939. if (!noRanking) c = b + 1 + ". " + asddc(c, 1)[1];
  940. var start = (ctx.measureText(c).width > 200) ? 2 : 100 - ctx.measureText(c).width * 0.5;
  941. ctx.fillText(c, start, 70 + 24 * b);
  942. }
  943. } else {
  944. for (b = c = 0; b < teamScores.length; ++b) {
  945. var d = c + teamScores[b] * Math.PI * 2;
  946. ctx.fillStyle = teamColor[b + 1];
  947. ctx.beginPath();
  948. ctx.moveTo(100, 140);
  949. ctx.arc(100, 140, 80, c, d, false);
  950. ctx.fill();
  951. c = d
  952. }
  953. }
  954. }
  955. }
  956.  
  957. function Cell(uid, ux, uy, usize, ucolor, uname, a) {
  958. this.id = uid;
  959. this.ox = this.x = ux;
  960. this.oy = this.y = uy;
  961. this.oSize = this.size = usize;
  962. this.color = ucolor;
  963. this.points = [];
  964. this.pointsAcc = [];
  965. this.createPoints();
  966. this.setName(uname)
  967. this._skin = a;
  968. }
  969.  
  970. function UText(usize, ucolor, ustroke, ustrokecolor) {
  971. usize && (this._size = usize);
  972. ucolor && (this._color = ucolor);
  973. this._stroke = !!ustroke;
  974. ustrokecolor && (this._strokeColor = ustrokecolor)
  975. }
  976. var localProtocol = wHandle.location.protocol,
  977. localProtocolHttps = "https:" == localProtocol;
  978. var nCanvas, ctx, mainCanvas, lbCanvas, chatCanvas, canvasWidth, canvasHeight, qTree = null,
  979. ws = null,
  980. nodeX = 0,
  981. nodeY = 0,
  982. nodesOnScreen = [],
  983. foodEaten = 0,
  984. playerCells = [],
  985. nodes = {},
  986. nodelist = [],
  987. Cells = [],
  988. pingtaym = 0,
  989. ping = 0,
  990. taymir = 0,
  991. leaderBoard = [],
  992. chatBoard = [],
  993. rawMouseX = 0,
  994. rawMouseY = 0,
  995. X = -1,
  996. Y = -1,
  997. cb = 0,
  998. timestamp = 0,
  999. userNickName = null,
  1000. leftPos = 0,
  1001. topPos = 0,
  1002. rightPos = 1E4,
  1003. bottomPos = 1E4,
  1004. viewZoom = 1,
  1005. showSkin = true,
  1006. showName = true,
  1007. showColor = false,
  1008. ua = false,
  1009. userScore = 0,
  1010. showDarkTheme = false,
  1011. showMass = false,
  1012. hideChat = false,
  1013. smoothRender = .4,
  1014. posX = nodeX = ~~((leftPos + rightPos) / 2),
  1015. posY = nodeY = ~~((topPos + bottomPos) / 2),
  1016. posSize = 1,
  1017. teamScores = null,
  1018. ma = false,
  1019. hasOverlay = true,
  1020. drawLine = false,
  1021. lineX = 0,
  1022. lineY = 0,
  1023. drawLineX = 0,
  1024. drawLineY = 0,
  1025. Ra = 0,
  1026. teamColor = ["#333333", "#FF3333", "#33FF33", "#3333FF"],
  1027. xa = false,
  1028. zoom = 1,
  1029. isTouchStart = "ontouchstart" in wHandle && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
  1030. splitIcon = new Image,
  1031. ejectIcon = new Image,
  1032. noRanking = false;
  1033. splitIcon.src = "assets/img/split.png";
  1034. ejectIcon.src = "assets/img/feed.png";
  1035. var wCanvas = document.createElement("canvas");
  1036. var playerStat = null;
  1037. wHandle.isSpectating = false;
  1038. wHandle.setNick = function(name, skin) {
  1039. hideOverlays();
  1040. userNickName = skin ? "{" + skin + "}" + name : name;
  1041. sendNickName();
  1042. userScore = 0
  1043. };
  1044. wHandle.setSkins = function(arg) {
  1045. showSkin = arg
  1046. };
  1047. wHandle.setNames = function(arg) {
  1048. showName = arg
  1049. };
  1050. wHandle.setDarkTheme = function(arg) {
  1051. showDarkTheme = arg
  1052. };
  1053. wHandle.setColors = function(arg) {
  1054. showColor = arg
  1055. };
  1056. wHandle.setShowMass = function(arg) {
  1057. showMass = arg
  1058. };
  1059. wHandle.setSmooth = function(arg) {
  1060. smoothRender = arg ? 2 : .4
  1061. };
  1062. wHandle.setChatHide = function(arg) {
  1063. hideChat = arg;
  1064. if (hideChat) {
  1065. wjQuery('#chat_textbox').hide();
  1066. } else {
  1067. wjQuery('#chat_textbox').show();
  1068. }
  1069. }
  1070. wHandle.spectate = function() {
  1071. userNickName = null;
  1072. wHandle.isSpectating = true;
  1073. sendUint8(1);
  1074. hideOverlays()
  1075. };
  1076. wHandle.setAcid = function(arg) {
  1077. xa = arg
  1078. };
  1079. wHandle.openSkinsList = function(arg) {
  1080. if ($('#inPageModalTitle').text() != "Skins") {
  1081. $.get('include/gallery.php').then(function(data) {
  1082. $('#inPageModalTitle').text("Skins");
  1083. $('#inPageModalBody').html(data);
  1084. });
  1085. }
  1086. };
  1087. if (null != wHandle.localStorage) {
  1088. wjQuery(window).load(function() {
  1089. wjQuery(".save").each(function() {
  1090. var id = $(this).data("box-id");
  1091. var value = wHandle.localStorage.getItem("checkbox-" + id);
  1092. if (value && value == "true" && 0 != id) {
  1093. $(this).prop("checked", "true");
  1094. $(this).trigger("change");
  1095. } else if (id == 0 && value != null) {
  1096. $(this).val(value);
  1097. }
  1098. });
  1099. wjQuery(".save").change(function() {
  1100. var id = $(this).data('box-id');
  1101. var value = (id == 0) ? $(this).val() : $(this).prop('checked');
  1102. wHandle.localStorage.setItem("checkbox-" + id, value);
  1103. });
  1104. });
  1105. if (null == wHandle.localStorage.AB8) {
  1106. wHandle.localStorage.AB8 = ~~(100 * Math.random());
  1107. }
  1108. }
  1109. setTimeout(function() {}, 3E5);
  1110. var T = {
  1111. ZW: "EU-London"
  1112. };
  1113. wHandle.connect = wsConnect;
  1114. var data = {
  1115. "action": "test"
  1116. };
  1117. wjQuery.ajax({
  1118. type: "POST",
  1119. dataType: "json",
  1120. url: "checkdir.php",
  1121. data: data,
  1122. success: function(data) {
  1123. response = JSON.parse(data["names"]);
  1124. for (var i = 0; i < response.length; i++) {
  1125. if (-1 == knownNameDict.indexOf(response[i])) {
  1126. knownNameDict.push(response[i]);
  1127. }
  1128. }
  1129. }
  1130. });
  1131. var delay = 500,
  1132. oldX = -1,
  1133. oldY = -1,
  1134. Canvas = null,
  1135. z = 1,
  1136. scoreText = null,
  1137. skins = {},
  1138. knownNameDict = "".split(";"),
  1139. knownNameDict_noDisp = [],
  1140. ib = ["_canvas'blob"];
  1141. Cell.prototype = {
  1142. id: 0,
  1143. points: null,
  1144. pointsAcc: null,
  1145. name: null,
  1146. nameCache: null,
  1147. sizeCache: null,
  1148. x: 0,
  1149. y: 0,
  1150. size: 0,
  1151. ox: 0,
  1152. oy: 0,
  1153. oSize: 0,
  1154. nx: 0,
  1155. ny: 0,
  1156. nSize: 0,
  1157. flag: 0,
  1158. updateTime: 0,
  1159. updateCode: 0,
  1160. drawTime: 0,
  1161. destroyed: false,
  1162. isVirus: false,
  1163. isEjected: false,
  1164. isAgitated: false,
  1165. wasSimpleDrawing: true,
  1166. destroy: function() {
  1167. var tmp;
  1168. for (tmp = 0, len = nodelist.length; tmp < len; tmp++)
  1169. if (nodelist[tmp] === this) {
  1170. nodelist.splice(tmp, 1);
  1171. break
  1172. }
  1173. delete nodes[this.id];
  1174. tmp = playerCells.indexOf(this);
  1175. if (-1 != tmp) {
  1176. ua = true;
  1177. playerCells.splice(tmp, 1);
  1178. }
  1179. tmp = nodesOnScreen.indexOf(this.id);
  1180. if (-1 != tmp) nodesOnScreen.splice(tmp, 1);
  1181. this.destroyed = true;
  1182. Cells.push(this)
  1183. },
  1184. getNameSize: function() {
  1185. return Math.max(~~(.3 * this.size), 24)
  1186. },
  1187. setName: function(a) {
  1188. this.name = a;
  1189. if (null == this.nameCache) {
  1190. this.nameCache = new UText(this.getNameSize(), "#FFFFFF", true, "#000000");
  1191. this.nameCache.setValue(this.name);
  1192. } else {
  1193. this.nameCache.setSize(this.getNameSize());
  1194. this.nameCache.setValue(this.name);
  1195. }
  1196. },
  1197. setSize: function(a) {
  1198. this.nSize = a;
  1199. var m = ~~(this.size * this.size * 0.01);
  1200. if (null === this.sizeCache)
  1201. this.sizeCache = new UText(this.getNameSize() * 0.5, "#FFFFFF", true, "#000000");
  1202. else this.sizeCache.setSize(this.getNameSize() * 0.5);
  1203. },
  1204. createPoints: function() {
  1205. for (var samplenum = this.getNumPoints(); this.points.length > samplenum;) {
  1206. var rand = ~~(Math.random() * this.points.length);
  1207. this.points.splice(rand, 1);
  1208. this.pointsAcc.splice(rand, 1)
  1209. }
  1210. if (0 == this.points.length && 0 < samplenum) {
  1211. this.points.push({
  1212. ref: this,
  1213. size: this.size,
  1214. x: this.x,
  1215. y: this.y
  1216. });
  1217. this.pointsAcc.push(Math.random() - .5);
  1218. }
  1219. while (this.points.length < samplenum) {
  1220. var rand2 = ~~(Math.random() * this.points.length),
  1221. point = this.points[rand2];
  1222. this.points.splice(rand2, 0, {
  1223. ref: this,
  1224. size: point.size,
  1225. x: point.x,
  1226. y: point.y
  1227. });
  1228. this.pointsAcc.splice(rand2, 0, this.pointsAcc[rand2])
  1229. }
  1230. },
  1231. getNumPoints: function() {
  1232. if (0 == this.id) return 16;
  1233. var a = 10;
  1234. if (20 > this.size) a = 0;
  1235. if (this.isVirus) a = 30;
  1236. var b = this.size;
  1237. if (!this.isVirus)(b *= viewZoom);
  1238. b *= z;
  1239. if (this.flag & 32)(b *= .25);
  1240. return ~~Math.max(b, a);
  1241. },
  1242. movePoints: function() {
  1243. this.createPoints();
  1244. for (var points = this.points, pointsacc = this.pointsAcc, numpoints = points.length, i = 0; i < numpoints; ++i) {
  1245. var pos1 = pointsacc[(i - 1 + numpoints) % numpoints],
  1246. pos2 = pointsacc[(i + 1) % numpoints];
  1247. pointsacc[i] += (Math.random() - .5) * (this.isAgitated ? 3 : 1);
  1248. pointsacc[i] *= .7;
  1249. 10 < pointsacc[i] && (pointsacc[i] = 10); -
  1250. 10 > pointsacc[i] && (pointsacc[i] = -10);
  1251. pointsacc[i] = (pos1 + pos2 + 8 * pointsacc[i]) / 10
  1252. }
  1253. for (var ref = this, isvirus = this.isVirus ? 0 : (this.id / 1E3 + timestamp / 1E4) % (2 * Math.PI), j = 0; j < numpoints; ++j) {
  1254. var f = points[j].size,
  1255. e = points[(j - 1 + numpoints) % numpoints].size,
  1256. m = points[(j + 1) % numpoints].size;
  1257. if (15 < this.size && null != qTree && 20 < this.size * viewZoom && 0 != this.id) {
  1258. var l = false,
  1259. n = points[j].x,
  1260. q = points[j].y;
  1261. qTree.retrieve2(n - 5, q - 5, 10, 10, function(a) {
  1262. if (a.ref != ref && 25 > (n - a.x) * (n - a.x) + (q - a.y) * (q - a.y)) {
  1263. l = true;
  1264. }
  1265. });
  1266. if (!l && points[j].x < leftPos || points[j].y < topPos || points[j].x > rightPos || points[j].y > bottomPos) {
  1267. l = true;
  1268. }
  1269. if (l) {
  1270. if (0 < pointsacc[j]) {
  1271. (pointsacc[j] = 0);
  1272. }
  1273. pointsacc[j] -= 1;
  1274. }
  1275. }
  1276. f += pointsacc[j];
  1277. 0 > f && (f = 0);
  1278. f = this.isAgitated ? (19 * f + this.size) / 20 : (12 * f + this.size) / 13;
  1279. points[j].size = (e + m + 8 * f) / 10;
  1280. e = 2 * Math.PI / numpoints;
  1281. m = this.points[j].size;
  1282. this.isVirus && 0 == j % 2 && (m += 5);
  1283. points[j].x = this.x + Math.cos(e * j + isvirus) * m;
  1284. points[j].y = this.y + Math.sin(e * j + isvirus) * m
  1285. }
  1286. },
  1287. updatePos: function() {
  1288. if (0 == this.id) return 1;
  1289. var a;
  1290. a = (timestamp - this.updateTime) / 120;
  1291. a = 0 > a ? 0 : 1 < a ? 1 : a;
  1292. var b = 0 > a ? 0 : 1 < a ? 1 : a;
  1293. this.getNameSize();
  1294. if (this.destroyed && 1 <= b) {
  1295. var c = Cells.indexOf(this); -
  1296. 1 != c && Cells.splice(c, 1)
  1297. }
  1298. this.x = a * (this.nx - this.ox) + this.ox;
  1299. this.y = a * (this.ny - this.oy) + this.oy;
  1300. this.size = b * (this.nSize - this.oSize) + this.oSize;
  1301. return b;
  1302. },
  1303. shouldRender: function() {
  1304. if (0 == this.id) {
  1305. return true
  1306. } else {
  1307. return !(this.x + this.size + 40 < nodeX - canvasWidth / 2 / viewZoom || this.y + this.size + 40 < nodeY - canvasHeight / 2 / viewZoom || this.x - this.size - 40 > nodeX + canvasWidth / 2 / viewZoom || this.y - this.size - 40 > nodeY + canvasHeight / 2 / viewZoom);
  1308. }
  1309. },
  1310. getStrokeColor: function() {
  1311. var r = (~~(parseInt(this.color.substr(1, 2), 16) * 0.9)).toString(16),
  1312. g = (~~(parseInt(this.color.substr(3, 2), 16) * 0.9)).toString(16),
  1313. b = (~~(parseInt(this.color.substr(5, 2), 16) * 0.9)).toString(16);
  1314. if (r.length == 1) r = "0" + r;
  1315. if (g.length == 1) g = "0" + g;
  1316. if (b.length == 1) b = "0" + b;
  1317. return "#" + r + g + b;
  1318. },
  1319. drawOneCell: function(ctx) {
  1320. if (this.shouldRender()) {
  1321. var b = (0 != this.id && !this.isVirus && !this.isAgitated && smoothRender > viewZoom);
  1322. if (10 > this.getNumPoints()) b = true;
  1323. if (this.wasSimpleDrawing && !b)
  1324. for (var c = 0; c < this.points.length; c++) this.points[c].size = this.size;
  1325. var bigPointSize = this.size;
  1326. if (!this.wasSimpleDrawing) {
  1327. for (var c = 0; c < this.points.length; c++) bigPointSize = Math.max(this.points[c].size, bigPointSize);
  1328. }
  1329. this.wasSimpleDrawing = b;
  1330. ctx.save();
  1331. this.drawTime = timestamp;
  1332. c = this.updatePos();
  1333. this.destroyed && (ctx.globalAlpha *= 1 - c);
  1334. ctx.lineWidth = 10;
  1335. ctx.lineCap = "round";
  1336. ctx.lineJoin = this.isVirus ? "miter" : "round";
  1337. if (showColor) {
  1338. ctx.fillStyle = "#FFFFFF";
  1339. ctx.strokeStyle = "#AAAAAA";
  1340. } else {
  1341. ctx.fillStyle = this.color;
  1342. if (b) ctx.strokeStyle = this.getStrokeColor();
  1343. else ctx.strokeStyle = this.color;
  1344. }
  1345. ctx.beginPath();
  1346. if (b) {
  1347. var lw = this.size * 0.03;
  1348. ctx.lineWidth = lw;
  1349. ctx.arc(this.x, this.y, this.size - lw * 0.5 + 5, 0, 2 * Math.PI, false);
  1350. ctx.stroke();
  1351. } else {
  1352. this.movePoints();
  1353. ctx.beginPath();
  1354. var d = this.getNumPoints();
  1355. ctx.moveTo(this.points[0].x, this.points[0].y);
  1356. for (c = 1; c <= d; ++c) {
  1357. var e = c % d;
  1358. ctx.lineTo(this.points[e].x, this.points[e].y);
  1359. }
  1360. }
  1361. ctx.closePath();
  1362. var skinName = this.name.toLowerCase();
  1363. skinName = asddc(skinName)[0];
  1364. if (typeof this._skin != 'undefined' && this._skin != '') {
  1365. if (this._skin[0] == '%') {
  1366. skinName = this._skin.substring(1);
  1367. }
  1368. }
  1369. if (showSkin && skinName != '' && -1 != knownNameDict.indexOf(skinName)) {
  1370. if (!skins.hasOwnProperty(skinName)) {
  1371. skins[skinName] = new Image;
  1372. skins[skinName].src = SKIN_URL + skinName + '.png';
  1373. }
  1374. if (0 != skins[skinName].width && skins[skinName].complete) {
  1375. c = skins[skinName];
  1376. } else {
  1377. c = null;
  1378. }
  1379. } else {
  1380. c = null;
  1381. }
  1382. b || ctx.stroke();
  1383. ctx.fill();
  1384. if (c) {
  1385. ctx.save();
  1386. ctx.clip();
  1387. ctx.drawImage(c, this.x - bigPointSize, this.y - bigPointSize, 2 * bigPointSize, 2 * bigPointSize);
  1388. ctx.restore();
  1389. }
  1390. if ((showColor || 15 < this.size) && !b) {
  1391. ctx.strokeStyle = '#000000';
  1392. ctx.globalAlpha *= .1;
  1393. ctx.stroke();
  1394. }
  1395. ctx.globalAlpha = 1;
  1396. c = -1 != playerCells.indexOf(this);
  1397. var ncache;
  1398. if (0 != this.id) {
  1399. var x = ~~this.x,
  1400. y = ~~this.y,
  1401. nz = this.getNameSize(),
  1402. ratio = Math.ceil(10 * viewZoom) * 0.1,
  1403. ratD = 1 / ratio;
  1404. if ((showName || c) && this.name && this.nameCache && (null == e || -1 == knownNameDict_noDisp.indexOf(skinName))) {
  1405. ncache = this.nameCache;
  1406. ncache.setValue(asddc(this.name)[1]);
  1407. ncache.setSize(nz);
  1408. ncache.setScale(ratio);
  1409. var rnchache = ncache.render(),
  1410. m = ~~(rnchache.width * ratD),
  1411. h = ~~(rnchache.height * ratD);
  1412. ctx.drawImage(rnchache, x - ~~(m * 0.5), y - ~~(h * 0.5), m, h);
  1413. b += rnchache.height * 0.5 * ratio + 4;
  1414. }
  1415. if (showMass && (c || 0 == playerCells.length && (!this.isVirus || this.isAgitated) && 20 < this.size)) {
  1416. var m = ~~(this.size * this.size * 0.01);
  1417. c = this.sizeCache;
  1418. c.setValue(m);
  1419. c.setScale(ratio);
  1420. e = c.render();
  1421. m = ~~(e.width * ratD);
  1422. h = ~~(e.height * ratD);
  1423. var g = this.name ? y + ~~(h * 0.7) : y - ~~(h * 0.5);
  1424. ctx.drawImage(e, x - ~~(m * 0.5), g, m, h);
  1425. }
  1426. }
  1427. ctx.restore();
  1428. }
  1429. }
  1430. };
  1431. UText.prototype = {
  1432. _value: "",
  1433. _color: "#000000",
  1434. _stroke: false,
  1435. _strokeColor: "#000000",
  1436. _size: 16,
  1437. _canvas: null,
  1438. _ctx: null,
  1439. _dirty: false,
  1440. _scale: 1,
  1441. setSize: function(a) {
  1442. if (this._size != a) {
  1443. this._size = a;
  1444. this._dirty = true;
  1445. }
  1446. },
  1447. setScale: function(a) {
  1448. if (this._scale != a) {
  1449. this._scale = a;
  1450. this._dirty = true;
  1451. }
  1452. },
  1453. setStrokeColor: function(a) {
  1454. if (this._strokeColor != a) {
  1455. this._strokeColor = a;
  1456. this._dirty = true;
  1457. }
  1458. },
  1459. setValue: function(a) {
  1460. if (a != this._value) {
  1461. this._value = a;
  1462. this._dirty = true;
  1463. }
  1464. },
  1465. render: function() {
  1466. if (null == this._canvas) {
  1467. this._canvas = document.createElement("canvas");
  1468. this._ctx = this._canvas.getContext("2d");
  1469. }
  1470. if (this._dirty) {
  1471. this._dirty = false;
  1472. var canvas = this._canvas,
  1473. ctx = this._ctx,
  1474. value = this._value,
  1475. scale = this._scale,
  1476. fontsize = this._size,
  1477. font = fontsize + 'px Russo One';
  1478. ctx.font = font;
  1479. var h = ~~(.2 * fontsize),
  1480. wd = fontsize * 0.1;
  1481. var h2 = h * 0.5;
  1482. canvas.width = ctx.measureText(value).width * scale + 3;
  1483. canvas.height = (fontsize + h) * scale;
  1484. ctx.font = font;
  1485. ctx.globalAlpha = 1;
  1486. ctx.lineWidth = wd;
  1487. ctx.strokeStyle = this._strokeColor;
  1488. ctx.fillStyle = this._color;
  1489. ctx.scale(scale, scale);
  1490. this._stroke && ctx.strokeText(value, 0, fontsize - h2);
  1491. ctx.fillText(value, 0, fontsize - h2);
  1492. }
  1493. return this._canvas
  1494. },
  1495. getWidth: function() {
  1496. return (ctx.measureText(this._value).width + 6);
  1497. }
  1498. };
  1499. Date.now || (Date.now = function() {
  1500. return (new Date).getTime()
  1501. });
  1502. var Quad = {
  1503. init: function(args) {
  1504. function Node(x, y, w, h, depth) {
  1505. this.x = x;
  1506. this.y = y;
  1507. this.w = w;
  1508. this.h = h;
  1509. this.depth = depth;
  1510. this.items = [];
  1511. this.nodes = []
  1512. }
  1513. var c = args.maxChildren || 2,
  1514. d = args.maxDepth || 4;
  1515. Node.prototype = {
  1516. x: 0,
  1517. y: 0,
  1518. w: 0,
  1519. h: 0,
  1520. depth: 0,
  1521. items: null,
  1522. nodes: null,
  1523. exists: function(selector) {
  1524. for (var i = 0; i < this.items.length; ++i) {
  1525. var item = this.items[i];
  1526. if (item.x >= selector.x && item.y >= selector.y && item.x < selector.x + selector.w && item.y < selector.y + selector.h) return true
  1527. }
  1528. if (0 != this.nodes.length) {
  1529. var self = this;
  1530. return this.findOverlappingNodes(selector, function(dir) {
  1531. return self.nodes[dir].exists(selector)
  1532. })
  1533. }
  1534. return false;
  1535. },
  1536. retrieve: function(item, callback) {
  1537. for (var i = 0; i < this.items.length; ++i) callback(this.items[i]);
  1538. if (0 != this.nodes.length) {
  1539. var self = this;
  1540. this.findOverlappingNodes(item, function(dir) {
  1541. self.nodes[dir].retrieve(item, callback)
  1542. })
  1543. }
  1544. },
  1545. insert: function(a) {
  1546. if (0 != this.nodes.length) {
  1547. this.nodes[this.findInsertNode(a)].insert(a);
  1548. } else {
  1549. if (this.items.length >= c && this.depth < d) {
  1550. this.devide();
  1551. this.nodes[this.findInsertNode(a)].insert(a);
  1552. } else {
  1553. this.items.push(a);
  1554. }
  1555. }
  1556. },
  1557. findInsertNode: function(a) {
  1558. return a.x < this.x + this.w / 2 ? a.y < this.y + this.h / 2 ? 0 : 2 : a.y < this.y + this.h / 2 ? 1 : 3
  1559. },
  1560. findOverlappingNodes: function(a, b) {
  1561. return a.x < this.x + this.w / 2 && (a.y < this.y + this.h / 2 && b(0) || a.y >= this.y + this.h / 2 && b(2)) || a.x >= this.x + this.w / 2 && (a.y < this.y + this.h / 2 && b(1) || a.y >= this.y + this.h / 2 && b(3)) ? true : false
  1562. },
  1563. devide: function() {
  1564. var a = this.depth + 1,
  1565. c = this.w / 2,
  1566. d = this.h / 2;
  1567. this.nodes.push(new Node(this.x, this.y, c, d, a));
  1568. this.nodes.push(new Node(this.x + c, this.y, c, d, a));
  1569. this.nodes.push(new Node(this.x, this.y + d, c, d, a));
  1570. this.nodes.push(new Node(this.x + c, this.y + d, c, d, a));
  1571. a = this.items;
  1572. this.items = [];
  1573. for (c = 0; c < a.length; c++) this.insert(a[c])
  1574. },
  1575. clear: function() {
  1576. for (var a = 0; a < this.nodes.length; a++) this.nodes[a].clear();
  1577. this.items.length = 0;
  1578. this.nodes.length = 0
  1579. }
  1580. };
  1581. var internalSelector = {
  1582. x: 0,
  1583. y: 0,
  1584. w: 0,
  1585. h: 0
  1586. };
  1587. return {
  1588. root: new Node(args.minX, args.minY, args.maxX - args.minX, args.maxY - args.minY, 0),
  1589. insert: function(a) {
  1590. this.root.insert(a)
  1591. },
  1592. retrieve: function(a, b) {
  1593. this.root.retrieve(a, b)
  1594. },
  1595. retrieve2: function(a, b, c, d, callback) {
  1596. internalSelector.x = a;
  1597. internalSelector.y = b;
  1598. internalSelector.w = c;
  1599. internalSelector.h = d;
  1600. this.root.retrieve(internalSelector, callback)
  1601. },
  1602. exists: function(a) {
  1603. return this.root.exists(a)
  1604. },
  1605. clear: function() {
  1606. this.root.clear()
  1607. }
  1608. }
  1609. }
  1610. };
  1611. wjQuery(function() {
  1612. function renderFavicon() {
  1613. if (0 < playerCells.length) {
  1614. redCell.color = playerCells[0].color;
  1615. redCell.setName(playerCells[0].name);
  1616. }
  1617. ctx.clearRect(0, 0, 32, 32);
  1618. ctx.save();
  1619. ctx.translate(16, 16);
  1620. ctx.scale(.4, .4);
  1621. redCell.drawOneCell(ctx);
  1622. ctx.restore();
  1623. var favicon = document.getElementById("favicon"),
  1624. oldfavicon = favicon.cloneNode(true);
  1625. oldfavicon.setAttribute("href", favCanvas.toDataURL("image/png"));
  1626. favicon.parentNode.replaceChild(oldfavicon, favicon)
  1627. }
  1628. var redCell = new Cell(0, 0, 0, 32, "#ED1C24", ""),
  1629. favCanvas = document.createElement("canvas");
  1630. favCanvas.width = 32;
  1631. favCanvas.height = 32;
  1632. var ctx = favCanvas.getContext("2d");
  1633. renderFavicon();
  1634. setInterval(drawChatBoard, 1E3);
  1635. setInterval(function() {
  1636. sendUint8(31);
  1637. pingtaym = Date.now()
  1638. }, 500);
  1639. });
  1640. wHandle.onload = gameLoop
  1641. })(window, window.jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement