Advertisement
Guest User

Driftin.io game.js code

a guest
May 19th, 2017
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.39 KB | None | 0 0
  1. var targetFPS = 60, delta, delta2, currentTime, oldTime = 0, gameState = 0, gameOver = !1, socket, port;
  2. Number.prototype.round = function(a) {
  3. return +this.toFixed(a)
  4. }
  5. ;
  6. CanvasRenderingContext2D.prototype.roundRect = function(a, b, c, d, e) {
  7. c < 2 * e && (e = c / 2);
  8. d < 2 * e && (e = d / 2);
  9. this.beginPath();
  10. this.moveTo(a + e, b);
  11. this.arcTo(a + c, b, a + c, b + d, e);
  12. this.arcTo(a + c, b + d, a, b + d, e);
  13. this.arcTo(a, b + d, a, b, e);
  14. this.arcTo(a, b, a + c, b, e);
  15. this.closePath();
  16. return this
  17. }
  18. ;
  19. var MathPI = Math.PI
  20. , MathCOS = Math.cos
  21. , MathSIN = Math.sin
  22. , MathABS = Math.abs
  23. , MathPOW = Math.pow
  24. , MathSQRT = Math.sqrt
  25. , MathMIN = Math.min
  26. , MathMAX = Math.max
  27. , MathATAN2 = Math.atan2
  28. , mainCanvas = document.getElementById("mainCanvas")
  29. , mainContext = mainCanvas.getContext("2d")
  30. , gameTitle = document.getElementById("gameTitle")
  31. , instructionsText = document.getElementById("instructionsText")
  32. , gameUiContainer = document.getElementById("gameUiContainer")
  33. , userInfoContainer = document.getElementById("userInfoContainer")
  34. , loadingContainer = document.getElementById("loadingContainer")
  35. , enterGameButton = document.getElementById("enterGameButton")
  36. , userNameInput = document.getElementById("userNameInput")
  37. , menuContainer = document.getElementById("menuContainer")
  38. , darkener = document.getElementById("darkener")
  39. , linksContainer = document.getElementById("linksContainer")
  40. , infoContainerM = document.getElementById("infoContainerM")
  41. , leaderboardList = document.getElementById("leaderboardList")
  42. , boostDisplay = document.getElementById("boostDisplay")
  43. , lapsDisplay = document.getElementById("lapsDisplay")
  44. , upgradesList = document.getElementById("upgradesList")
  45. , upgradesInfo = document.getElementById("upgradesInfo")
  46. , upgradesHeaders = document.getElementById("upgradesHeaders")
  47. , className = document.getElementById("className")
  48. , classDescription = document.getElementById("classDescription")
  49. , classDiff = document.getElementById("classDiff")
  50. , endBoardContainer = document.getElementById("endBoardContainer")
  51. , endBoardTable = document.getElementById("endBoardTable")
  52. , endBoardTimer = document.getElementById("endBoardTimer")
  53. , useAbilityContainer = document.getElementById("useAbilityContainer")
  54. , useAbilityName = document.getElementById("useAbilityName")
  55. , followText = document.getElementById("followText")
  56. , lobbyKey = document.getElementById("lobbyKey")
  57. , lobbyKeyText = document.getElementById("lobbyKeyText")
  58. , classIcon = document.getElementById("classIcon")
  59. , chatbox = document.getElementById("chatbox");
  60. chatbox.style.display = "block";
  61. var chatInput = document.getElementById("chatInput")
  62. , chatList = document.getElementById("chatList")
  63. , modeSelector = document.getElementById("modeSelector")
  64. , modeListView = document.getElementById("modeListView")
  65. , instructionsIndex = 0
  66. , instructionsSpeed = 5500
  67. , insturctionsCountdown = 0
  68. , instructionsList = "move your mouse to control your vehicle and click to use your boost;you can earn points to upgrade your vehicle by completing objectives;crashing into walls and other players damages your vehicle;if your vehicle is destroyed, you have to start over again;press Enter to toggle the chat and press C to hide or show the chat;listening to eurobeat improves your ability to play this game".split(";")
  69. , instructionsIndex = UTILS.randInt(0, instructionsList.length - 1)
  70. , randomLoadingTexts = "starting engines...;prepare to drive...;engaging flux capacitors...;pumping gas...;buckle up buckeroo...;playing eurobeat...".split(";");
  71. function addChatItem(a, b, c) {
  72. var d = document.createElement("li");
  73. c ? (d.className = "sysMsg",
  74. d.innerHTML = b) : d.innerHTML = "[" + a + "] <span class='grayMsg'>" + b + "</span>";
  75. for (; 120 < chatList.clientHeight; )
  76. chatList.removeChild(chatList.childNodes[0]);
  77. chatList.appendChild(d)
  78. }
  79. var hasStorage = "undefined" !== typeof Storage;
  80. if (hasStorage) {
  81. var cid = localStorage.getItem("sckt");
  82. cid || (cid = UTILS.getUniqueID(),
  83. localStorage.setItem("sckt", cid))
  84. }
  85. var partyKey = null, player = null, modeIndex = 0, modeList, gameObjects = [], map = null, currentMode = null, target = [0, 0, 0, 0], viewMult = 1, maxScreenWidth = 1920, maxScreenHeight = 1080, originalScreenWidth = maxScreenWidth, originalScreenHeight = maxScreenHeight, screenWidth, screenHeight;
  86. function getURLParam(a, b) {
  87. b || (b = location.href);
  88. a = a.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  89. var c = (new RegExp("[\\?&]" + a + "=([^&#]*)")).exec(b);
  90. return null == c ? null : c[1]
  91. }
  92. var lobbyURLIP = getURLParam("l"), lobbyRoomID;
  93. if (lobbyURLIP) {
  94. var tmpL = lobbyURLIP.split("-")
  95. , lobbyURLIP = tmpL[0];
  96. lobbyRoomID = tmpL[1]
  97. }
  98. window.onload = function() {
  99. enterGameButton.onclick = function() {
  100. enterGame()
  101. }
  102. ;
  103. console.log(lobbyURLIP);
  104. $.get("/getIP", {
  105. sip: lobbyURLIP
  106. }, function(a) {
  107. port = a.port;
  108. socket || (socket = io.connect("http://" + a.ip + ":" + a.port, {
  109. "connect timeout": 3E3,
  110. reconnection: !0,
  111. query: "cid=" + cid + "&rmid=" + lobbyRoomID
  112. }),
  113. setupSocket())
  114. })
  115. }
  116. ;
  117. mainCanvas.addEventListener("mousemove", gameInput, !1);
  118. mainCanvas.addEventListener("mousedown", mouseDown, !1);
  119. mainCanvas.addEventListener("mouseup", mouseUp, !1);
  120. var mouseX, mouseY, forceTarget = !0;
  121. function gameInput(a) {
  122. a.preventDefault();
  123. a.stopPropagation();
  124. mouseX = a.clientX;
  125. mouseY = a.clientY;
  126. sendTarget(forceTarget);
  127. forceTarget = !1
  128. }
  129. function mouseDown(a) {
  130. a.preventDefault();
  131. a.stopPropagation();
  132. 3 !== a.which && 2 !== a.button && (target[2] = 1,
  133. sendTarget(!0));
  134. document.activeElement.blur();
  135. mainCanvas.focus()
  136. }
  137. function mouseUp(a) {
  138. a.preventDefault();
  139. a.stopPropagation();
  140. 3 === a.which || 2 === a.button ? socket.emit("3") : (target[2] = 0,
  141. sendTarget(!0))
  142. }
  143. window.onkeyup = function(a) {
  144. a = a.keyCode ? a.keyCode : a.which;
  145. socket && (userNameInput === document.activeElement ? 13 == a && (userNameInput.blur(),
  146. enterGame()) : chatInput === document.activeElement ? 13 == a && (chatInput.blur(),
  147. mainCanvas.focus(),
  148. socket.emit("c", chatInput.value),
  149. chatInput.value = "") : player && !player.dead && (67 == a && (chatbox.style.display = "block" == chatbox.style.display ? "none" : "block"),
  150. 13 == a ? chatInput.focus() : 49 <= a && 55 >= a ? socket.emit("2", a - 49) : 32 == a ? socket.emit("3") : 81 == a && (target[3] = target[3] ? 0 : 1,
  151. sendTarget(!0))))
  152. }
  153. ;
  154. function setupSocket() {
  155. socket.on("connect_error", function() {
  156. lobbyURLIP ? kickPlayer("Connection failed. Please check your lobby ID.") : kickPlayer("Connection failed. Please check your internet connection.")
  157. });
  158. socket.on("disconnect", function(a) {
  159. kickPlayer("Disconnected.");
  160. console.log("Send this to the dev: " + a)
  161. });
  162. socket.on("error", function(a) {
  163. kickPlayer("Disconnected. The server may have updated.");
  164. console.log("Send this to the dev: " + a)
  165. });
  166. socket.on("kick", function(a) {
  167. kickPlayer(a)
  168. });
  169. socket.on("v", function(a, b, c) {
  170. viewMult != c && (viewMult = c,
  171. maxScreenWidth = a * c,
  172. maxScreenHeight = b * c,
  173. resize())
  174. });
  175. socket.on("mds", function(a, b) {
  176. modeList = a;
  177. modeSelector.innerHTML = a[b].name + " <i style='vertical-align: middle;' class='material-icons'>&#xE5C5;</i>";
  178. modeIndex = b
  179. });
  180. socket.on("c", function(a, b, c) {
  181. addChatItem(a, b, c)
  182. });
  183. socket.on("gd", function(a, b) {
  184. map = a;
  185. currentMode = b;
  186. document.getElementById("notifDisplay").style.display = currentMode.recTime ? "inline-block" : "none";
  187. document.getElementById("modeVotes0").innerHTML = "(0)"
  188. });
  189. socket.on("spawn", function(a, b) {
  190. objectExists(a) ? updateOrPushObject(a) : gameObjects.push(a);
  191. b && (player = a,
  192. gameState = 1,
  193. toggleMenuUI(!1),
  194. toggleGameUI(!0),
  195. mainCanvas.focus())
  196. });
  197. socket.on("cv", function(a, b) {
  198. document.getElementById("modeVotes" + a).innerHTML = "(" + b + ")"
  199. });
  200. socket.on("lk", function(a) {
  201. partyKey = a
  202. });
  203. socket.on("d", function(a) {
  204. a = getPlayerIndexById(a);
  205. null != a && gameObjects.splice(a, 1)
  206. });
  207. socket.on("0", getLeaderboardData);
  208. socket.on("1", updateObjectData);
  209. socket.on("2", function(a, b) {
  210. screenShake(a, b)
  211. });
  212. socket.on("3", function(a, b, c, d) {
  213. var e = getPlayerIndex(a);
  214. null != e && (gameObjects[e].health = b,
  215. c && (gameObjects[e].maxHealth = c),
  216. 0 >= gameObjects[e].health && gameObjects[e].visible && (gameObjects[e].dead = !0,
  217. gameObjects[e].deathScaleMult = 1,
  218. gameObjects[e].deathAlpha = 1),
  219. d && (gameObjects[e].hitFlash = d));
  220. player && a == player.sid && (player.health = b,
  221. player.dead = 0 >= b,
  222. player.dead && (hideMainMenuText(),
  223. leaveGame()))
  224. });
  225. socket.on("4", updateFuelDisplay);
  226. socket.on("ts", function(a, b) {
  227. player && player.team == b && (lapsDisplay.innerHTML = currentMode.objName + " " + a + "/" + currentMode.pointsToWin)
  228. });
  229. socket.on("5", function(a, b, c) {
  230. null != a && (lapsDisplay.innerHTML = currentMode.objName + " " + a + "/" + currentMode.pointsToWin,
  231. currentMode.recTime && addLapInfo(a, 0),
  232. 1 < a && currentMode.scrText && showNotification(currentMode.scrText));
  233. upgradesList.innerHTML = "";
  234. upgradesHeaders.innerHTML = "";
  235. upgradesInfo.style.display = "none";
  236. if (0 < b) {
  237. for (var d = a = "", e = 0; e < c.length; ++e) {
  238. var d = d + ("<div class='upgradeIndx'>" + (e + 1) + "</div>")
  239. , f = "";
  240. c[e].cost && (f += "(" + c[e].cost + ") ");
  241. f = 1 == c[e].type ? f + "<span class='yellow'>use item</span>" : c[e].lvl < c[e].max ? f + ("lvl " + c[e].lvl) : "max level";
  242. a += "<div class='upgradeItem'><div class='upgradeTxt'>" + c[e].name + "</div><div class='upgradeNum'>" + f + "</div></div>"
  243. }
  244. upgradesList.innerHTML = a;
  245. upgradesHeaders.innerHTML = d;
  246. upgradesInfo.innerHTML = "points available (" + b + ")";
  247. upgradesInfo.style.display = "inline-block";
  248. $("#upgradesInfo").animate({
  249. "font-size": "24px"
  250. }, 100).animate({
  251. "font-size": "19px"
  252. }, 100)
  253. }
  254. });
  255. socket.on("a", function(a) {
  256. a ? (useAbilityContainer.style.display = "inline-block",
  257. useAbilityName.innerHTML = a.name,
  258. a.cd ? ($("#abilityCooldown").css("height", "75px"),
  259. $("#abilityCooldown").animate({
  260. height: "0%"
  261. }, a.cd)) : $("#abilityCooldown").css("height", "0")) : useAbilityContainer.style.display = "none"
  262. });
  263. socket.on("6", updateLapInfo);
  264. socket.on("7", function(a, b, c) {
  265. a = getPlayerIndex(a);
  266. null != a && (gameObjects[a][b] = c)
  267. });
  268. socket.on("8", function(a) {
  269. gameOver = !0;
  270. bestTime = null;
  271. initBest = !1;
  272. toggleGameUI(!1);
  273. toggleMenuUI(!1);
  274. darkener.style.display = "block";
  275. showEndBoard(a)
  276. });
  277. socket.on("9", function(a) {
  278. endBoardTimer.innerHTML = "Next game " + a
  279. });
  280. socket.on("n", function(a) {
  281. showNotification(a)
  282. })
  283. }
  284. var updateObjectData = function(a, b) {
  285. if (a)
  286. a.visible = !0,
  287. updateOrPushObject(a),
  288. delete a;
  289. else if (b) {
  290. for (var c = 0; c < gameObjects.length; ++c)
  291. gameObjects[c].visible || (gameObjects[c].forcePos = 1),
  292. gameObjects[c].visible = !1;
  293. for (c = 0; c < b.length; ) {
  294. var d = getPlayerIndex(b[c]);
  295. null != d && (gameObjects[d].x = b[c + 1],
  296. gameObjects[d].y = b[c + 2],
  297. gameObjects[d].dir = b[c + 3] || gameObjects[d].dir,
  298. gameObjects[d].visible = !0);
  299. c += 4
  300. }
  301. delete b
  302. }
  303. }
  304. , getLeaderboardData = function(a) {
  305. for (var b = "", c = 1, d = 0; d < a.length; )
  306. b += "<div class='leaderboardItem'><div style='display:inline-block;float:left;' class='whiteText'>" + c + ".</div> <div class='" + (player && a[d] == player.sid ? "leaderYou" : "leader " + a[d + 1]) + "'>" + a[d + 2] + "</div><div class='leaderboardLapsNum'>" + a[d + 3] + "</div></div>",
  307. d += 4,
  308. c++;
  309. leaderboardList.innerHTML = b;
  310. delete a
  311. }
  312. , updateFuelDisplay = function(a) {
  313. boostDisplay.innerHTML = a + " Boost"
  314. }
  315. , classIndex = 0;
  316. hasStorage && (classIndex = parseInt(localStorage.getItem("clssI")) || 0);
  317. var playerClasses = [{
  318. name: "Racer",
  319. diff: "Speed <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Defense <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Damage <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Handling <span class='greyMenuText'>\u25a0\u25a0\u25a0</span>"
  320. }, {
  321. name: "Bully",
  322. diff: "Speed <span class='greyMenuText'>\u25a0</span></br>Defense <span class='greyMenuText'>\u25a0\u25a0\u25a0\u25a0</span></br>Damage <span class='greyMenuText'>\u25a0</span></br>Handling <span class='greyMenuText'>\u25a0\u25a0\u25a0\u25a0</span>"
  323. }, {
  324. name: "Flash",
  325. diff: "Speed <span class='greyMenuText'>\u25a0\u25a0\u25a0\u25a0\u25a0\u25a0</span></br>Defense <span class='greyMenuText'>\u25a0</span></br>Damage <span class='greyMenuText'>\u25a0</span></br>Handling <span class='greyMenuText'>\u25a0</span>"
  326. }, {
  327. name: "Hazard",
  328. diff: "Speed <span class='greyMenuText'>\u25a0\u25a0</span></br>Defense <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Damage <span class='greyMenuText'>\u25a0\u25a0\u25a0\u25a0\u25a0</span></br>Handling <span class='greyMenuText'>\u25a0\u25a0</span>"
  329. }, {
  330. name: "Buster",
  331. diff: "Speed <span class='greyMenuText'>\u25a0</span></br>Defense <span class='greyMenuText'>\u25a0\u25a0</span></br>Damage <span class='greyMenuText'>\u25a0\u25a0\u25a0\u25a0</span></br>Handling <span class='greyMenuText'>\u25a0\u25a0</span></br>Special <span class='greyMenuText'>Cannon</span>"
  332. }, {
  333. name: "Ambulamp",
  334. diff: "Speed <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Defense <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Damage <span class='greyMenuText'>\u25a0</span></br>Handling <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Special <span class='greyMenuText'>Healing Orb</span>"
  335. }, {
  336. name: "Piercer",
  337. diff: "Speed <span class='greyMenuText'>\u25a0\u25a0\u25a0\u25a0\u25a0</span></br>Defense <span class='greyMenuText'>\u25a0</span></br>Damage <span class='greyMenuText'>\u25a0</span></br>Handling <span class='greyMenuText'>\u25a0\u25a0\u25a0\u25a0</span></br>Special <span class='greyMenuText'>Force Push</span>"
  338. }, {
  339. name: "Sludger",
  340. diff: "Speed <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Defense <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Damage <span class='greyMenuText'>\u25a0\u25a0</span></br>Handling <span class='greyMenuText'>\u25a0\u25a0\u25a0\u25a0</span></br>Special <span class='greyMenuText'>Sludge</span>"
  341. }, {
  342. name: "Deprived",
  343. diff: "Speed <span class='greyMenuText'>\u25a0</span></br>Defense <span class='greyMenuText'>\u25a0</span></br>Damage <span class='greyMenuText'>\u25a0</span></br>Handling <span class='greyMenuText'>\u25a0</span>"
  344. }]
  345. , unlockedSecret0 = !1;
  346. hasStorage && localStorage.getItem("scrt0") && unlockSecret(0);
  347. function unlockSecret(a) {
  348. a || unlockedSecret0 || (unlockedSecret0 = 1,
  349. followText.innerHTML = "Thank you for playing",
  350. playerClasses.push({
  351. name: "Star",
  352. diff: "Speed <span class='greyMenuText'>\u25a0\u25a0</span></br>Defense <span class='greyMenuText'>\u25a0\u25a0</span></br>Damage <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Handling <span class='greyMenuText'>\u25a0\u25a0\u25a0</span></br>Special <span class='greyMenuText'>Star Power</span>"
  353. }),
  354. hasStorage && localStorage.setItem("scrt0", 1))
  355. }
  356. function changeClass(a) {
  357. classIndex += a;
  358. classIndex >= playerClasses.length ? classIndex = 0 : 0 > classIndex && (classIndex = playerClasses.length - 1);
  359. classIcon.src = classIcons[classIndex];
  360. className.innerHTML = playerClasses[classIndex].name;
  361. classDiff.innerHTML = playerClasses[classIndex].diff;
  362. hasStorage && localStorage.setItem("clssI", classIndex)
  363. }
  364. function loadPartyKey() {
  365. partyKey && (window.history.pushState("", "Driftin.io", "/?l=" + partyKey),
  366. lobbyKeyText.innerHTML = "send the url above to a friend",
  367. lobbyKey.className = "deadLink")
  368. }
  369. function enterGame() {
  370. socket && (gameOver = !1,
  371. showMainMenuText(randomLoadingTexts[UTILS.randInt(0, randomLoadingTexts.length - 1)]),
  372. socket.emit("respawn", {
  373. name: userNameInput.value,
  374. classIndex: classIndex
  375. }),
  376. mainCanvas.focus())
  377. }
  378. function castVote(a) {
  379. socket.emit("cv", a)
  380. }
  381. function leaveGame() {
  382. gameState = 0;
  383. initBest = !1;
  384. notifDisplay && notifDisplay.html("");
  385. $("#abilityCooldown").css("height", "100%");
  386. toggleGameUI(!1);
  387. toggleMenuUI(!0);
  388. endBoardContainer.style.display = "none"
  389. }
  390. var maxFlashAlpha = .3
  391. , playerCanvas = document.createElement("canvas")
  392. , playerCanvasScale = 150;
  393. playerCanvas.width = playerCanvas.height = playerCanvasScale;
  394. var playerContext = playerCanvas.getContext("2d");
  395. playerContext.translate(playerCanvas.width / 2, playerCanvas.height / 2);
  396. playerContext.lineJoin = "round";
  397. var updateGameLoop = function(a) {
  398. if (player) {
  399. updateScreenShake();
  400. for (var b, c = 0; c < gameObjects.length; ++c)
  401. if (b = gameObjects[c],
  402. b.visible && !b.dead)
  403. if (b.forcePos || void 0 == b.localX || void 0 == b.localY)
  404. b.localX = b.x,
  405. b.localY = b.y,
  406. b.forcePos = 0;
  407. else {
  408. var d = b.x - b.localX;
  409. b.localX += d * a * .01;
  410. d = b.y - b.localY;
  411. b.localY += d * a * .01
  412. }
  413. b = gameObjects[getPlayerIndex(player.sid)];
  414. var e, f;
  415. b && (e = b.localX,
  416. f = b.localY);
  417. d = (e || 0) - maxScreenWidth / 2 - screenSkX;
  418. f = (f || 0) - maxScreenHeight / 2 - screenSkY;
  419. map && currentMode && (mainContext.lineWidth = 2 * map.tracksidePadding,
  420. mainContext.fillStyle = map.wallColor,
  421. mainContext.strokeStyle = "#ea6363",
  422. mainContext.lineJoin = "miter",
  423. mainContext.fillRect(0, 0, maxScreenWidth, maxScreenHeight),
  424. mainContext.fillStyle = map.backgroundColor,
  425. "square" == map.shape ? (mainContext.fillRect(-map.widthH - d, -map.heightH - f, map.width, map.height),
  426. mainContext.strokeRect(-map.widthH - d + map.tracksidePadding, -map.heightH - f + map.tracksidePadding, map.width - 2 * map.tracksidePadding, map.height - 2 * map.tracksidePadding),
  427. map.trackWidth && (mainContext.fillStyle = "#ea6363",
  428. mainContext.fillRect(-map.innerWidthH - d - 2 * map.tracksidePadding, -map.innerHeightH - f - 2 * map.tracksidePadding, map.innerWidth + 4 * map.tracksidePadding, map.innerHeight + 4 * map.tracksidePadding),
  429. mainContext.fillStyle = map.wallColor,
  430. mainContext.fillRect(-map.innerWidthH - d, -map.innerHeightH - f, map.innerWidth, map.innerHeight)),
  431. mainContext.strokeStyle = "#fff",
  432. mainContext.setLineDash([100, 100]),
  433. mainContext.strokeRect(-map.widthH - d + map.tracksidePadding, -map.heightH - f + map.tracksidePadding, map.width - 2 * map.tracksidePadding, map.height - 2 * map.tracksidePadding),
  434. map.trackWidth && mainContext.strokeRect(-map.innerWidthH - d - map.tracksidePadding, -map.innerHeightH - f - map.tracksidePadding, map.innerWidth + 2 * map.tracksidePadding, map.innerHeight + 2 * map.tracksidePadding),
  435. mainContext.setLineDash([])) : "circle" == map.shape && (mainContext.beginPath(),
  436. mainContext.arc(-d, -f, map.heightH, 0, 2 * Math.PI),
  437. mainContext.closePath(),
  438. mainContext.fill(),
  439. mainContext.beginPath(),
  440. mainContext.arc(-d, -f, map.heightH - map.tracksidePadding, 0, 2 * Math.PI),
  441. mainContext.closePath(),
  442. mainContext.stroke(),
  443. map.trackWidth && (mainContext.fillStyle = "#ea6363",
  444. mainContext.beginPath(),
  445. mainContext.arc(-d, -f, map.innerWidthH + 2 * map.tracksidePadding, 0, 2 * Math.PI),
  446. mainContext.closePath(),
  447. mainContext.fill(),
  448. mainContext.fillStyle = map.wallColor,
  449. mainContext.beginPath(),
  450. mainContext.arc(-d, -f, map.innerWidthH, 0, 2 * Math.PI),
  451. mainContext.closePath(),
  452. mainContext.fill()),
  453. mainContext.strokeStyle = "#fff",
  454. mainContext.setLineDash([100, 100]),
  455. mainContext.beginPath(),
  456. mainContext.arc(-d, -f, map.innerWidthH + map.tracksidePadding, 0, 2 * Math.PI),
  457. mainContext.closePath(),
  458. mainContext.stroke(),
  459. mainContext.beginPath(),
  460. mainContext.arc(-d, -f, map.heightH - map.tracksidePadding, 0, 2 * Math.PI),
  461. mainContext.closePath(),
  462. mainContext.stroke(),
  463. mainContext.setLineDash([])),
  464. mainContext.fillStyle = map.lineColor,
  465. mainContext.strokeStyle = map.lineColor,
  466. map.startLine && mainContext.fillRect(-(map.startLineWidth / 2) - d, map.height / 2 - map.trackWidth - f + 2 * map.tracksidePadding, map.startLineWidth, map.trackWidth - 4 * map.tracksidePadding));
  467. for (c = 0; c < gameObjects.length; ++c)
  468. if (b = gameObjects[c],
  469. b.visible && !b.dead || b.deathAlpha) {
  470. e = b.localX - d;
  471. var h = b.localY - f, g = 0, k;
  472. b.deathAlpha && b.dead ? (b.deathScaleMult += a / 50,
  473. g = b.deathScaleMult,
  474. b.deathAlpha -= a / 300,
  475. 0 >= b.deathAlpha && (b.deathAlpha = 0),
  476. k = b.deathAlpha) : k = 1;
  477. var m = b.squeeze || 1, g = g + 2.25 * b.scale, l;
  478. playerContext.lineWidth = 11;
  479. playerContext.clearRect(-(playerCanvasScale / 2), -(playerCanvasScale / 2), playerCanvasScale, playerCanvasScale);
  480. b.isPlayer ? (renderPlayer(playerContext, g, m, b.classIndex, b.special),
  481. l = 1 == b.classIndex ? g / 2 : 2 == b.classIndex ? g / 1.8 : 3 == b.classIndex ? g / 1.9 : 4 == b.classIndex ? g / 1.8 : 5 == b.classIndex ? g / 1.9 : 6 == b.classIndex ? g / 1.7 : 7 == b.classIndex ? g / 1.9 : 8 == b.classIndex ? g / 2.1 : 9 == b.classIndex ? g / 1.9 : g / 1.8) : (1 == b.colorIndex ? (playerContext.fillStyle = "#68d65a",
  482. playerContext.strokeStyle = "#7bfa6a") : 2 == b.colorIndex ? (playerContext.fillStyle = "#a95ad6",
  483. playerContext.strokeStyle = "#c26afa") : (playerContext.fillStyle = "#615959",
  484. playerContext.strokeStyle = "#706767"),
  485. playerContext.beginPath(),
  486. playerContext.arc(0, 0, g / 2, 0, 2 * MathPI, !1),
  487. playerContext.fill(),
  488. playerContext.stroke());
  489. !gameOver && 0 < b.spawnProt && (void 0 == b.flashAlpha && (b.flashAlpha = maxFlashAlpha,
  490. b.flashInc = 5E-4),
  491. b.flashAlpha += b.flashInc * a,
  492. b.flashAlpha > maxFlashAlpha ? (b.flashAlpha = maxFlashAlpha,
  493. b.flashInc *= -1) : 0 >= b.flashAlpha && (b.flashAlpha = 0,
  494. b.flashInc *= -1),
  495. playerContext.globalCompositeOperation = "source-atop",
  496. playerContext.fillStyle = "rgba(255, 255, 255, " + b.flashAlpha + ")",
  497. playerContext.fillRect(-playerCanvas.width / 2, -playerCanvas.height / 2, playerCanvas.width, playerCanvas.height),
  498. playerContext.globalCompositeOperation = "source-over");
  499. !gameOver && 0 < b.hitFlash && (b.hitFlash -= .001 * a,
  500. 0 >= b.hitFlash && (b.hitFlash = 0),
  501. playerContext.globalCompositeOperation = "source-atop",
  502. playerContext.fillStyle = "rgba(255, 255, 255, " + b.hitFlash + ")",
  503. playerContext.fillRect(-playerCanvas.width / 2, -playerCanvas.height / 2, playerCanvas.width, playerCanvas.height),
  504. playerContext.globalCompositeOperation = "source-over");
  505. mainContext.save();
  506. mainContext.globalAlpha = k;
  507. mainContext.translate(e, h);
  508. mainContext.rotate((b.sid != player.sid || player.turnSpeed ? b.dir : target[0]) + MathPI / 2);
  509. mainContext.drawImage(playerCanvas, -(playerCanvasScale / 2), -(playerCanvasScale / 2));
  510. mainContext.restore();
  511. b.isPlayer && b.name && !gameOver && (mainContext.font = "36px regularF",
  512. mainContext.textAlign = "center",
  513. mainContext.strokeStyle = "#5f5f5f",
  514. mainContext.lineWidth = 6,
  515. 380 > mainContext.measureText(b.name).width && (mainContext.strokeText(b.name, e, h - l - 25),
  516. mainContext.fillStyle = "#ffffff",
  517. mainContext.fillText(b.name, e, h - l - 25)));
  518. !gameOver && b.isPlayer && (k = b.health / b.maxHealth,
  519. m = 80 * k,
  520. g = 80 / 9,
  521. mainContext.fillStyle = "#5f5f5f",
  522. mainContext.roundRect(e - 40 - 3, h + l + 25 - 3, 86, g + 6, 6).fill(),
  523. mainContext.fillStyle = .35 < k ? "#78d545" : "#d55d45",
  524. mainContext.roundRect(e - m / 2, h + l + 25, m, g, 6).fill())
  525. }
  526. updateAnimTexts(a);
  527. delete b
  528. }
  529. };
  530. function renderPlayer(a, b, c, d, e, f) {
  531. if (1 == d)
  532. a.fillStyle = "#5a68d6",
  533. a.strokeStyle = "#6a74fa",
  534. f && (b /= 1.5),
  535. a.beginPath(),
  536. a.arc(0, 0, b / 2, 0, 2 * MathPI, !1),
  537. a.fill(),
  538. a.stroke();
  539. else if (2 == d)
  540. f && (b /= 2,
  541. c = .8),
  542. a.fillStyle = "#a95ad6",
  543. a.strokeStyle = "#c26afa",
  544. a.lineWidth *= 2,
  545. a.beginPath(),
  546. a.moveTo(0, -2 * b / 3),
  547. a.lineTo(-b / 2 * c, b / 3),
  548. a.lineTo(b / 2 * c, b / 3),
  549. a.lineTo(0, -2 * b / 3),
  550. a.closePath(),
  551. a.stroke(),
  552. a.fill();
  553. else if (3 == d) {
  554. f && (b /= 1.3);
  555. a.fillStyle = "#3b3838";
  556. a.strokeStyle = "#4f4c4c";
  557. c = 8;
  558. f = MathPI / 2 * 3;
  559. d = b / 2;
  560. e = MathPI / c;
  561. a.beginPath();
  562. a.moveTo(0, -d);
  563. for (b = 0; b < c; b++)
  564. a.lineTo(MathCOS(f) * d, MathSIN(f) * d),
  565. f += e,
  566. a.lineTo(.8 * MathCOS(f) * d, .8 * MathSIN(f) * d),
  567. f += e;
  568. a.lineTo(0, -d);
  569. a.closePath();
  570. a.fill();
  571. a.stroke()
  572. } else if (4 == d)
  573. f && (b /= 2),
  574. a.fillStyle = "#757575",
  575. a.strokeStyle = "#888888",
  576. a.beginPath(),
  577. a.moveTo(-b / 4, -b / 1.5),
  578. a.lineTo(b / 4, -b / 1.5),
  579. a.lineTo(b / 2, b / 2.5),
  580. a.lineTo(-b / 2, b / 2.5),
  581. a.closePath(),
  582. a.fill(),
  583. a.stroke();
  584. else if (5 == d)
  585. d = 80,
  586. f && (b /= 2,
  587. c = .8,
  588. a.lineWidth *= 1.6,
  589. d = 70),
  590. a.fillStyle = "#e0e0e0",
  591. a.strokeStyle = "#f5f5f5",
  592. a.fillRect(-b * c / 2, -b / 2, b * c, b),
  593. a.strokeRect(-b * c / 2, -b / 2, b * c, b),
  594. a.font = d + "px regularF",
  595. a.textBaseline = "middle",
  596. a.textAlign = "center",
  597. a.fillStyle = "#fa6a6a",
  598. a.fillText("+", 0, 0);
  599. else if (6 == d)
  600. f && (b /= 2,
  601. c = .8),
  602. a.fillStyle = "#e89c42",
  603. a.strokeStyle = "#ffab48",
  604. a.lineWidth *= 2,
  605. a.beginPath(),
  606. a.moveTo(0, -2 * b / 3),
  607. a.lineTo(-b / 2 * c, b / 3),
  608. a.lineTo(0, b / 5),
  609. a.lineTo(b / 2 * c, b / 3),
  610. a.lineTo(0, -2 * b / 3),
  611. a.closePath(),
  612. a.stroke(),
  613. a.fill();
  614. else if (7 == d) {
  615. f && (b /= 2);
  616. a.fillStyle = "#68d65a";
  617. a.strokeStyle = "#7bfa6a";
  618. c = 6;
  619. e = -Math.PI / c - Math.PI / 2;
  620. f = b / 1.3;
  621. d = f / 1.5;
  622. a.beginPath();
  623. a.moveTo(d * Math.cos(e), d * Math.sin(e));
  624. for (b = 0; b <= c; b++) {
  625. e = 2 * b * Math.PI / c - Math.PI / 2;
  626. var h = (2 * b + 1) * Math.PI / c - Math.PI / 2;
  627. a.quadraticCurveTo(f * Math.cos(e), f * Math.sin(e), d * Math.cos(h), d * Math.sin(h))
  628. }
  629. a.fill();
  630. a.stroke();
  631. a.closePath()
  632. } else if (8 == d) {
  633. f && (b /= 1.4);
  634. a.fillStyle = "#ad8a36";
  635. a.strokeStyle = "#cba240";
  636. c = b / 2;
  637. f = 2 * Math.PI / 6;
  638. a.beginPath();
  639. a.moveTo(c, 0);
  640. for (b = 1; 6 > b; b++)
  641. a.lineTo(c * Math.cos(f * b), c * Math.sin(f * b));
  642. a.closePath();
  643. a.fill();
  644. a.stroke()
  645. } else if (9 == d) {
  646. f && (b /= 1.3);
  647. a.fillStyle = e ? "#000" : "#f7ed3e";
  648. a.strokeStyle = e ? "#fff" : "#ffff66";
  649. c = e ? 4 : 5;
  650. f = MathPI / 2 * 3;
  651. d = b / 2;
  652. e = MathPI / c;
  653. a.beginPath();
  654. a.moveTo(0, -d);
  655. for (b = 0; b < c; b++)
  656. a.lineTo(MathCOS(f) * d, MathSIN(f) * d),
  657. f += e,
  658. a.lineTo(.5 * MathCOS(f) * d, .5 * MathSIN(f) * d),
  659. f += e;
  660. a.lineTo(0, -d);
  661. a.closePath();
  662. a.fill();
  663. a.stroke()
  664. } else
  665. f && (b /= 2),
  666. a.fillStyle = "#d65a5a",
  667. a.strokeStyle = "#fa6a6a",
  668. a.lineWidth *= 2,
  669. a.beginPath(),
  670. a.moveTo(0, -2 * b / 3),
  671. a.lineTo(-b / 2 * c, b / 3),
  672. a.lineTo(b / 2 * c, b / 3),
  673. a.lineTo(0, -2 * b / 3),
  674. a.closePath(),
  675. a.stroke(),
  676. a.fill()
  677. }
  678. for (var classIconScale = 100, classIcons = [], i = 0; 10 > i; ++i) {
  679. var tmpCanvas = document.createElement("canvas");
  680. tmpCanvas.width = tmpCanvas.height = classIconScale;
  681. var tmpContext = tmpCanvas.getContext("2d");
  682. tmpContext.lineWidth = 11;
  683. tmpContext.translate(tmpCanvas.width / 2, tmpCanvas.height / 2);
  684. tmpContext.lineJoin = "round";
  685. renderPlayer(tmpContext, classIconScale, 1, i, 0, !0);
  686. classIcons.push(tmpCanvas.toDataURL())
  687. }
  688. changeClass(0);
  689. $("#classSelector").bind("contextmenu", function(a) {
  690. changeClass(-1);
  691. return !1
  692. });
  693. function updateMenuLoop(a) {
  694. 1 != gameState && (insturctionsCountdown -= a,
  695. 0 >= insturctionsCountdown && (insturctionsCountdown = instructionsSpeed,
  696. instructionsText.innerHTML = instructionsList[instructionsIndex],
  697. instructionsIndex++,
  698. instructionsIndex >= instructionsList.length && (instructionsIndex = 0)))
  699. }
  700. var sendFrequency = 1E3 / 24
  701. , lastSent = 0;
  702. function sendTarget(a) {
  703. var b = currentTime;
  704. !gameOver && player && !player.dead && (a || b - lastSent > sendFrequency) && (target[1] = MathSQRT(MathPOW(mouseY - screenHeight / 2, 2) + MathPOW(mouseX - screenWidth / 2, 2)),
  705. target[1] *= MathMIN(maxScreenWidth / screenWidth, maxScreenHeight / screenHeight),
  706. target[0] = MathATAN2(mouseY - screenHeight / 2, mouseX - screenWidth / 2),
  707. target[0] = target[0].round(2),
  708. target[1] = target[1].round(2),
  709. lastSent = b,
  710. socket.emit("1", target))
  711. }
  712. var maxNotifs = 2
  713. , bestTime = null
  714. , initBest = !1
  715. , lastTime = 0
  716. , notifDisplay = $("#notifDisplay");
  717. function addLapInfo(a, b) {
  718. if (!initBest) {
  719. initBest = !0;
  720. var c = $("<div/>").addClass("notificationWrapper")
  721. , d = $("<span/>").addClass("notificationText").html("Best <span class='greyMenuText'>" + UTILS.getTimeString(bestTime || b) + "</span>");
  722. d.attr("id", "lapInfoBest");
  723. d.appendTo(c);
  724. c.appendTo(notifDisplay)
  725. } else if (!bestTime || lastTime < bestTime)
  726. bestTime = lastTime,
  727. $("#lapInfoBest").html("Best <span class='greyMenuText'>" + UTILS.getTimeString(bestTime) + "</span>");
  728. var e = notifDisplay.children().length
  729. , c = $("<div/>").addClass("notificationWrapper")
  730. , d = $("<span/>").addClass("notificationText").html("Lap " + a + " <span class='greyMenuText'>" + UTILS.getTimeString(b) + "</span>");
  731. e >= maxNotifs && notifDisplay.children().eq(1).remove();
  732. d.attr("id", "lapInfo" + a);
  733. d.appendTo(c);
  734. c.appendTo(notifDisplay);
  735. c.animate({
  736. "font-size": "28px"
  737. }, 100).animate({
  738. "font-size": "20px"
  739. }, 100)
  740. }
  741. function updateLapInfo(a, b) {
  742. currentMode.recTime && ($("#lapInfo" + a).html("Lap " + a + " <span class='greyMenuText'>" + UTILS.getTimeString(b) + "</span>"),
  743. bestTime || $("#lapInfoBest").html("Best <span class='greyMenuText'>" + UTILS.getTimeString(b) + "</span>"),
  744. lastTime = b)
  745. }
  746. for (var animTexts = [], animTextIndex = 0, i = 0; 20 > i; ++i)
  747. animTexts.push(new animText);
  748. function updateAnimTexts(a) {
  749. mainContext.textAlign = "center";
  750. mainContext.strokeStyle = "#5f5f5f";
  751. mainContext.fillStyle = "#ffffff";
  752. mainContext.lineWidth = 7;
  753. for (var b = 0; b < animTexts.length; ++b)
  754. animTexts[b].update(a);
  755. mainContext.globalAlpha = 1
  756. }
  757. function animText() {
  758. this.fadeSpeed = this.fadeDelay = this.scalePlus = this.maxScale = this.minScale = this.scale = this.alpha = this.y = this.x = 0;
  759. this.text = "";
  760. this.active = !1;
  761. this.update = function(a) {
  762. this.active && (this.scale += this.scalePlus * a,
  763. this.scale >= this.maxScale ? (this.scalePlus *= -1,
  764. this.scale = this.maxScale) : this.scale <= this.minScale && (this.scalePlus = 0,
  765. this.scale = this.minScale),
  766. this.fadeDelay -= a,
  767. 0 >= this.fadeDelay && (this.alpha -= this.fadeSpeed * a,
  768. 0 >= this.alpha && (this.alpha = 0,
  769. this.active = !1)),
  770. this.active && (mainContext.globalAlpha = this.alpha,
  771. mainContext.font = this.scale * viewMult + "px regularF",
  772. mainContext.strokeText(this.text, this.x, this.y),
  773. mainContext.fillText(this.text, this.x, this.y)))
  774. }
  775. ;
  776. this.show = function(a, b, c, d, e, f) {
  777. this.x = a;
  778. this.y = b;
  779. this.minScale = this.scale = d;
  780. this.maxScale = 1.35 * d;
  781. this.scalePlus = f;
  782. this.text = c || "";
  783. this.alpha = 1;
  784. this.fadeDelay = e || 0;
  785. this.fadeSpeed = .003;
  786. this.active = !0
  787. }
  788. }
  789. function showAnimText(a, b, c, d, e, f, h) {
  790. if (!gameOver) {
  791. var g = animTexts[animTextIndex];
  792. g.show(a, b, c, d, e, h);
  793. g.type = f;
  794. animTextIndex++;
  795. animTextIndex >= animTexts.length && (animTextIndex = 0)
  796. }
  797. }
  798. function showNotification(a) {
  799. for (var b = 0; b < animTexts.length; ++b)
  800. "notif" == animTexts[b].type && (animTexts[b].active = !1);
  801. showAnimText(maxScreenWidth / 2, maxScreenHeight / 1.3, a, 46, 1E3, "notif", .19)
  802. }
  803. function showBigNotification(a) {
  804. for (var b = 0; b < animTexts.length; ++b)
  805. "bNotif" == animTexts[b].type && (animTexts[b].active = !1);
  806. showAnimText(maxScreenWidth / 2, maxScreenHeight / 3, a, 130, 1E3, "bNotif", .26)
  807. }
  808. var screenSkX = 0
  809. , screenShackeScale = 0
  810. , screenSkY = 0
  811. , screenSkRed = .5
  812. , screenSkDir = 0;
  813. function screenShake(a, b) {
  814. screenShackeScale < a && (screenShackeScale = a,
  815. screenSkDir = b)
  816. }
  817. function updateScreenShake(a) {
  818. 0 < screenShackeScale && (screenSkX = screenShackeScale * MathCOS(screenSkDir),
  819. screenSkY = screenShackeScale * MathSIN(screenSkDir),
  820. screenShackeScale *= screenSkRed,
  821. .1 >= screenShackeScale && (screenShackeScale = 0))
  822. }
  823. var kickReason = null;
  824. function kickPlayer(a) {
  825. leaveGame();
  826. kickReason || (kickReason = a);
  827. showMainMenuText(kickReason);
  828. socket.close();
  829. window.history.pushState("", "Driftin.io", "/")
  830. }
  831. function updateOrPushObject(a) {
  832. var b = getPlayerIndex(a.sid);
  833. null != b ? gameObjects[b] = a : gameObjects.push(a)
  834. }
  835. function objectExists(a) {
  836. for (var b = 0; b < gameObjects.length; ++b)
  837. if (gameObjects[b].sid == a.sid)
  838. return !0;
  839. return !1
  840. }
  841. function getPlayerIndex(a) {
  842. for (var b = 0; b < gameObjects.length; ++b)
  843. if (gameObjects[b].sid == a)
  844. return b;
  845. return null
  846. }
  847. function getPlayerIndexById(a) {
  848. for (var b = 0; b < gameObjects.length; ++b)
  849. if (gameObjects[b].id == a)
  850. return b;
  851. return null
  852. }
  853. function showMainMenuText(a) {
  854. userInfoContainer.style.display = "none";
  855. loadingContainer.style.display = "block";
  856. loadingContainer.innerHTML = a
  857. }
  858. function hideMainMenuText() {
  859. userInfoContainer.style.display = "block";
  860. loadingContainer.style.display = "none"
  861. }
  862. function toggleGameUI(a) {
  863. gameUiContainer.style.display = a ? "block" : "none"
  864. }
  865. function toggleMenuUI(a) {
  866. a ? (menuContainer.style.display = "flex",
  867. darkener.style.display = "block",
  868. linksContainer.style.display = "block",
  869. infoContainerM.style.display = "block",
  870. endBoardContainer.style.display = "none",
  871. userNameInput.focus(),
  872. target[2] = 0) : (menuContainer.style.display = "none",
  873. darkener.style.display = "none",
  874. linksContainer.style.display = "none",
  875. infoContainerM.style.display = "none")
  876. }
  877. var tmpPlayer;
  878. function showEndBoard(a) {
  879. endBoardContainer.style.display = "flex";
  880. endBoardTable.innerHTML = "";
  881. var b;
  882. if (currentMode.recTime) {
  883. b = "<tr><th>Player</th><th>Best Time</th><th>Total Time</th><th>Kills</th><th>Deaths</th><th>" + currentMode.objName + "</th></tr>";
  884. for (var c = 0; c < a.length; ++c)
  885. tmpPlayer = a[c],
  886. b += "<tr><td style=" + (player && tmpPlayer.id == player.id ? "color:#fff" : "") + "><img src='" + classIcons[tmpPlayer.classIndex] + "' style='width:20px;height:20px;display:inline-block;vertical-align:middle;'> " + tmpPlayer.name + "</td><td>" + tmpPlayer.bestTime + "</td><td>" + tmpPlayer.totalTime + "</td><td>" + tmpPlayer.kills + "</td><td>" + tmpPlayer.deaths + "</td><td>" + tmpPlayer.score + "</td></tr>"
  887. }
  888. endBoardTable.innerHTML = b
  889. }
  890. function showModeList() {
  891. if (modeList)
  892. if ("block" == modeListView.style.display)
  893. modeListView.style.display = "none";
  894. else {
  895. for (var a = "", b = 0; b < modeList.length; ++b)
  896. a += "<div onclick='changeMode(" + b + ")' class='modeListItem'>" + modeList[b].name + "</div>";
  897. modeListView.style.display = "block";
  898. modeListView.innerHTML = a
  899. }
  900. }
  901. function changeMode(a) {
  902. modeList && modeList[a] && a !== modeIndex && (modeListView.style.display = "none",
  903. modeSelector.innerHTML = modeList[a].name + "<i style='vertical-align: middle;' class='material-icons'>&#xE5C5;</i>",
  904. window.location.href = modeList[a].url)
  905. }
  906. window.addEventListener("resize", resize);
  907. function resize() {
  908. screenWidth = window.innerWidth;
  909. screenHeight = window.innerHeight;
  910. var a = MathMAX(screenWidth / maxScreenWidth, screenHeight / maxScreenHeight);
  911. mainCanvas.width = screenWidth;
  912. mainCanvas.height = screenHeight;
  913. mainContext.setTransform(a, 0, 0, a, (screenWidth - maxScreenWidth * a) / 2, (screenHeight - maxScreenHeight * a) / 2)
  914. }
  915. resize();
  916. var targetFPS = 60
  917. , then = Date.now();
  918. window.requestAnimFrame = function() {
  919. return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(a, b) {
  920. window.setTimeout(a, 1E3 / targetFPS)
  921. }
  922. }();
  923. function callUpdate() {
  924. requestAnimFrame(callUpdate);
  925. currentTime = Date.now();
  926. var a = currentTime - then;
  927. a > 1E3 / targetFPS && (then = currentTime - a % (1E3 / targetFPS),
  928. updateGameLoop(a),
  929. updateMenuLoop(a))
  930. }
  931. callUpdate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement