Advertisement
madcatzano

slitherio

Apr 18th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function updateElem() {
  2. currServ = bso ? bso.ip + ':' + bso.po : 'None';
  3. var x = snake ? parseInt(snake.xx) : 0;
  4. var y = snake ? parseInt(snake.yy) : 0;
  5. topElem.textContent = 'Server: ' + currServ + ', ' + 'X: ' + x + ', Y: ' + y;
  6. }
  7.  
  8. function force(elem) {
  9. var splitArr = elem.value.split(':');
  10. if (splitArr.length > 1) forceServer((splitArr[0] || ''), (splitArr[1] || ''));
  11. };
  12.  
  13. var topElem = document.createElement('span');
  14. window.onload = function(){
  15. topElem.style.position = 'fixed';
  16. topElem.style.zIndex = '666';
  17. topElem.style.top = '5px';
  18. topElem.style.textAlign = 'center';
  19. topElem.style.width = '100%';
  20. topElem.style.fontSize = '20px';
  21. topElem.style.fontFamily = 'Verdana';
  22. topElem.style.color = '#FFF';
  23. document.body.appendChild(topElem);
  24.  
  25. var parent = document.getElementById('playh');
  26. var div = document.createElement('div');
  27. var input = document.createElement('input');
  28. var button = document.createElement('span');
  29. var currServ = 'None';
  30.  
  31. div.style.width = '244px';
  32. div.style.margin = '14px auto';
  33. div.style.background = '#4c447c none repeat scroll 0% 0%';
  34. div.style.boxShadow = '0px 6px 50px rgb(0, 0, 0)';
  35. div.style.border = '2px solid rgba(0, 0, 0, 1)';
  36. div.style.borderRadius = '29px';
  37. div.style.display = 'block';
  38. div.style.padding = '5px';
  39. div.style.fontFamily = 'Verdana';
  40. div.style.position = 'relative';
  41.  
  42. input.type = 'text';
  43. input.placeholder = 'IP-Address:Port';
  44. input.style.margin = '2px';
  45. input.style.background = 'rgba(0, 0, 0, 0) none repeat scroll 0 0';
  46. input.style.border = '0 none';
  47. input.style.color = '#e0e0ff';
  48. input.style.fontSize = '15px';
  49.  
  50. button.textContent = 'Go!';
  51. button.style.cursor = 'pointer';
  52. button.style.color = '#FFF';
  53. button.style.borderRadius = '24px';
  54. button.style.margin = '2px';
  55. button.style.padding = '2px 6px';
  56. button.style.background = 'linear-gradient(180deg, #9DA, #485)';
  57. button.onclick = function() { force(input); };
  58.  
  59. div.appendChild(input);
  60. div.appendChild(button);
  61.  
  62. parent.appendChild(div);
  63. timerID = setInterval(function () {
  64. updateElem();
  65. }, 1000);
  66. };
  67.  
  68. (function(w) {
  69. var renderMode = 1, // 2 - normal, 1 - simple (mobile)
  70. gameFPS = null,
  71. positionHUD = null,
  72. fpsHUD = null,
  73. ipHUD = null,
  74. styleHUD = "color: #FFF; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 14px; position: fixed; opacity: 0.35; z-index: 100;",
  75. clearedBg = false,
  76. clearedGlow = false;
  77. function init() {
  78. // Append DIVs
  79. appendDiv("position-hud", "nsi", styleHUD + "right: 30; bottom: 120px;");
  80. appendDiv("fps-hud", "nsi", styleHUD + "right: 30; bottom: 140px;");
  81. appendDiv("ip-hud", "nsi", styleHUD + "right: 30; bottom: 8;");
  82. positionHUD = document.getElementById("position-hud");
  83. fpsHUD = document.getElementById("fps-hud");
  84. ipHUD = document.getElementById("ip-hud");
  85. // Hijack console log
  86. if (window.console) {
  87. window.console.logOld = console.log;
  88. window.console.log = getConsoleLog;
  89. }
  90. // Set game
  91. setGame();
  92. // Clear background and glow
  93. clearBg();
  94. // Update game
  95. updateGame();
  96. }
  97. // Append DIV
  98. function appendDiv(id, className, style) {
  99. var div = document.createElement("div");
  100. if (id) {
  101. div.id = id;
  102. }
  103. if (className) {
  104. div.className = className;
  105. }
  106. if (style) {
  107. div.style = style;
  108. }
  109. document.body.appendChild(div);
  110. }
  111. // Get console log
  112. function getConsoleLog(log) {
  113. window.console.logOld(log);
  114. if (log.indexOf("FPS") != -1) {
  115. gameFPS = log;
  116. }
  117. }
  118. // Set game
  119. function setGame() {
  120. if (w.render_mode && w.render_mode != renderMode) {
  121. w.render_mode = renderMode;
  122. }
  123. if (w.high_quality) {
  124. w.high_quality = false;
  125. }
  126. if (w.gla && w.gla != 0) {
  127. w.gla = 0;
  128. }
  129. }
  130. // Clear background and glow
  131. function clearBg() {
  132. if (clearedBg && clearedGlow) {
  133. return;
  134. }
  135. if (w.ii && !clearedBg) {
  136. w.ii.src = "";
  137. w.ii.onload = null;
  138. w.ii = null;
  139. if (w.bgi2) {
  140. w.bgi2 = null;
  141. }
  142. clearedBg = true;
  143. }
  144. if (w.ggbg) {
  145. w.ggbg = false;
  146. }
  147. if (w.gbgi && !clearedGlow) {
  148. w.gbgi.src = "";
  149. w.gbgi.onload = null;
  150. w.gbgi = null;
  151. if (w.gbgmc) {
  152. w.gbgmc = null;
  153. }
  154. clearedGlow = true;
  155. }
  156. setTimeout(clearBg, 50);
  157. }
  158. // Update game
  159. function updateGame() {
  160. if (positionHUD) {
  161. positionHUD.textContent = "X: " + (~~w.view_xx || 0) + " Y: " + (~~w.view_yy || 0);
  162. }
  163. if (fpsHUD && gameFPS) {
  164. fpsHUD.textContent = gameFPS;
  165. }
  166. if (ipHUD && w.bso) {
  167. ipHUD.textContent = "IP: " + w.bso.ip + ":" + w.bso.po;
  168. }
  169. setGame();
  170. setTimeout(updateGame, 500);
  171. }
  172. // Init
  173. init();
  174. })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement